Results 1 to 40 of 47

Thread: Master/Detail (Parent/Child) Data-binding (.NET 2.0+ WinForms)

Threaded View

  1. #19

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Master/Detail (Parent/Child) Data-binding (.NET 2.0+ WinForms)

    Quote Originally Posted by lechip View Post
    What if I what to view the PARENT of an actual record?
    This data-binding technique is about filtering child records. There's nothing built in that I aware of that will display or select a parent record based on selection of a child.

    It's not too hard to do with a small amount of code though. Once you've got a child DataRow, you can call its GetParentRow method to get the parent DataRow. Assuming that you have two BindingSources bound to two DataTables with a DataRelation between them, that might look like this:
    vb.net Code:
    1. Private Sub childBindingSource_CurrentChanged(sender As Object, e As EventArgs) Handles childBindingSource.CurrentChanged
    2.     Dim childRow As DataRow = DirectCast(Me.childBindingSource.Current, DataRowView).Row
    3.     Dim parentRow As DataRow = childRow.GetParentRow("ParentChildRelation")
    4.     Dim parentIndex As Integer = Me.parentBindingSource.Find("ParentID", parentRow("ParentID"))
    5.  
    6.     Me.parentBindingSource.Position = parentIndex
    7. End Sub
    Last edited by jmcilhinney; Oct 4th, 2020 at 10:39 PM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width