471,119 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,119 software developers and data experts.

How do I use a combobox for master-detail binding with a datagrid?

I have a combobox that is populated with a list of names. When a name is
selected I want to populate a datagrid with name information. I have my
master-detail defined in my dataset and it works fine if I use a datagrid
for the master, instead of a combobox. But the combobox won't cause the
repopulation of the datagrid with the appropriate data. What's the trick?

TIA,

Larry Woods
cross-posted on ...dotnet.languages.vb.controls
Nov 21 '05 #1
1 1888
Hi,

Create a dataview to for the datagrid. Bind the datagrid to the
dataview. Filter the records in the combobox selected item changed event.

Dim ds As New DataSet

Dim dv As DataView

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

Dim strConn As String

Dim strSQL As String

Dim da, daOrders As OleDbDataAdapter

Dim conn As OleDbConnection

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"

strConn &= "Data Source = Northwind.mdb;"

conn = New OleDbConnection(strConn)

da = New OleDbDataAdapter("Select * From Customers", conn)

da.Fill(ds, "Customers")

daOrders = New OleDbDataAdapter("Select * From Orders", conn)

daOrders.Fill(ds, "Orders")

dv = New DataView(ds.Tables("Orders"))

ComboBox1.DataSource = ds.Tables("Customers")

ComboBox1.DisplayMember = "CustomerID"

DataGrid1.DataSource = dv

End Sub

Private Sub ComboBox1_SelectedValueChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles ComboBox1.SelectedValueChanged

Dim drv As DataRowView

Try

drv = DirectCast(ComboBox1.SelectedItem, DataRowView)

dv.RowFilter = "CustomerID = '" & drv.Item("CustomerID").ToString & "'"

Catch ex As Exception

End Try

End Sub

Ken
----------------------
"Larry Woods" <la***@NOSPAMlwoods.com> wrote in message
news:uy*************@TK2MSFTNGP11.phx.gbl...
I have a combobox that is populated with a list of names. When a name is
selected I want to populate a datagrid with name information. I have my
master-detail defined in my dataset and it works fine if I use a datagrid
for the master, instead of a combobox. But the combobox won't cause the
repopulation of the datagrid with the appropriate data. What's the trick?

TIA,

Larry Woods
cross-posted on ...dotnet.languages.vb.controls

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Mr. B | last post: by
4 posts views Thread by Chandra | last post: by
5 posts views Thread by Mika M | last post: by
2 posts views Thread by Don | last post: by
3 posts views Thread by Mark | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.