VB2005: Simulate BindingSource Navigation of Parent - Child Table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nev
    Contributor
    • Oct 2007
    • 251

    VB2005: Simulate BindingSource Navigation of Parent - Child Table

    I have placed fields on form using datadesigner. I have a parent, child and childchild table. When I navigate the parent, naturally the child and childchild follows. Due to certain requirements, I changed the bindings of the childchild fields to point to its true table. Of course, when I navigate the parent, the childchild fields will not follow anymore.

    Now I place this code in the childbindingsou rce currentchanged event to let the childchild fields follow again...

    dim drv as datarowview = directcast(chil dbindingsource. current, datarowview)
    childchildbindi ngsource.filter = "PrimaryKey = '" & drv("ForeignKey ") & ""'"

    My problem is when I navigate the parent and it has no corresponding child data. The child fields follow the parent and will of course be blank just like EndOfFile. But what will I do to the childchildbindi ngsource so that the childchild fields will also be blank and point to the EndOfFile?

    Hoping anyone can enlighten me.
  • Shashi Sadasivan
    Recognized Expert Top Contributor
    • Aug 2007
    • 1435

    #2
    Originally posted by nev
    I have placed fields on form using datadesigner. I have a parent, child and childchild table. When I navigate the parent, naturally the child and childchild follows. Due to certain requirements, I changed the bindings of the childchild fields to point to its true table. Of course, when I navigate the parent, the childchild fields will not follow anymore.

    Now I place this code in the childbindingsou rce currentchanged event to let the childchild fields follow again...

    dim drv as datarowview = directcast(chil dbindingsource. current, datarowview)
    childchildbindi ngsource.filter = "PrimaryKey = '" & drv("ForeignKey ") & ""'"

    My problem is when I navigate the parent and it has no corresponding child data. The child fields follow the parent and will of course be blank just like EndOfFile. But what will I do to the childchildbindi ngsource so that the childchild fields will also be blank and point to the EndOfFile?

    Hoping anyone can enlighten me.
    Lets see how well i understood this.
    You have a parent datatable, whever you navigate it, then the data in another datatable being displayed is changed due to the cange in the parent table navigation.
    Now if this does not exist or the parent does not have data, your child table still shows it.

    something like that i believe.

    What i did was to find if there is data in the parent table, or if (corresponding data could be found, if not clear the table)

    does that help anyways?

    probably a smaller example of a parent and a child table o f your explanation can make it clearer.

    cheers

    Comment

    • nev
      Contributor
      • Oct 2007
      • 251

      #3
      Originally posted by Shashi Sadasivan
      Lets see how well i understood this.
      You have a parent datatable, whever you navigate it, then the data in another datatable being displayed is changed due to the cange in the parent table navigation.
      Now if this does not exist or the parent does not have data, your child table still shows it.

      something like that i believe.

      What i did was to find if there is data in the parent table, or if (corresponding data could be found, if not clear the table)

      does that help anyways?

      probably a smaller example of a parent and a child table o f your explanation can make it clearer.

      cheers
      Well, you've almost got it. Thing is I used 3 tables in my previous example because it nearly reflects what I'm really doing. And I use the bindingsource to navigate.

      I got Table1 --(parent of)--> Table2 --(parent of)--> Table3

      After using the datadesigner to drag n drop the fields from the datasources pane to my form, I can navigate Table1... Table2 and Table3 follows.

      Note: If I navigate Table1 and Table2 has no data, then Table3 will not display data also because it is connected to Table2.

      Then, I need to change the bindings of Table3 to point it to its true table due to certain requirements.

      When I navigate Table1, only Table2 follows. So I did the code in my previous post to make Table3 follow programatically .

      The problem is (see note above), If I navigate Table1 and Table2 has no data, I do not know what I should do to the Table3 bindingsource to make it blank like Table2.

      I tried Table3bindingso urce.Filter = "PrimaryKey ='" & directcast(Tabl e2bindingsource .current, datarowview)("F oreignKey") & "'"

      or Table3bindingso urce.position = -1

      or dumber Table3bindingso urce.EOF = True

      ERROR!

      Comment

      • Shashi Sadasivan
        Recognized Expert Top Contributor
        • Aug 2007
        • 1435

        #4
        ok,
        so you should be using the position changed event of the navigators to accomplish this.
        on the change evnd of the 2nd tables navigator, check if there is any data, using bindingNavigato r.Count.
        if this value is zero then clear the dataTable

        using dataTable.Clear

        cheers
        This is how I do it, a little learning is needed to make it as flawless as possible

        Comment

        • nev
          Contributor
          • Oct 2007
          • 251

          #5
          Originally posted by Shashi Sadasivan
          ok,
          so you should be using the position changed event of the navigators to accomplish this.
          on the change evnd of the 2nd tables navigator, check if there is any data, using bindingNavigato r.Count.
          if this value is zero then clear the dataTable

          using dataTable.Clear

          cheers
          This is how I do it, a little learning is needed to make it as flawless as possible
          Based on your suggestion, I have tried this code just to check it out:

          In Table2bindingso urce currentchanged event

          if Table2bindingso urce.count > 0 then
          msgbox("Greater ")
          else
          msgbox("Less or Equal")
          end if

          When I navigate Table1 and Table2 has data, no problem. But when I encounter a Table2 without data, errorhandler fires even before my messagebox "Less or Equal" displays. Can I do this without having to modify the errorhandler? The problem lies in the 'else' statement.

          Comment

          • Shashi Sadasivan
            Recognized Expert Top Contributor
            • Aug 2007
            • 1435

            #6
            Originally posted by nev
            Based on your suggestion, I have tried this code just to check it out:

            In Table2bindingso urce currentchanged event

            if Table2bindingso urce.count > 0 then
            msgbox("Greater ")
            else
            msgbox("Less or Equal")
            end if

            When I navigate Table1 and Table2 has data, no problem. But when I encounter a Table2 without data, errorhandler fires even before my messagebox "Less or Equal" displays. Can I do this without having to modify the errorhandler? The problem lies in the 'else' statement.
            instead of the msgbox of les or equal, clear data from table 3. using the Clear method of it.

            Comment

            • nev
              Contributor
              • Oct 2007
              • 251

              #7
              Originally posted by Shashi Sadasivan
              instead of the msgbox of les or equal, clear data from table 3. using the Clear method of it.
              Ok. I tried

              Dataset.Table3d atatable... ---> There is no clear method here so I tried...

              Table3bindingso urce.clear

              ERROR! The statement Table3bindingso urce.clear becomes highlighted in green.

              Comment

              Working...