[Gambas-user] Help on Listbox

ron ronstk at ...239...
Tue Apr 27 01:22:42 CEST 2004


On Saturday 24 April 2004 10:48, Lucian Teofanescu wrote:
> Hi all, thank you for answering my previous question.
>
> Here is a second one:
> I need to fill a listbox with customers names from a table but I also need
> to store in the listbox the ID of the customer from the same table, to use
> it for performing future select queries on other tables. In VB6 (old habits
> ;-)) I'm doing like this:
>
> 'fill the listbox List1 with customers names from recordset rsCustomers
> Do While Not rsCustomers.EOF
>     List1.AddItem rsCustomers!Name
>     List1.ItemData(List1.NewIndex) = rsCustomers!ID
>     rsCustomers.MoveNext
> Loop
>
> Private Sub List1_Click()
>     MsgBox List1.ItemData(List1.ListIndex) ' Show the ItemData property of
> the current clicked item End Sub
>
>
> In Gambas I'm doing like this:
>
> 'fill the listbox ListBox1 customers names from resultset rsCustomers
> Do While rsCustomers.Available
>     ListBox1.Add rsCustomers!Name
>     rsCustomers.MoveNext
> Loop
>
> Where to store the ID field - I mean what property of the listbox to use
> (an equivalent for the ItemData property in VB)? If there isn't such a
> property maybe it will be available in future versions of Gambas. But how
> to provide similar functionality until then? The only think I have in mind
> is to concatenate the Name and ID fields (something like "Lucian Teofanescu
> #2905") and fill the list with this string. When I need to retrieve the ID
> of the customer I can extract the part after # and convert it to an integer
> in order to perform my queries. Is there an easier way?
>
> Thank you for your time
> Lucian Teofanescu

In the PlayGround is a example with the ListBox, ListView and ColumnView
The ListView is the nearest way you need in your request but as everyone 
knows there will be a request for more data fields and ColumnView can 
store more values in the background.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: playground-0.0.tar.gz
Type: application/x-tgz
Size: 1736 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20040427/610eb653/attachment.bin>


More information about the User mailing list