Listbox select from ID

Friends, I show in a listbox with a database
with the following sample records:

Color ID

  1.    Green
    
  2.     Network
    
  3.     Black
    

I want to select the ID value from the database.

For example, if I have id 3 from the database, I want to select row 3

Greetings.

Do you mean something like

me.listindex = theDatabase.sqlselect("select ID from table")

Edit: that won’t work. You need to get the result of the SQL into a recordset and then set the listindex after getting the data out of the recordset.

No friend, for example, the green color with id 1, I want it to be shown by selecting from the list, how do I do it?

If I use DataList.ListIndex = 1, the record that is selected is the Network, this can work DataList.ListIndex = 1 - 1?

[quote=370284:@Victor Manuel Osornio]No friend, for example, the green color with id 1, I want it to be shown by selecting from the list, how do I do it?

If I use DataList.ListIndex = 1, the record that is selected is the Network, this can work DataList.ListIndex = 1 - 1?[/quote]

ListBox.ListIndex is 0 based.

Yes, how can I select the record that gets its value from the database, for example, select the green record, use its name or identify unique.

A simple approach to select a specific entry in your ListBox by it’s value, could look like this:

[code]For X As Integer = ListBox.ListCount-1 DownTo 0

If ListBox.Cell(X, 0) = “Green” Then

ListBox.Selected(X) = True

End If

Next X[/code]

Remember that the UNISUE ID of the Database can have holes in the numbering sheme. 1, 5, 12 (as examples) can be missing. You better search the Color name from the Database in the Listbox column. IMHO

If the Column in the Database is unique, this would be ok i’d say. In any other case, take a 2nd column into account and store it’s field value (f.e. in the CellTag) and use this to access this specific Database Entry.