tommyf Posted May 25, 2004 Posted May 25, 2004 I have a combobox bound to a dataset using databinding. When the form loads it popultes the rest of the text boxes with the relevant information from the first record. What I can't seem to find out what to do is when I change the record in the combobox the rest of the text boxes change to. Do I have to use the position of the record as the key to all this. Quote
wessamzeidan Posted May 25, 2004 Posted May 25, 2004 you can use the selectedindexchanged event, and use the selectedindex property to retrieve the desired row from the dataset Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
*Experts* jfackler Posted May 26, 2004 *Experts* Posted May 26, 2004 (edited) binding data After establishing the complex binding (to the combobox) and simple binding (to the text boxes), setting the BindingContext of the form establishes which record is displayed on the form. Set it equal to the selectedindex of the combobox. example: cmbEmployeeName.DataSource = dataset1.Tables("Employees") cmbEmployeeName.DisplayMember = "Name" lblEmployeeName.DataBindings.Add("text", dataset1, "Employees.Name") lblPhone.DataBindings.Add("text", dataset1, "Employees.Phone") then, in the selectedindexchanged event of the combobox, reset the bindingcontext: Private Sub cmbEmployeeName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbEmployeeName.SelectedIndexChanged Me.BindingContex(dataset1, "Employees").Position=cmbEmployeeName.SelectedIndex End Sub Jon Edited May 26, 2004 by jfackler Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.