Parent child binding question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob

    #1

    Parent child binding question

    Got a datagridview with records bound to tableParent. Each time I go to a
    new row (single select) in the datagrid view I want a series of textboxes as
    well as another datagridview to shwo the realted records. The textboxes are
    in tableChild1 and the other datagridview is of tableChild2, Both these
    tables have a PK-FK relationship established in the dataset being used. How
    can I do this?

    Any help appreciated.

    Bob


  • Aphazel

    #2
    Re: Parent child binding question

    Actually it's quite simple. One important thing is that all control bindings
    must refer to tables and columns indirectly thru dataset. If you bind the
    controls directly to particular tables/columns, you'll loose the synchro you
    want while browsing tableParent.

    You're supposed to name the tables (at least tableParent) and relations, if
    they aren't named yet (use TableName and RelationName properties).

    ' let's say the DataSet object is ds
    ' for tableParent
    parentGridView. DataSource = ds
    parentGridView. DataMember = "tableParent_na me"

    ' for tableChild1 each control must have separate binding, eg. binding to
    sampleTextBox.T ext looks like this:
    sampeTextBox.Da taBindings.Add( New System.Windows. Forms.Binding(" Text", ds,
    "tableParent_na me.parent_child 2_relation_name .column_name", True))

    ' for tableChild2
    child2GridView. DataSource = ds
    child2GridView. DataMember = "tableParent_na me.parent_child 2_relation_name "

    ' FOLLOWING IS THE WRONG WAY
    child2GridView. DataSource = ds.Tables("tabl eParent_name")
    child2GridView. DataMember = "parent_child2_ relation_name"

    Hope you find it simple ;)
    Aph
    [color=blue]
    > Got a datagridview with records bound to tableParent. Each time I go to a
    > new row (single select) in the datagrid view I want a series of textboxes
    > as well as another datagridview to shwo the realted records. The textboxes
    > are in tableChild1 and the other datagridview is of tableChild2, Both
    > these tables have a PK-FK relationship established in the dataset being
    > used. How can I do this?
    >
    > Any help appreciated.
    >
    > Bob[/color]


    Comment

    • Bob

      #3
      Re: Parent child binding question

      Thanks Aph

      Microsoft should hire you to do their documentation. Then idiots like me
      could understand and cut through all the marketing BS and unintelligible
      jargon.
      Bob

      "Aphazel" <aphazel@o2.p l> wrote in message
      news:e66d6j$54u $1@nemesis.news .tpi.pl...[color=blue]
      > Actually it's quite simple. One important thing is that all control
      > bindings must refer to tables and columns indirectly thru dataset. If you
      > bind the controls directly to particular tables/columns, you'll loose the
      > synchro you want while browsing tableParent.
      >
      > You're supposed to name the tables (at least tableParent) and relations,
      > if they aren't named yet (use TableName and RelationName properties).
      >
      > ' let's say the DataSet object is ds
      > ' for tableParent
      > parentGridView. DataSource = ds
      > parentGridView. DataMember = "tableParent_na me"
      >
      > ' for tableChild1 each control must have separate binding, eg. binding to
      > sampleTextBox.T ext looks like this:
      > sampeTextBox.Da taBindings.Add( New System.Windows. Forms.Binding(" Text", ds,
      > "tableParent_na me.parent_child 2_relation_name .column_name", True))
      >
      > ' for tableChild2
      > child2GridView. DataSource = ds
      > child2GridView. DataMember = "tableParent_na me.parent_child 2_relation_name "
      >
      > ' FOLLOWING IS THE WRONG WAY
      > child2GridView. DataSource = ds.Tables("tabl eParent_name")
      > child2GridView. DataMember = "parent_child2_ relation_name"
      >
      > Hope you find it simple ;)
      > Aph
      >[color=green]
      >> Got a datagridview with records bound to tableParent. Each time I go to a
      >> new row (single select) in the datagrid view I want a series of textboxes
      >> as well as another datagridview to shwo the realted records. The
      >> textboxes are in tableChild1 and the other datagridview is of
      >> tableChild2, Both these tables have a PK-FK relationship established in
      >> the dataset being used. How can I do this?
      >>
      >> Any help appreciated.
      >>
      >> Bob[/color]
      >
      >[/color]


      Comment

      Working...