Strange Issue With VB .NET Datagrid - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Strange Issue With VB .NET Datagrid

YoShIe66YoShIe66 Posts: 6Member
I'm working on an application that uses a dataset containing four datatables and a single datagrid I use to display each of them as I need to see their contents. When the datagrid is displayed, I bind it's datasource attribute to the required datatable. On loading each of the tables, this works very well.

The problem I am seeing is that if I bring up table(0) or table(1) and then make changes to the datagrid directly, those changes are not carrying down to the connecting datatable. Also, if I make a change directly to table(0) or table(1) and then refresh the datagrid, I also do not see the changes.

What makes this even stranger is that if I then load either table(2) or table(3) (which are identical in design), they function as I would expect: changes to the dagarid carry directly to the connecting datatable and changes to the datatable are visible upon using refresh().

It almost appears as though the databinding between tables(0) and table(1) is getting broken immediately after the table is loaded into the datagrid (I can see the data in the grid upon loading, so I know for sure it gets atleast that far).

Anyone have an idea what could be causing this?

Comments

  • YoShIe66YoShIe66 Posts: 6Member
    After several hours of line-by-line tracing, I have managed to figure out what the problem was. It appears to be an error in the documentation on datasets. This is the problem:

    In the documentation (and I have checked it in several books and in Microsoft's help), in order to duplicate a dataset (and the contained tables), you are to use something like this:

    [code]Private Sub CopyDataSet(ByVal myDataSet As DataSet )
    ' Create an object variable for the copy.
    Dim copyDataSet As DataSet
    copyDataSet = myDataSet.Copy() <====
    ' Insert code to work with the copy.
    End Sub[/code]

    And of course, you are to use "clone()" to duplicate the structure but not the data, as below:

    [code]Private Sub GetClone(ByVal myDataSet As DataSet)
    ' Get a clone of the original DataSet.
    Dim cloneSet As DataSet
    cloneSet = myDataSet.Clone()
    ' Insert code to work with clone of the DataSet.
    End Sub[/code]

    Well, it turns out that for some reason, in Visual Studio 2003, the copy() is not correct. I was using it to duplicate a dataset into an object (which does all these calculations, etc) and then copying it back out to the parent form (from which it originally came). At the point where I used copy(), the dataset was not being properly copied. Instead, it acts more like clone() in that I get an empty dataset. The syntax that actually works for me looks more like this:

    [code]Private Sub CopyDataSet(ByVal myDataSet As DataSet )
    ' Create an object variable for the copy.
    Dim copyDataSet As DataSet
    copyDataSet = myDataSet
    ' Insert code to work with the copy.
    End Sub[/code]

    This copies both the dataset completely, as well as all of the tables within it (and their data), thus resolving the problem I was seeing. Basically, I was saving the tables properly (and doing the calcs), but then when the dataset was returned to the form, it was not properly being copied (thus the entries in my datagrid were being overwritten by duplicate "old" data)
Sign In or Register to comment.