0

I am using Combo-box of type CComboBox. In it I am filling state values and one special value "Other"(if some user wants to enter a different state) at dialog initialization. When I select Other, I want Combo-box to display text as "Type here" instead of selected value(i.e. Other), but it is not displaying.

For example: Suppose I filled states as State1, State2, State3 and Other in combo-box. When I select State1, then combo-box should display State1 in its edit control. But when I select "Other" then combo-box should display "Type here" instead of "Other" in its edit control.

For that I have checked on"OnCbnSelchangeCmbState" event if user selected Other.
If he has, then I used SetWindowText(_T("Type here")).
2nd way I have tried is by using ReplaceSel(_T("Type here")).
Combo-box is displaying "Type here" till OnCbnEditchangeCmbState event, but after that it is setting empty text. Why this is happening?

m_Cmb_State.GetLBText(m_Cmb_State.GetCurSel(), csState);
if (0 == csState.CompareNoCase(_T("OTHER")))
{
    m_pComboEdit->ReplaceSel(_T("Type here..."));
}
Blacktempel
  • 3,935
  • 3
  • 29
  • 53
Sam L
  • 31
  • 6
  • Please elaborate. It's hard to understand what you want. – Jabberwocky Jul 22 '15 at 11:37
  • Suppose I filled states as State1, State2, State3 and Other in combo-box. When I select State1, then combo-box should display State1 in its edit control. But when I select "Other" then combo-box should display "Type here" instead of "Other" in its edit control. – Sam L Jul 22 '15 at 11:43
  • Please elaborate your question by _editing_ your question. – Jabberwocky Jul 22 '15 at 11:43
  • Try to use SPY++ to check what window messages are sent after your action. Maybe it is better to post a message to yourself to get an execution paint after the combo box has done it's own stuff... – xMRi Jul 24 '15 at 08:29
  • I have used Spy++ to check messages. When user selects "Other", then I set Combo-box's text to "Type here" in "OnCbnSelchangeCmbState". Till "OnCbnEditchangeCmbState" it is setting successfully. But after that it is again setting to "Other". I have seen messages through Spy++. First it is sending WM_SETTEXT with "Type here" and later on one more WM_SETTEXT is sent with "Other". I am not getting who is sending the second WM_SETTEXT message. Is the second WM_SETTEXT is sent through Default window procedure? – Sam L Jul 24 '15 at 10:28
  • I have seen a link and solution for same kind of question but it is for c#. [link]http://stackoverflow.com/questions/7358292/change-the-comboboxs-text-field-when-an-item-is-selected-from-the-drop-down-lis. Is there a way to do it in MFC? – Sam L Jul 29 '15 at 08:21
  • See if http://stackoverflow.com/a/17869453/383779 can help you. `CEdit` has a `SetCueBanner` method; maybe if you can get the inner `CEdit` of a combobox, it will be possible to do what you want. – sergiol Dec 10 '16 at 23:02

0 Answers0