[Gambas-user] Automatic selection in a listbox

Benoit Minisini gambas at ...1...
Fri Dec 2 00:02:27 CET 2005


On Thursday 01 December 2005 17:53, Felice Cafarelli wrote:
> Hi all, I had a problem with a listbox in gambas1.0.13:
> I populate dinamically (values from db) a listbox, and I want to
> automatically select the first value in the list after the population. I
> tried with the property INDEX, but I got only '-1' indexes, so i cannot
> distinguish the first item in the list. What can i do?
> I post here the code:
>
> FOR i = 1 TO rNumber
>     lstUsers.Add(rData!user & "(" & lstUsers.Index & ")")
>     IF lstUsers.Index = 0 THEN
>       lstUsers.SetFocus
>       lstUsers.Current.Selected
>     ENDIF
>     rData.MoveNext
>   NEXT
>
> Result is this list
>
> Bob(-1)
> Simon(-1)
> Teddy(-1)
>
> So I want Bob to be automatically selected... any idea?
> Cheers
> Felix
>

If you want to set the current item (which is selected if the ListBox is in 
single selection mode), you must do MyListBox.Index = n, where n is the index 
of the item (between 0 and MyListBox.Count - 1)

If the ListBox is in multiple selection mode, then you can do 
MyListBox[n].Selected = TRUE / FALSE, to set the selected state of the n-th 
item.

Regards,

-- 
Benoit Minisini





More information about the User mailing list