How can I determine If a Listbox is selected

Hi all.
How can I know if a Listbox is selected, I only know how to determine which cell is selected on Listbox.

But I Want to determine if a Listbox is selected or on Focus.

Thanks

the window or container has a focus property
check that

http://documentation.xojo.com/index.php/Window.Focus

You keep track of it by setting a property in Gotfocus and Lostfocus or with

If self.Focus <> Nil Then
If self.Focus.Name = “ListBox1”

[quote=224655:@Marco Hof]You keep track of it by setting a property in Gotfocus and Lostfocus or with

If self.Focus <> Nil Then
If self.Focus.Name = “ListBox1”
…[/quote]

Curious why you;d keep track of the name ?

If self.Focus <> Nil Then
If self.Focus = ListBox1

Not tracking the name. I mean Either setting a boolean property on GotFocus to True and to False on LostFocus Or via self.focus.Name.

The first is sometimes needed when you need to know the focus while your App is not the active one. In that case, self.Focus = Nil.

Perfect, Thanks a lot.

Now If I need to know How many rows are selected on the Listbox?

Run through the Selected array and count them.

Better yet, use Listbox.selcount. Tim, are you alright?

Thanks It Works

LOL, how did I not see SelCount?

cough wheeze Must be a touch of the plague or something.

I’d swear it wasn’t there yesterday!

That’s why I always used .ListIndex > -1

This happens to me sometimes (too many times and it increase with age)…

so do i… don’t even know that SelCount exist.

Note: ListIndex is valid for single selection mode. SelCount/Selected should be used for multi-select mode. I only ever use single selection mode, so my knowledge of multi-select is a little dated.

i do used Selected property for listbox when i need to loop through the record and found out the ID.