Problemos with SQL and ComboBox

  • Thread starter Thread starter Pepehammer
  • Start date Start date
P

Pepehammer

Hi there guys!

I'm still having problems with my ComboBox.

I got a table, in SQL, with two columns, ProductID, ProductDescription.

I want to fill a ComboBox with the ProductDescription column, but when the
user selects an item, I want to return the ProductID, so I guess I got to
fill somewhere in the ComboBox the ProductID too.

How could I do this?

Examples are appreciated!!! ;-)

Thanks guys!
 
Hi Pepehammer,

A sample just changed because I saw a message from Ken

I hope this helps?
Cor

\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
dt.Columns.Add("Description", System.Type.GetType("System.String"))
dt.Columns.Add("Code", System.Type.GetType("System.Int32"))
Dim i As Integer
For i = 65 To 90
Dim dr As DataRow = dt.NewRow()
dr("Description") = ChrW(i)
dr("Code") = i
dt.Rows.Add(dr)
Next i
Dim dv As DataView = New DataView(dt)
dv.Sort = "Description"
Me.ComboBox2.DisplayMember = "Description"
Me.ComboBox2.ValueMember = "Code"
Me.ComboBox2.DataSource = dv
Me.ComboBox2.SelectedIndex = 5
End Sub

Private Sub ComboBox2_SelectionChangeCommitted _
(ByVal sender As Object, ByVal e As System.EventArgs) Handles _
ComboBox2.SelectionChangeCommitted
MessageBox.Show(Me.ComboBox2.SelectedText & _
" " & Me.ComboBox2.SelectedValue.ToString)
End Sub
///
 
Back
Top