Another problem... Binding

liam

Member
Joined
Jun 8, 2004
Messages
23
Programming Experience
Beginner
I have already populaed my combobox with the account names. I need to do this because i want the user to choose the name from the combobox then information with regard to the account name will appear below in textboxes.

I have already bounded the textboxes with their respective fields BUT WHEN I SELECT THE ACCOUNT NAME FROM THE COMBOBOX THE INFORMATION BELOW DOES NOT FOLLOW.

Here's the code I used:

Private Sub frmAccountPortfolio_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'Bind Account Name to cbAccName

'Fill the Dataset

OleDbDataAdapter1.Fill(DsAccInfo1, "Account_Information")

'Bind Combobox1 and display first member

cbAccName.DataSource = DsAccInfo1.Tables("Account_Information")

cbAccName.DisplayMember = DsAccInfo1.Tables("Account_Information").Columns("AccName").ToString

End Sub

Hope to have some solutions.. Thanks a lot for helping.. M doing my masteral thesis and my defense is on monday.. Hope to hear from u the soonest time...
 
it display the second column of the table
VB.NET:
 Dim dt As New DataTable()
 		da.Fill(dt)
 		Dim dr As DataRow
 		For Each dr In dt.Rows
 			ComboBox1.Items.Add(dr(1))
 		Next
 
You need to use the SelectedValueChanged or SelectedIndexChanged event of the comboBox to change the Position of the BindingContext of the dataSource that the textBoxs are bound to.

If you are to use the SelectedValueChanged event, you will need to also set the ValueMember property of the comboBox. It's common to use the primaryKey field to bind to the ValueMember.
 
Last edited:
Back
Top