Binding currencyManager and dataRelation - datagridview - possible

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

    #1

    Binding currencyManager and dataRelation - datagridview - possible

    Hello,

    Following an example at

    http://www.vb-tips.com/dbpages.aspx?IA=DG (by Cor Lightert and Ken Tucker)

    on binding a dataRelation to a Datagridview for sqlClient, I was able to
    view rows in datagridview2 that corresponded to a selected row in
    datagridview1. Great article/example.

    Now I am navigating through the primary table using currencyManager and
    displaying the data in textboxes rather than a datagridview. But I am still
    using a datagridview for the secondary table. I bind the currencymanager to
    the primary table, and I have a datarelation between the primary table and
    the secondary table. But when I move to another row in the primary table
    using the currencymanager , the datagridview is not displaying the
    corresponding rows in the secondary table.

    Is there a way I can navigate the primary table using currency manager and
    display the corresponding rows of the secondary table in the datagridview
    using the datarelation? I was previously using a dataview and the
    dataview.Rowfil ter for synchronizing the datagridview rows with the current
    row in the primary table. This technique worked, but I believe the
    datarelation method is better. Here is the code I am using for the
    datarelation and currencty manager technique:

    Priavate Sub Form1_Load(...)
    ....
    Dim daPrimary As New SqlClient.SqlDa taAdapter("Sele ct * From PrimaryTbl",
    conn)
    Dim daSecondary As New SqlClient.SqlDa taAdapter("Sele ct * From
    SecondaryTbl", conn)

    daPrimary.Fill( ds, "Prinmary")
    daSecondary.Fil l(ds, "Secondary" )

    ds.Relations.Ad d("relPrimarySe condary", ds.Tables("Prim ary").Columns(" ID"),
    ds.Tables("Seco ndary").Columns ("SubID"))
    DataGridView1.D ataSource = ds
    DataGridView1.D ataMember = "Primary.relPri marySecondary"

    curMgr = CType(Me.Bindin gContext(ds.Tab les("Primary")) , CurrencyManager )
    curMgr.Position = 0

    Me.txt0.DataBin dings.Add("Text ", ds.Tables("Prim ary"), "ID")
    Me.txt1.DataBin dings.Add("Text ", ds.Tables("Prim ary"), "fName")
    Me.txt2.DataBin dings.Add("Text ", ds.Tables("Prim ary"), "lName")
    End Sub

    Private Sub btn1_Click(...)
    curMgr.Position += 1
    End Sub

    The currencymanager will iterate through the primary table. Is it possible
    to synchronize the datagridview with the primary table using a datarelation?
    How to do this?

    Thanks,
    Rich

  • Rich

    #2
    RE: Binding currencyManager and dataRelation - datagridview - possible

    I came up with one solution for using currencyManager and synchronizing rows
    from primary table to datagridview2, but it is not ideal because it involves
    binding currencymanager to datagridview1, so my textboxes do not display the
    current data.. The goal is to be able to iterate through Primary table and
    display that data in the textboxes and the corresponding rows in
    datagridview2. I also tried some code that will bind the currencyManager to
    the dataRelation, but does not iterate through the Primary table. Here is
    what I have so far which uses the currencyManager bound to datagridview1:
    _______________ _______________ _______________ _
    ....
    curMgr = CType(Me.DataGr idView1.Binding Context(ds, "Primary"),
    CurrencyManager )
    DataGridView1.D ataSource = ds
    DataGridView2.D ataSource = ds

    DataGridView1.D ataMember = "Primary"
    DataGridView2.D ataMember = "Primary.relPri marySecondary"
    End Sub

    Sub curMrgInc()
    curMgr.Position =+ 1
    End Sub
    -----------------------------------------------------
    Here is the binding of currencyManager to the datarelation:

    curMgr = CType(Me.Bindin gContext(ds, "Primary.relPri marySecondary") ,
    CurrencyManager )

    But this does not iterate anything. My alternative would be to have 2
    currencyManager s - One for the datagridviews and one for the textboxes. The
    goal is to be able to iterate through Primary Table - display the current row
    in the textboxes and display the corresponding rows from Secondary Table in
    the datagridview - using only one currencyManager . The only way I have been
    able to do this so far is by using Dataview.Rowfil ter. How can I bind
    currencyManager to Primary Table and have Secondary Table synchronized with
    Primary?


    "Rich" wrote:
    [color=blue]
    > Hello,
    >
    > Following an example at
    >
    > http://www.vb-tips.com/dbpages.aspx?IA=DG (by Cor Lightert and Ken Tucker)
    >
    > on binding a dataRelation to a Datagridview for sqlClient, I was able to
    > view rows in datagridview2 that corresponded to a selected row in
    > datagridview1. Great article/example.
    >
    > Now I am navigating through the primary table using currencyManager and
    > displaying the data in textboxes rather than a datagridview. But I am still
    > using a datagridview for the secondary table. I bind the currencymanager to
    > the primary table, and I have a datarelation between the primary table and
    > the secondary table. But when I move to another row in the primary table
    > using the currencymanager , the datagridview is not displaying the
    > corresponding rows in the secondary table.
    >
    > Is there a way I can navigate the primary table using currency manager and
    > display the corresponding rows of the secondary table in the datagridview
    > using the datarelation? I was previously using a dataview and the
    > dataview.Rowfil ter for synchronizing the datagridview rows with the current
    > row in the primary table. This technique worked, but I believe the
    > datarelation method is better. Here is the code I am using for the
    > datarelation and currencty manager technique:
    >
    > Priavate Sub Form1_Load(...)
    > ...
    > Dim daPrimary As New SqlClient.SqlDa taAdapter("Sele ct * From PrimaryTbl",
    > conn)
    > Dim daSecondary As New SqlClient.SqlDa taAdapter("Sele ct * From
    > SecondaryTbl", conn)
    >
    > daPrimary.Fill( ds, "Prinmary")
    > daSecondary.Fil l(ds, "Secondary" )
    >
    > ds.Relations.Ad d("relPrimarySe condary", ds.Tables("Prim ary").Columns(" ID"),
    > ds.Tables("Seco ndary").Columns ("SubID"))
    > DataGridView1.D ataSource = ds
    > DataGridView1.D ataMember = "Primary.relPri marySecondary"
    >
    > curMgr = CType(Me.Bindin gContext(ds.Tab les("Primary")) , CurrencyManager )
    > curMgr.Position = 0
    >
    > Me.txt0.DataBin dings.Add("Text ", ds.Tables("Prim ary"), "ID")
    > Me.txt1.DataBin dings.Add("Text ", ds.Tables("Prim ary"), "fName")
    > Me.txt2.DataBin dings.Add("Text ", ds.Tables("Prim ary"), "lName")
    > End Sub
    >
    > Private Sub btn1_Click(...)
    > curMgr.Position += 1
    > End Sub
    >
    > The currencymanager will iterate through the primary table. Is it possible
    > to synchronize the datagridview with the primary table using a datarelation?
    > How to do this?
    >
    > Thanks,
    > Rich
    >[/color]

    Comment

    • Cor Ligthert [MVP]

      #3
      Re: Binding currencyManager and dataRelation - datagridview - possible

      Rich,

      I did not investigate your latest problem, but I am afraid I did this
      already to often.

      I have the idea that you are now at the limitations of the relations about
      which I was speaking in the first messages of the problem.

      At least I cannot reach the currency manager with the relations. Therefore
      we have as well that sample of faking a datarelation on our website using
      the dataview.

      Does not helps you, but maybe it helps, that you are not the only one with
      this problem.

      Cor

      "Rich" <Rich@discussio ns.microsoft.co m> schreef in bericht
      news:99D4676E-CC7D-4D3B-AFEA-382422B0136B@mi crosoft.com...[color=blue]
      >I came up with one solution for using currencyManager and synchronizing
      >rows
      > from primary table to datagridview2, but it is not ideal because it
      > involves
      > binding currencymanager to datagridview1, so my textboxes do not display
      > the
      > current data.. The goal is to be able to iterate through Primary table
      > and
      > display that data in the textboxes and the corresponding rows in
      > datagridview2. I also tried some code that will bind the currencyManager
      > to
      > the dataRelation, but does not iterate through the Primary table. Here is
      > what I have so far which uses the currencyManager bound to datagridview1:
      > _______________ _______________ _______________ _
      > ...
      > curMgr = CType(Me.DataGr idView1.Binding Context(ds, "Primary"),
      > CurrencyManager )
      > DataGridView1.D ataSource = ds
      > DataGridView2.D ataSource = ds
      >
      > DataGridView1.D ataMember = "Primary"
      > DataGridView2.D ataMember = "Primary.relPri marySecondary"
      > End Sub
      >
      > Sub curMrgInc()
      > curMgr.Position =+ 1
      > End Sub
      > -----------------------------------------------------
      > Here is the binding of currencyManager to the datarelation:
      >
      > curMgr = CType(Me.Bindin gContext(ds, "Primary.relPri marySecondary") ,
      > CurrencyManager )
      >
      > But this does not iterate anything. My alternative would be to have 2
      > currencyManager s - One for the datagridviews and one for the textboxes.
      > The
      > goal is to be able to iterate through Primary Table - display the current
      > row
      > in the textboxes and display the corresponding rows from Secondary Table
      > in
      > the datagridview - using only one currencyManager . The only way I have
      > been
      > able to do this so far is by using Dataview.Rowfil ter. How can I bind
      > currencyManager to Primary Table and have Secondary Table synchronized
      > with
      > Primary?
      >
      >
      > "Rich" wrote:
      >[color=green]
      >> Hello,
      >>
      >> Following an example at
      >>
      >> http://www.vb-tips.com/dbpages.aspx?IA=DG (by Cor Lightert and Ken
      >> Tucker)
      >>
      >> on binding a dataRelation to a Datagridview for sqlClient, I was able to
      >> view rows in datagridview2 that corresponded to a selected row in
      >> datagridview1. Great article/example.
      >>
      >> Now I am navigating through the primary table using currencyManager and
      >> displaying the data in textboxes rather than a datagridview. But I am
      >> still
      >> using a datagridview for the secondary table. I bind the currencymanager
      >> to
      >> the primary table, and I have a datarelation between the primary table
      >> and
      >> the secondary table. But when I move to another row in the primary table
      >> using the currencymanager , the datagridview is not displaying the
      >> corresponding rows in the secondary table.
      >>
      >> Is there a way I can navigate the primary table using currency manager
      >> and
      >> display the corresponding rows of the secondary table in the datagridview
      >> using the datarelation? I was previously using a dataview and the
      >> dataview.Rowfil ter for synchronizing the datagridview rows with the
      >> current
      >> row in the primary table. This technique worked, but I believe the
      >> datarelation method is better. Here is the code I am using for the
      >> datarelation and currencty manager technique:
      >>
      >> Priavate Sub Form1_Load(...)
      >> ...
      >> Dim daPrimary As New SqlClient.SqlDa taAdapter("Sele ct * From PrimaryTbl",
      >> conn)
      >> Dim daSecondary As New SqlClient.SqlDa taAdapter("Sele ct * From
      >> SecondaryTbl", conn)
      >>
      >> daPrimary.Fill( ds, "Prinmary")
      >> daSecondary.Fil l(ds, "Secondary" )
      >>
      >> ds.Relations.Ad d("relPrimarySe condary",
      >> ds.Tables("Prim ary").Columns(" ID"),
      >> ds.Tables("Seco ndary").Columns ("SubID"))
      >> DataGridView1.D ataSource = ds
      >> DataGridView1.D ataMember = "Primary.relPri marySecondary"
      >>
      >> curMgr = CType(Me.Bindin gContext(ds.Tab les("Primary")) , CurrencyManager )
      >> curMgr.Position = 0
      >>
      >> Me.txt0.DataBin dings.Add("Text ", ds.Tables("Prim ary"), "ID")
      >> Me.txt1.DataBin dings.Add("Text ", ds.Tables("Prim ary"), "fName")
      >> Me.txt2.DataBin dings.Add("Text ", ds.Tables("Prim ary"), "lName")
      >> End Sub
      >>
      >> Private Sub btn1_Click(...)
      >> curMgr.Position += 1
      >> End Sub
      >>
      >> The currencymanager will iterate through the primary table. Is it
      >> possible
      >> to synchronize the datagridview with the primary table using a
      >> datarelation?
      >> How to do this?
      >>
      >> Thanks,
      >> Rich
      >>[/color][/color]


      Comment

      Working...