combo box question

rangerbud249

Active member
Joined
Aug 18, 2004
Messages
27
Programming Experience
Beginner
can someone let me know how to set my combobox to a specific item in my list. (q) is the id number of the row im trynig to set the combobox to.

this is the code im using.
<
Private Sub fillQuestionlist(ByVal q As Integer)
Dim rowdata As ADODB.Recordset
rowdata = fillQuestion()
rowdata.MoveFirst()

Do While Not rowdata.BOF And Not rowdata.EOF
With Me.cbquestion
.Items.Add(
New Stations(rowdata.Fields(1).Value, rowdata.Fields(0).Value))
End With
rowdata.MoveNext()
Loop
End Sub

Public Function fillQuestion()
Dim rs As New ADODB.Recordset
Dim sSql As String
rs.Open("SELECT id, Question From [tbl_question.txt] order by id", dbTXTConn)
fillQuestion = rs
rs =
Nothing
End Function
>

thanks,
 
1) You really should be using ADO.NET and not Classic ADO for database operations in .NET
2) If you insist on using ADO, then you'll need to somehow store the ID along with the data so that you can then later loop through the items in the list and set the SelectedItem upon finding the correct item.
3) If you use ADO.NET, return your data results in a datatable, then set the .DataSource of the list to the datatable. Set the .DisplayMember to the name of the fiel to display, and set the .ValueMember to the field name of you id field. Then all you need to do is set .SelectedValue to q.

-tg
 
thanks for your help, but is there not a way to just set the combo box to a specific value. This way it displays the text that belongs to that value.

I do this in asp.net but dont know how to do it in vb.net

asp.net code
<
ddlStation.DataSource = station.getStation()
ddlStation.DataValueField = "id"
ddlStation.DataTextField = "Station_Name"
ddlStation.DataBind()
ddlStation.SelectedValue = (ed.Rows(0).Item(8))
>

the (ed.Rows(0).Item(8)) sets my list to that specific item.


 
Back
Top