Pages

Sunday, 28 May 2017

Setting Combo-box Value and Display Data with VB.Net

I was working on a Brokerage Calculation project where I need to load a table’s data into combo box as in the form of value member and display member because a combo-box store two value ID which not shown at drop down list but reside in combo-box .
We need to Set/Get data through value because it’s mostly primary key and  display mode for display 
field. Take a look on following code:

Dim con As New OleDbConnection(getconstr)
Dim da As New OleDbDataAdapter(sql, con)

Dim ds As New DataSet
 Try
da.Fill(ds)
ComboBox1.ValueMember = "ID"
            ComboBox1.DisplayMember = "unit"
            ComboBox1.DataSource = ds.Tables(0)       
Catch ex As Exception
            MsgBox ex.Message)

 End Try

No comments:

Post a Comment