2. Cannot move focus away from CComboBox
I have a simple dialog box containing a combo box and and a list box
control. The combo box contains a number of items, e.g. Item 1, Item 2, Item
3 etc. The list box on the other hand contains the sub-items of the items in
the combo box. So for example, if "Item 1" in the combo box is selected,
then the list box will display "Item 1 - Sub item 1", "Item 1 - Sub item 2",
and so on.
The problem I am having at the moment is when the dialog comes up (in the
OnInitDialog() function), I set the content of the combo box to equal to
what the user has selected from another dialog box. So if the item selected
was "Item 1" in the other dialog, the combo box content of the second dialog
box will be set to "Item 1" to reflect the selection.
Upon setting the content of the dialog box, I populate the contents of the
list box and set the cursor to first item in the list box. But what I'm
finding is that the focus (the blue highlight bar) is still staying on the
combo box item. The first item in the list box also has the highlight bar
since I set it, but it doesn't seem to be the item in focus, i.e. it doesn't
have the broken (dotted) border around the blue highlight bar, which
normally indicates that an item is selected.
The following is the piece of code that I'm using to implement the desire
behaviour.
// m_cbItems is the member variable for the combo box
// m_lbSubItems is the member variable for the list box
// m_strSelItem is a string variable for copying the selected
// item text into.
BOOL CMyDialog::OnInitDialog()
{
int index = m_cbItems.FindStringExact(0, m_strSelItem);
m_agentListCB.SetCurSel(index);
// Call this function to add the sub-items to the list box
PopulateListBox(m_strSelItem);
// Move the focus to the list box
m_lbSubItems.SetFocus();
// Default selection to first entry inlist box
m_lbSubItems.SetCurSel(0);
return TRUE;
}
What am I missing? Thanks for any help here.
CS
3. DataGrid setting DataSource setting focus to grid - CSharp/C#
4. Setting Text Color In CComboBox list control
I need to set the text color of the items in a CComboBox list control based upon each value or an associate value. Can I do this within the CComboBox code or do I need to subclass the CListCtrl with my own class that overrides DrawItem, OnCtlColor or something along those lines? Thanks much Eric
5. How to set default value for CComboBox
Hi, I try to set a combo box style with CBomboBox::SetExtendedUI(FALSE) TO disable/enable user's typing on the edit control but it didn'twork. Am I missing something? Thanks for any help, Chi
7. setting default value in a CComboBox instance?
8. Setting focus to a form based on a form handle ( C# )
Hi! I maintain a collection of all form handles that I span out. The forms can be MDI Parents or Children - my app opens up several forms of different type. Once in a while, when a user performs an action that opens up a new form, I want to check first if the form is already opened and if so, just set the focus to that form. Is there an API call that can do that ? I can not find anything in managed code. May be I am not looking right ? Please let me know if you've done similar things. Many Thanks, --Mike