[Gambas-user] Help on Listbox

Nigel Gerrard nigel at ...38...
Mon Apr 26 13:59:07 CEST 2004


Lucian,

At the moment there is no way to have more than one column in the Listbox.   As an alternative I would consider using an array to hold the ID of the customer. e.g.

DIM ID AS NEW Integer[]

'fill the listbox ListBox1 customers names from resultset rsCustomers
Do While rsCustomers.Available
    ListBox1.Add(rsCustomers!Name)
    ID.Add(rsCustomer!ID)
    rsCustomers.MoveNext
Loop

Then you can find the ID for the selected Customer:

CustomerID = ID[ListBox1.Index]

Hope this helps.

Nigel
  ----- Original Message ----- 
  From: Lucian Teofanescu 
  To: gambas-user at lists.sourceforge.net 
  Sent: Saturday, April 24, 2004 9:48 AM
  Subject: [Gambas-user] Help on Listbox


  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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20040426/33791f6c/attachment.html>


More information about the User mailing list