how to see if data changed in DataGrid

Discussion in 'Microsoft ADO .NET' started by DraguVaso, Aug 30, 2004.

  1. DraguVaso

    DraguVaso Guest

    Hi,

    How can I see if the Data is changed by the user in my DataGrid so I can ask
    him to save the changes or not?

    Thanks,

    Pieter
     
    DraguVaso, Aug 30, 2004
    #1
    1. Advertisements

  2. DraguVaso

    Cor Ligthert Guest

    Pieter,

    You can check if the underlaying datatable has changes.

    Unluckely there is no method datatable.haschanges.

    So you should use a workaround something as pseudo

    myNewTable as new datatable = datasource.table.getchanges
    And than test if that is filled with rows.

    I hope that this gives an idea?

    Cor
     
    Cor Ligthert, Aug 30, 2004
    #2
    1. Advertisements

  3. DraguVaso

    DraguVaso Guest

    Hm thanks, that seems to work.
    But what if I have 2 bound DataTables in my DataGrid, and I wan't only do
    the check on the records that are currently in the DataView?

    Pieter

    "Cor Ligthert" <> wrote in message
    news:...
    > Pieter,
    >
    > You can check if the underlaying datatable has changes.
    >
    > Unluckely there is no method datatable.haschanges.
    >
    > So you should use a workaround something as pseudo
    >
    > myNewTable as new datatable = datasource.table.getchanges
    > And than test if that is filled with rows.
    >
    > I hope that this gives an idea?
    >
    > Cor
    >
    >
     
    DraguVaso, Aug 30, 2004
    #3
  4. DraguVaso

    Cor Ligthert Guest

    Pieter,

    The dataview has as well a table property which tells which table it
    references

    Cor

    > Hm thanks, that seems to work.
    > But what if I have 2 bound DataTables in my DataGrid, and I wan't only do
    > the check on the records that are currently in the DataView?
    >
     
    Cor Ligthert, Aug 30, 2004
    #4
  5. You could also make a loop foreach through all rows and check their RowState
    property - it should be even faster than calling GetChanges.

    --
    Miha Markic [MVP C#] - RightHand .NET consulting & development
    miha at rthand com
    www.rthand.com

    "DraguVaso" <> wrote in message
    news:%23$...
    > Hi,
    >
    > How can I see if the Data is changed by the user in my DataGrid so I can
    > ask
    > him to save the changes or not?
    >
    > Thanks,
    >
    > Pieter
    >
    >
     
    Miha Markic [MVP C#], Aug 30, 2004
    #5
  6. DraguVaso

    Cor Ligthert Guest

    Miha,

    I like to have the datatable.haschanges

    And in a chat was told that they where thinking about it. I think it is
    easier than making for every table an own dataset what is as well an
    alternative.

    Do you understand now?

    However I do not think that looping or getchanges would make difference.

    :)

    Cor
     
    Cor Ligthert, Aug 30, 2004
    #6
  7. DraguVaso

    DraguVaso Guest

    Thanks,

    I gave it a try and it looked at least as fast as the solution of Cor. Maybe
    I'm gonna see a difference when I work with bigger DataSets.

    Thanks a lot!

    Pieter


    "Miha Markic [MVP C#]" <miha at rthand com> wrote in message
    news:ea4A%...
    > You could also make a loop foreach through all rows and check their

    RowState
    > property - it should be even faster than calling GetChanges.
    >
    > --
    > Miha Markic [MVP C#] - RightHand .NET consulting & development
    > miha at rthand com
    > www.rthand.com
    >
    > "DraguVaso" <> wrote in message
    > news:%23$...
    > > Hi,
    > >
    > > How can I see if the Data is changed by the user in my DataGrid so I can
    > > ask
    > > him to save the changes or not?
    > >
    > > Thanks,
    > >
    > > Pieter
    > >
    > >

    >
    >
     
    DraguVaso, Aug 30, 2004
    #7
  8. Hi Cor,

    "Cor Ligthert" <> wrote in message
    news:...
    > Miha,
    >
    > I like to have the datatable.haschanges


    Yes, me too :)

    >
    > And in a chat was told that they where thinking about it. I think it is
    > easier than making for every table an own dataset what is as well an
    > alternative.
    >
    > Do you understand now?


    Yes, I did understand before, too :)
    >
    > However I do not think that looping or getchanges would make difference.


    Oh, it does make a difference.
    Imagine a table with 10000 rows and all of them are changed.
    If you invoke GetChanges you'll get back a nice copy of entire table while
    using a loop, there is no overhead of data returned and you can stop at the
    first changed row: :)

    --
    Miha Markic [MVP C#] - RightHand .NET consulting & development
    miha at rthand com
    www.rthand.com
     
    Miha Markic [MVP C#], Aug 30, 2004
    #8
  9. DraguVaso

    Cor Ligthert Guest

    Miha,

    > Oh, it does make a difference.
    > Imagine a table with 10000 rows and all of them are changed.
    > If you invoke GetChanges you'll get back a nice copy of entire table while
    > using a loop, there is no overhead of data returned and you can stop at

    the
    > first changed row: :)


    You win this time, I did not think on that, good one.

    :)

    Cor
     
    Cor Ligthert, Aug 30, 2004
    #9

  10. > You win this time, I did not think on that, good one.
    >
    > :)
    >


    That makes Slovenia: Netherland 1:0 :)
    Hey Cor, many people, many solutions. Sometimes you win sometimes you don't.
    However, it is not about wining, I really like to see many different
    solutions - so I can learn.

    --
    Miha Markic [MVP C#] - RightHand .NET consulting & development
    miha at rthand com
    www.rthand.com
     
    Miha Markic [MVP C#], Aug 30, 2004
    #10
  11. Hi,

    In addition to the other replies you can use the currencymanger
    currentchanged event to be notified of data being changed.


    Dim ds As New DataSet

    Dim WithEvents cm As CurrencyManager



    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load

    Dim strConn As String

    Dim strSQL As String

    Dim da As OleDbDataAdapter





    strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"

    strConn &= "Data Source = Northwind.mdb;"



    conn = New OleDbConnection(strConn)

    da = New OleDbDataAdapter("Select * From Categories", conn)

    da.Fill(ds, "Categories")

    DataGrid1.DataSource = ds.Tables("Categories")



    cm = CType(Me.BindingContext(DataGrid1.DataSource), CurrencyManager)

    End Sub



    Private Sub cm_CurrentChanged(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles cm.CurrentChanged

    MessageBox.Show("Item Changed")

    End Sub


    Ken
    --------------------------------------
    "DraguVaso" <> wrote in message
    news:%23$...
    Hi,

    How can I see if the Data is changed by the user in my DataGrid so I can ask
    him to save the changes or not?

    Thanks,

    Pieter
     
    Ken Tucker [MVP], Aug 31, 2004
    #11
  12. DraguVaso

    DraguVaso Guest

    "Miha Markic [MVP C#]" <miha at rthand com> wrote in message
    news:...
    >


    > That makes Slovenia: Netherland 1:0 :)


    And like usually the Belgians didn't even qualify... ;-)
     
    DraguVaso, Sep 2, 2004
    #12
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ramica
    Replies:
    1
    Views:
    258
  2. MadCrazyNewbie

    Datagrid Postion Changed Bining Problem (Re-Post)

    MadCrazyNewbie, Mar 30, 2004, in forum: Microsoft ADO .NET
    Replies:
    0
    Views:
    159
    MadCrazyNewbie
    Mar 30, 2004
  3. Oriane
    Replies:
    2
    Views:
    252
    Oriane
    Mar 24, 2005
  4. Replies:
    0
    Views:
    213
  5. Don
    Replies:
    1
    Views:
    206
Loading...

Share This Page