Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Listview checkbox (https://www.delphipraxis.net/98156-listview-checkbox.html)

Razor 22. Aug 2007 12:52


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.

DeddyH 22. Aug 2007 13:01

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.

s-off 22. Aug 2007 13:09

Re: Listview checkbox
 
My ListView does not have a property called 'VisibleItems'

Razor 22. Aug 2007 13:10

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

DeddyH 22. Aug 2007 13:14

Re: Listview checkbox
 
What' s your aim? Do you want to know if any of the items is checked?

Razor 22. Aug 2007 13:16

Re: Listview checkbox
 
Yes if any items are checked and if they are checked get their's index.

s-off 22. Aug 2007 13:16

Re: Listview checkbox
 
Try this:

Delphi-Quellcode:
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;
Edit:
In addition you could store the indexes (Checked = True) in an array or similar.

Razor 22. Aug 2007 13:23

Re: Listview checkbox
 
It works but it wont show specific index,i need this becouse of events. :P

s-off 22. Aug 2007 13:30

Re: Listview checkbox
 
Zitat:

Zitat von s-off
Try this:
Edit:
In addition you could store the indexes (Checked = True) in an array or similar.

Check your control variable (i.e. 'i').
Either you could use it immediately or store it in an array, string variable or similar for further using.

Razor 22. Aug 2007 14:19

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 00:26 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz