![]() |
Listview checkbox
I want to get checked items with code(programaticly) when i use the code bellow its shows an error. :oops:
Delphi-Quellcode:
procedure TForm1.Button5Click(Sender: TObject);
begin if listview1.Items.Item[listview1.VisibleItems].Checked=true then form1.caption:='some items have been checked'; end; end. |
Re: Listview checkbox
Hi,
I cannot check this at the moment, but I guess, listview1.VisibleItems contains the number of items actually visible. If all items are visible you will get an index error because the last item will have the index listview1.VisibleItems - 1. |
Re: Listview checkbox
My ListView does not have a property called 'VisibleItems'
|
Re: Listview checkbox
This is TMS Advlistview
//But listview1.VisibleItems can be replaced with listview1.itemindex but this will change the message on the form only if you accually selected the item.Wich isnt good :x |
Re: Listview checkbox
What' s your aim? Do you want to know if any of the items is checked?
|
Re: Listview checkbox
Yes if any items are checked and if they are checked get their's index.
|
Re: Listview checkbox
Try this:
Delphi-Quellcode:
Edit:
procedure TForm1.Button1Click(Sender: TObject);
var i: Integer; iChecked: Integer; begin iChecked := 0; for i := 0 to ListView1.Items.Count - 1 do begin if ListView1.Items[i].Checked then Inc(iChecked); end; if iChecked > 1 then begin if iChecked < ListView1.Items.Count then Form1.Caption := 'some items are checked' else Form1.Caption := 'All items are checked'; end else begin case iChecked of 0: Form1.Caption := 'No item is checked'; 1: Form1.Caption := 'One item is checked'; end; end; end; In addition you could store the indexes (Checked = True) in an array or similar. |
Re: Listview checkbox
It works but it wont show specific index,i need this becouse of events. :P
|
Re: Listview checkbox
Zitat:
Either you could use it immediately or store it in an array, string variable or similar for further using. |
Re: Listview checkbox
This shows how many are selected but their index :(
Delphi-Quellcode:
var
i: {array[0..50] of} integer; iChecked: Integer; b:integer; begin iChecked := 0; for i := 0 to ListView1.Items.Count - 1 do begin if ListView1.Items[i].Checked then Inc(iChecked); end; { if iChecked > 1 then begin if iChecked < ListView1.Items.Count then Form1.Caption := 'some items are checked' else Form1.Caption := 'All items are checked'; } // end //else begin Form1.Caption:=inttostr(iChecked); //end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:22 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz