Question

I'm using an Xceed grid bound with a DataSet/DataTable. The thing is, I need to know if changes were made before loading new datas in the grid and therefore, losing changes if I don't save them then.

But neither the DataSet nor DataTable's function getChanges([DataRowState]) return the right thing :S

I've found that sometimes dataColumnChangeEvent is called, but NOT dataRowChangeEvent, these are the times where the changes are not saved into the getChanges() function.

This happens when I click out of the grid while in an editing cell instead of selecting an other of the grid's cell by any way.

Also, I've looked and the rowState is to Unchanged, even if the data do is changed :S

Any ideas?

Was it helpful?

Solution

Great! I've finnaly found a solution.

Even if the dataRowChangeEvent doesn't seem to be called (I'll explain latter)

If the only code in the rowChangeEvent is the code below it works :

Private Sub RowChanged(ByVal sender As Object, ByVal e As DataColumnChangeEventArgs)
    If e.Row.RowState = DataRowState.Unchanged Then
        e.Row.AcceptChanges()
        e.Row.SetModified()
    End If
End Sub

We check the rowState because we can only setModified() a row wit the Unchanged state.

We do AcceptChanges() because doing only setModified() removes the changes on the edited cell.

We do SetModified(0 because if not AcceptChanges() leaves the RowState to Unchanged and therefor it doesn't get in the table's getChanges.

EDIT : This brings an other problem, the dataAdapter uses the datarow's original and current Value to do update, delete and insert, doing "acceptChanges" set OriginalValue to the current Value so delete and Update doesn't work anymore :(

--More--

When I said it doesn't seem to get in the event, it's because the code below :

Private Sub RowChanged(ByVal sender As Object, ByVal e As DataColumnChangeEventArgs)
    If e.Row.RowState = DataRowState.Unchanged Then
        e.Row.AcceptChanges()
        e.Row.SetModified()
    End If
    MessageBox.Show("hasError=" & IIf(e.Row.HasErrors, "true ", "false ") & _
                    "; action=" & e.ProposedValue)
End Sub

neither Shows the message Box nor get the changes in the dataTable's getChanges()...

Also, having only

MessageBox.Show("Changing")

instead of the previons messageBox, Do show the messageBox, and Do get the changes right, BUT it then kindof breaks the event so it doesn't go further in the newProjectSelected => no new project is loaded, but it only needs a "re-clic".

So, I've explained how it behaves.

But it's soo strange, I'de appreciate if someone would explaine shuch behaviour.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top