Top.Mail.Ru
Ответы

Как пользоватся ComboBox в C++ Builder? например как определить какую строчку выбрал пользователь

По дате
По Рейтингу
Аватар пользователя
Новичок
14лет

Indicates which item in the drop-down list is selected.

__property int ItemIndex = {read=GetItemIndex, write=SetItemIndex, nodefault};

Description

Read ItemIndex to determine which item in the list is the selected value in the combo box. This value appears in the edit box portion of the combo box. The first item in the list has index 0, the second item has index 1, and so on. If no item is selected, the value of ItemIndex is -1.

Write to ItemIndex to programmatically select an item from the list by passing in the index value.

Вроде все понятно - хелп от борланда.

Аватар пользователя
14лет

Только учтите, что, если у ComboBox включена сортировка, то номер выбранной строки может не совпадать с порядком формирования строк.
Советую использовать Objects (запоминать для строки ее первоначальный номер) .

for(int i=0;i<=count;i++)
{
// ...
ComboBoxMap->Items->AddObject(name,(TObject *)i);
// ...
}

// ...

int number = (int)(ComboBoxMap->Items->Objects[ComboBoxMap->ItemIndex]);

Аватар пользователя
Мыслитель
14лет

не знаком с c++ builder, но учитывая, что разработчик borland, могу предположить, что за это отвечает свойство ItemIndex