PC Review


Reply
Thread Tools Rate Thread

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

 
 
Larry Woods
Guest
Posts: n/a
 
      14th Nov 2004
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


 
Reply With Quote
 
 
 
 
Ken Tucker [MVP]
Guest
Posts: n/a
 
      14th Nov 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
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



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Master/Detail Binding TabControl elPato Microsoft Dot NET Framework Forms 0 13th Nov 2005 03:13 PM
Master-Detail DataGrid with conditional (detail) formatting John Sitka Microsoft Dot NET Framework Forms 0 4th Nov 2005 08:50 PM
Reproducible bug in Master-Detail DataGrid when RowFilter applied to Master jgbailey@gmail.com Microsoft Dot NET Framework Forms 0 21st Oct 2005 08:19 PM
Master - Detail Data Binding Hemang Shah Microsoft C# .NET 0 24th Jan 2005 06:08 AM
Filtering the Detail Datagrid in a Master Detail Relationship =?Utf-8?B?Qm9i?= Microsoft ADO .NET 1 19th Dec 2004 08:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:48 PM.