Bound Form Dirty

This should be fall off the log simple for a brand new development environment, but...
In VS2005 b2 I have a bound windows form. How do I determine if the user has made changes to the data?
TIA
[203 byte] By [BobHeitzman] at [2007-12-16]
# 1
Is it bound to a dataset? If so you could check the version property of the row in the dataset.
Txghia58 at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2
OK- so it isn't simple.

I am amazed that such a common need as determining if any changes have been made to bound data is not supported in a simple boolean somewhere.

How do I check the 'version' property (there does not appear to be a 'version' property on any of may objects that is of use) of a row?

My form does use a dataset and can have one or more rows. VS2005 B2 VB is the platform. The dataset is connected to SQL Server 2000.

I have tried using Me.MyTableBindingSource.Current to get a DataRowView of the displayed row. This object does not have a DataRowState which would be useful. It does have a DataRowVersion but it always seems to return 'Current' as the value when I check the Local value.

I am trying to write a function like this:

Function DirtyRow(ByVal row As System.Data.DataRowView) As Boolean

DirtyRow = (row.RowVersion <> Data.DataRowVersion.Original)

End Function

Called by:

If DirtyRow(Me.MyTableBindingSource.Current) Then...


Note this call uses the binding source and not the DataSet. I don't see a way to get a row from the dataset that corresponds to the displayed data.

Do I have to resort to monitoring keystrokes to set my own dirty flag? Sad.

BobHeitzman at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
Txghia58 wrote:
Is it bound to a dataset? If so you could check the version property of the row in the dataset.

Could someone give an example of how to do this assuming the form is bound to a dataset created by dragging a table from the Data Sources pane in the IDE?

TIA

BobHeitzman at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4

I dont know if you ever got an answer but here is my sample

Sub chk()

Dim ans As Boolean = False

If Me.TestSigCapDataSet.HasChanges Then Me.Text = "HasChanges=Yes " Else Me.Text = "HasChanges=No "

If CType(Me.LoginsBindingSource.Current, DataRowView).Row.HasVersion(DataRowVersion.Proposed) Then

ans = True

End If

Me.Text += " HasProposed=" + ans.ToString

End Sub

jerry C

JerryCic at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 5
You can listen for one of the change events and flag a boolean to true once a change occurs.
JaredParsonsMSFT at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 6

What events?

This issue is exactly the issue i am trying to get an answer for in my current post at

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=696784&SiteID=1

If you have any insight i would be very happy.

Jerry Cicierega

JerryCic at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 7
Why not bind to RowChanged on all of the DataTables in the DataSet?
JaredParsonsMSFT at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 8

It appears that the 'RowChanged' event only fires after the acceptchanges in invoked. This is well after any HasChanges flags have been set. And after any column data is assigned a 'proposed' version value.

I myself am looking for an event that fires as soon as the DataRow.HasVersion(DataRowVersion.Proposed) becomes true.

This occurs when any edit occurs, even before HasChanges becomes true. In order for HasChanges to become true, the EndEdit must be invoked for the current row or the CurrencyManager.Position must change.

Jerry Cicierega

JerryCic at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...