Hi all,

I'm facing some difficulties with the getchanges method of a datatable...

In my program, I have a standalone datatable which I'm using as the datasource to a datagridview. When I make changes to the datagridview, and I use the getchanges(DataRowState.Modified) method, I get Nothing as the result, no matter what changes I made. I also tried using the table as bindingsource to the datagridview but this didn't help either. Can anybody please point me out what I'm doing wrong? Below is my code:

- usr is an object that contains a table named table
- dgv is a datagridview on my form
- the update sub is a member of usr which is called when a button on the form is clicked

BindingSource1.DataSource = usr.table
            BindingSource1.RaiseListChangedEvents = True
            dgv.DataSource = BindingSource1

public sub update()

dim tmpdt as new datatable
tmpdt = table.getchanges(DataRowState.Modified)

end sub

Thanks in advance.

This example code explains maybe :=)

Dim _DT As DataTable = Nothing

    Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        _DT = New DataTable
        _DT.BeginLoadData()

        For i As Integer = 0 To 5
            Dim _Col As DataColumn = New DataColumn("", System.Type.GetType("System.String"))
            _DT.Columns.Add(_Col)
            _Col.Dispose()
            _Col = Nothing
        Next

        For i As Integer = 0 To 5
            Dim _Row As DataRow = _DT.NewRow
            _Row.Item(0) = String.Format("Test {0}", i.ToString)
            _DT.Rows.Add(_Row)
        Next
        _DT.EndLoadData()
        _DT.AcceptChanges() 
        Me.BindingSource1.DataSource = _DT

        Me.DataGridView1.DataSource = Me.BindingSource1

    End Sub

    Private Sub BindingSource1_CurrentItemChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles BindingSource1.CurrentItemChanged
        Dim tmpTable As DataTable = _DT.GetChanges(System.Data.DataRowState.Modified)
        Me.DataGridView2.DataSource = tmpTable
    End Sub

MSDN says....

When you call AcceptChanges on the DataSet, any DataRow objects still in edit-mode end their edits successfully. The RowState property of each DataRow also changes; Added and Modified rows become Unchanged, and Deleted rows are removed.

Thanks 4advanced... with your help, I've managed to solve the problem... I had to call acceptchanges() after having set the datatable as binding source and subsequently the bindingsource as the datasource of the datagridview. Thanks.

This question has already been answered. Start a new discussion instead.