ListView

Delphi

19/12/2005

Como posso pegar somente as linhas selecionadas em um listView?
Abs


Felipeiw

Felipeiw

Curtidas 0

Respostas

Jairroberto

Jairroberto

19/12/2005

Olá, Felipe!

Veja o exemplo do método ´GetNextItem´ do objeto TCustomListView:

This example demonstrates how to retrieve all selected items in a ListView component and add the Caption of the selected ListItems to a ListBox component. procedure TForm1.Button1Click(Sender: TObject); var Item: TListItem; begin Item := ListView1.Selected; while Item <> nil do begin ListBox1.Items.Add(Item.Caption); Item := ListView1.GetNextItem(Item, sdAll, [isSelected]); end; end;



Um abraço,
Jair


GOSTEI 0
Bruno Belchior

Bruno Belchior

19/12/2005

Uma outra maneira...
var
  Cont: Smallint;
begin
  for Cont := 0 to LstVw.SelCount - 1 do
    ShowMessage(LstVw.Items[Cont].Caption);
end;



GOSTEI 0
Michael

Michael

19/12/2005

Olá Bruno!

O seu código não vai funcionar, pois o valor de Cont será sempre de 0 até o total de itens selecionados. Se eu selecionar dentre 10 elementos o primeiro, o quinto e o último, por exemplo, vou receber o primeiro, o segundo e o terceiro (0 até 2).

Uma alternativa seria:

var
  I: Integer;
begin
  for I := 0 to ListView.Items.Count - 1 do
    if ListView.Items[I].Selected then
      FazAlgumaCoisa;
end;


[]´s


GOSTEI 0
Bruno Belchior

Bruno Belchior

19/12/2005

É verdade...


GOSTEI 0
POSTAR