Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

  • *Experts*
Posted (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 by jfackler

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...