jwz104
jwz104

Reputation: 367

If one item is selected in listview

How can i see if exactly one item is selected in a listview?

I now use:

if listview1.Selected <> nil then
begin
...
end;

But this code works when one or more items are selected, what is the script to see if one item is selected

Upvotes: 1

Views: 2647

Answers (2)

Frazz
Frazz

Reputation: 3043

You did not provide any info on Delphi version, VCL or FireMonkey... so I'm not sure this will work in all cases:

If ListView1.Selected = ListView1.Items[IndexOfItemYouWantToCheck]

or, if you have a reference to the item in some variable, then:

If ListView1.Selected = ItemYouWantToCheck

Upvotes: 0

Sentient
Sentient

Reputation: 1122

Try

if ListView1.SelCount = 1 then
  // do something

Upvotes: 6

Related Questions