AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Listview checkbox

Ein Thema von Razor · begonnen am 22. Aug 2007 · letzter Beitrag vom 22. Aug 2007
Antwort Antwort
Seite 1 von 2  1 2      
Razor
(Gast)

n/a Beiträge
 
#1

Listview checkbox

  Alt 22. Aug 2007, 12:52
I want to get checked items with code(programaticly) when i use the code bellow its shows an error.

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.
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.542 Beiträge
 
Delphi 11 Alexandria
 
#2

Re: Listview checkbox

  Alt 22. Aug 2007, 13:01
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.
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
s-off
(Gast)

n/a Beiträge
 
#3

Re: Listview checkbox

  Alt 22. Aug 2007, 13:09
My ListView does not have a property called 'VisibleItems'
  Mit Zitat antworten Zitat
Razor
(Gast)

n/a Beiträge
 
#4

Re: Listview checkbox

  Alt 22. Aug 2007, 13:10
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
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.542 Beiträge
 
Delphi 11 Alexandria
 
#5

Re: Listview checkbox

  Alt 22. Aug 2007, 13:14
What' s your aim? Do you want to know if any of the items is checked?
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
Razor
(Gast)

n/a Beiträge
 
#6

Re: Listview checkbox

  Alt 22. Aug 2007, 13:16
Yes if any items are checked and if they are checked get their's index.
  Mit Zitat antworten Zitat
s-off
(Gast)

n/a Beiträge
 
#7

Re: Listview checkbox

  Alt 22. Aug 2007, 13:16
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.
  Mit Zitat antworten Zitat
Razor
(Gast)

n/a Beiträge
 
#8

Re: Listview checkbox

  Alt 22. Aug 2007, 13:23
It works but it wont show specific index,i need this becouse of events.
  Mit Zitat antworten Zitat
s-off
(Gast)

n/a Beiträge
 
#9

Re: Listview checkbox

  Alt 22. Aug 2007, 13:30
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.
  Mit Zitat antworten Zitat
Razor
(Gast)

n/a Beiträge
 
#10

Re: Listview checkbox

  Alt 22. Aug 2007, 14:19
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;
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:59 Uhr.
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