CComboBoxEx how do i make an item be the selected one in the drop down list 
Author Message
 CComboBoxEx how do i make an item be the selected one in the drop down list

I have a CComboBoxEx control in MFC app. I am populating the combobox
control using the InsertItem method with about 18 items. Then i wish to
select one of the items in the list based on some matching text.

I try to do the following but it wont work? Anyone else got any ideas:

m_cbo.GetComboBoxCtrl()->SetCurSel(m_cbo.GetComboBoxCtrl()->FindString(0,m_s
zText));



Mon, 12 Sep 2005 17:14:36 GMT  
 CComboBoxEx how do i make an item be the selected one in the drop down list
Try splitting them into individual statements and check for error code.
Something like

    CComboBox* pCombo = m_cbo.GetComboBoxCtrl();
     if ( pCombo  )
    {
        int nIndex = pCombo->FindString(0,m_szText);
        if ( CB_ERR != nIndex )
        {
            pCombo->SetCurSel(nIndex);
        }
    }

--
Cheers
Check Abdoul [ VC++ MVP ]
-----------------------------------


Quote:
> I have a CComboBoxEx control in MFC app. I am populating the combobox
> control using the InsertItem method with about 18 items. Then i wish to
> select one of the items in the list based on some matching text.

> I try to do the following but it wont work? Anyone else got any ideas:

m_cbo.GetComboBoxCtrl()->SetCurSel(m_cbo.GetComboBoxCtrl()->FindString(0,m_s
Quote:
> zText));



Mon, 12 Sep 2005 17:42:21 GMT  
 CComboBoxEx how do i make an item be the selected one in the drop down list
Thanks for this. I have figured this out but doesnt seem consistent.

I have to do this simple call to set the current selection item:

m_cbo.SetCurSel(i)

However I dont see why i can directly access the CComboBoxEx item for this
member function and not call other ones.

Whilst i am on this subject do you know the answer to this one.

I have the style set to DropDown so i can pick from a list or type in an
entry in the edit box. I then want to call some other functions when the
user tabs away from the combo box to update another combo box.

I am overriding the OnKillFocus member function but this is only being
called when I change the item by dropping down the list. If however i am
just typing in the edit box portion and then tab away from the combobox
nothing happens.

Any ideas?

Thanks


Quote:
> Try splitting them into individual statements and check for error code.
> Something like

>     CComboBox* pCombo = m_cbo.GetComboBoxCtrl();
>      if ( pCombo  )
>     {
>         int nIndex = pCombo->FindString(0,m_szText);
>         if ( CB_ERR != nIndex )
>         {
>             pCombo->SetCurSel(nIndex);
>         }
>     }

> --
> Cheers
> Check Abdoul [ VC++ MVP ]
> -----------------------------------



> > I have a CComboBoxEx control in MFC app. I am populating the combobox
> > control using the InsertItem method with about 18 items. Then i wish to
> > select one of the items in the list based on some matching text.

> > I try to do the following but it wont work? Anyone else got any ideas:

m_cbo.GetComboBoxCtrl()->SetCurSel(m_cbo.GetComboBoxCtrl()->FindString(0,m_s

- Show quoted text -

Quote:
> > zText));



Mon, 12 Sep 2005 18:22:13 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. VC++ ComboBox only drops down one item

2. Last Item in DataTable not bound to Drop Down List

3. Combo box control automatically drop down the list of items

4. Selecting items in drop list in ComboBox

5. CComboBoxEx problems, am I the only one ?

6. Setting the hight of a list in a combo box (Drop Down List)

7. Setting the hight of a list in a combo box (Drop Down List)

8. Setting the hight of a list in a combo box (Drop Down List)

9. Selecting Items from a multi select list box VC++ 6.0 on W2K

10. API for making Start Menu Drop Down...

11. One Line Drop Down Combo Box

12. CComboBox won't drop down past one element

 

 
Powered by phpBB® Forum Software