Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: Общие вопросы > Добавить значение в ComboBox


Автор: RN3QGA 28.11.2005, 18:27
Здравствуйте.
Вопросик таков.
Есть ComboBox у которого Items заполнен, ну скажем на 300 строк
Подскажите как можно выполнить проверку при вводе в ComboBox
такого типа:
Если введенная строка не совпадает с уже существующими, то добавить в Items, а если совпадает то ничего.
Я пробывал организовать цикл проверки, но что-то не получается и совсем запутался.
Спасибо.

Автор: DemoCode 28.11.2005, 18:44
Цитата
TStrings.IndexOf

Returns the position of a string in the list.

function IndexOf(const S: string): Integer; virtual;

Description

Call IndexOf to obtain the position of the first occurrence of the string S, or of a string that differs from S only by case. IndexOf returns the 0-based index of the string. Thus, if S matches the first string in the list, IndexOf returns 0, if S is the second string, IndexOf returns 1, and so on. If the string is not in the string list, IndexOf returns -1.

Note: If the string appears in the list more than once, IndexOf returns the position of the first occurrence.


if ComboBox.Items.IndexOf(str) = -1 then ... // Еще нет
else // Такая строка уже есть

Автор: RN3QGA 28.11.2005, 18:57
Спасибо !
Попробуем осуществить!

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)