Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I append new items into a combobox ?

0 views
Skip to first unread message

Peter Damgaard Ebeling

unread,
May 19, 1998, 3:00:00 AM5/19/98
to

Hi

I have some small problems with the CComboBox class (the methods).

In a class called CAdvancedIdPage I have a private variable
called m_ComboBox (actually I have more than one), the combobox
is created with the following:

BOOL CAdvancedIdPage::OnInitDialog()
{
CPropertyPage::OnInitDialog();

m_ComboBox.Create ( WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_TABSTOP
CBS_DROPDOWN | CBS_SORT, dim, this, nId);

return TRUE;
}

When I am running my program and activating my CAdvancedIdPage the combobox
appers and I can select items from my combobox-list, and in my code (when I
press the OK button) I can fetch the selected item by using GetCurSel, as follow:

void CAdvancedIdPage::OnOK()
{
int i;
CString s;

if ( CB_ERR != (i = m_ComboBox.GetCurSel()))
m_ComboBox.GetLBText (i, s);
}

All that works fine.


Now to my problem, what if I never has selected an item from my combobox-list,
but insted is entering a new item (using the 'edit' part of my combobox -
remember the style, CBS_DROPDOWN). Now I can't get this new item by using
GetCurSel - what do i miss ?

Somehow - I think, I must first append the new item, before I can select it by
using GetCurSel.
But then another question arise, when is the right time to use the append method ?
Because, I need some way to indicate that the entering of the new item is
finished - before appending it.

With hope for help or any links that can help me to solve my problem.
Regards

Peter Damgaard Ebeling
Bosch Telecom A/S Danmark

Private Email: pete...@pip.dknet.dk
Work Email: p...@dancall.dk

jhill

unread,
May 19, 1998, 3:00:00 AM5/19/98
to

Peter,

I've had the same problem. Some of the steps I've taken was:

I have default values in my combobox and I made the first one blank. This
way when I call GetCurSel( ) and the index
returned is zero(0), The user has not selected a valid item from the list.

If the index is zero, I then call GetWindowText( ) which will return me the
text from the CEdit half of the combobox.
You pass this method a CString&. If the CString has zero length. No work to
be done. If it has a length, I search the
combobox list for an exact match with the method FindStringExact( -1 ,
LPCTSTR str ). str is the string you pulled from
the CEdit half of the combobox and -1 tells the method to search from the
head of the list.

If no match, I then add it to the list with AddString( ). This will add the
item to the end of the list.
If the combobox was created with CBS_SORT, like your's, the list will auto
sort.

Let me know if this helps,
Jim
H- jh...@shore.net
W- james...@libertymutual.com

Peter Damgaard Ebeling wrote in message <3561ddb0...@news.dknet.dk>...

0 new messages