Solved

clear text portion of a dropdown list style combo box

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 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

11 Experts available now in Live!

Get 1:1 Help Now