![]() |
|
|
|
|
#1
|
||||
|
||||
|
Как можно найти строку в листбоксе, Например:
Есть три строки : 1 - Первая, 2 - Вторая, 3 - Третья? При вводе слова в едит - "Вторая", В листбоксе фокусируется на второй строке. |
|
#2
|
||||
|
||||
|
Как найти понял, А как можно теперь, чтобы он выделил эту строку?
Код:
var
i: integer;
Find: string;
begin
Find := Edit.text;
for i := 0 to LBox.Items.Count - 1 do
if Pos(Find, LBox.Items.Strings[i]) <> 0
then showmessage('Нашел!'); |
|
#3
|
|||
|
|||
|
Цитата:
Код:
procedure TForm1.Button1Click(Sender: TObject);
begin
ListBox1.Items.Add('1');
ListBox1.Items.Add('2');
{This will fail on a single selection ListBox}
// ListBox1.Selected[1] := true;
ListBox1.ItemIndex := 1; {This is ok}
end; |
|
#4
|
||||
|
||||
|
Код:
var
i: integer;
Find: string;
begin
Find := Edit.text;
for i := 0 to LBox.Items.Count - 1 do
if Pos(Find, LBox.Items.Strings[i]) <> 0
then then LBox.ItemIndex:=i; ![]() |
|
#5
|
|||
|
|||
|
Общий смысл такой, только вместо showmessage - выделение нужной строки.
Код:
procedure TForm1.FormCreate(Sender: TObject);
begin
ListBox1.Items.Add('1');
ListBox1.Items.Add('2');
ListBox1.Items.Add('3');
ListBox1.Items.Add('4');
ListBox1.Items.Add('5');
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
begin
for i := 0 to ListBox1.Items.Count - 1 do
if ListBox1.Items[i] = Edit1.Text then
ShowMessage(ListBox1.Items[i]);
end; |