how to see if data changed in DataGrid

  • Thread starter Thread starter DraguVaso
  • Start date Start date
D

DraguVaso

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
 
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
 
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
 
Pieter,

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

Cor
 
You could also make a loop foreach through all rows and check their RowState
property - it should be even faster than calling GetChanges.
 
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
 
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 said:
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 said:
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
 
Hi Cor,

Cor Ligthert said:
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,
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
 
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.
 
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
--------------------------------------
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
 
Back
Top