binding to a combo box

N

NCiii

I have form with 2 combo boxes that are related to each other. The
first combo1 acts as a parent and combo2 as a child. When I load
combo1 only the relavent corresponding data should be populated to
combo2. Also, when a change is detected in combo1 I want combo2 to be
automatically updated with the relavent data that reflects the change
in combo1.

I am able to bind data from a dataset or datatable to combo1 without
any problems. I created a datarelation to handle the parent/child
relation that is required. I have not been able to successfully bind
the data to combo2 so only the required data is populated in combo2.

If anyone can help me with this issue i would greatly appreciate the
guidance.

Also, if someone knows of a good web site with good explanations of
how to use the combo.selectedvalue and combo.selectedindex properties
correctly it would be a big help.

Thanks in advance

NCiii
 
L

Lars Netzel

Something like this maybe? I don't know how you load the Combos and where
the Info is coming from, from database or Static Items???

But something like this this maybe?

---------------------------------------
Private Sub Combo1_SelectedIndexChanged()
BindCombo2(Combo1.SelectedValue)
End Sub

Private Sub BindCombo2(id as integer)
'Use the ID to filter a Dataview's Rowfilter
End Sub
----------------------------------------


Hope it'll help you

/Lars
 
N

NCiii

Lars thanks for your reply,

I was able to figure out how to use the DataRelation I created. I'm
still not sure if its the best way or very effecient. So i am posting
the code that returns the data the way I would like it too for
reveiw/critique - not too badly please :)

Should data be bound to a combo box in any specific order i.e.
datasource first, displaymember next, etc.

Thanks again for any assistance provided.

--sub to bind to cboClient (parent table)
Sub BindClients()

Try
With cboClient
.DataSource = DS --> local copy
.DisplayMember = "Clients.Cint" --> datarelation
.ValueMember = "clients.Cint" --> datarelation
.SelectedIndex = 0
End With
Me.lblClientDescription.DataBindings.Add(New
System.Windows.Forms.Binding("Text", Me.DS, "Clients.Client_Name"))
--> binding label control for display

Catch e As Exception
MsgBox(e.Message)
End Try

End Sub

--> binds to cboMatter (child table)
Sub BindMatters()

Try
With cboMatter
.DataSource = DS
.ValueMember = "matters.Cint"
.DisplayMember = "Clients.ClientMatter.Matter_id"
.SelectedIndex = 0
End With
Me.lblMatterName.DataBindings.Add(New
System.Windows.Forms.Binding("Text", Me.DS,
"Clients.ClientMatter.Matter_Name"))
Catch e As Exception
MsgBox(e.Message, MsgBoxStyle.Information)
End Try
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top