Solved

clear text portion of a dropdown list style combo box

Posted on 1997-10-23
1
549 Views
Last Modified: 2013-11-20
I want to clear the text portion of a dropdown list style combo box.when the user presses the delete key.  To support this, I have made the first item  in the list an empty string.  Then I have provided an OnKeyDown handler in a derived CCombo class.  It almost works.  If the user tabs into my combo box, presses DEL, and tabs out, everything is as expected.  However if he presses DEL when the list box portion is dropped, the edit portion clears as expected, but then when the user tabs to the next control, the previous contents of the combo box are restored.  How can I prevent this.  Here's my OnKeyDown code.

void MyCombo::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
      if (nChar == VK_DELETE)
            SetCurSel(0);
      else
            CComboBox::OnKeyDown(nChar, nRepCnt, nFlags);
}
0
Comment
Question by:boreilly
1 Comment
 
LVL 4

Accepted Solution

by:
mbhakta earned 100 total points
ID: 1308699
Here is a solution :
Create a private var m_bInited and follow the code :
This works for me.

MyCombo::MyCombo()
{
      m_bInited = FALSE;
}

void MyCombo::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
      if (nChar == VK_DELETE)
      {
            SetCurSel(0);
            m_bInited = TRUE;
      }
      else
      {
            CComboBox::OnKeyDown(nChar, nRepCnt, nFlags);
            m_bInited = FALSE;
      }
}

void MyCombo::OnCloseup()
{
      if ( m_bInited == TRUE)
      {
            SetCurSel(0);
            m_bInited = FALSE;
      }
}

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now