Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

clear text portion of a dropdown list style combo box

Posted on 1997-10-23
1
Medium Priority
?
562 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 400 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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 …
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.
Screencast - Getting to Know the Pipeline
Suggested Courses

916 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