Solved

clear text portion of a dropdown list style combo box

Posted on 1997-10-23
1
559 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: 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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

622 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