Solved

clear text portion of a dropdown list style combo box

Posted on 1997-10-23
1
554 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 199
bobThere java chalenge 45 95
Tab names are off by one 5 54
fizzArray  challenge 1 107
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

685 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