Dan
Dan

Reputation: 149

Datagridview's Datasource Doesn't Update Until Leaving Row

Sorry if this is answered elsewhere, I've searched all over and can't find an answer. I think my scenario is pretty simple.

I have a DataGridView who's DataSource is set to a DataTable. I handle the DataGridView's CellValueChanged event so that I can get the changes and decide what to do with them, like this:

Private Sub DataGridView1_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
    Dim dtChanges As DataTable = CType(DataGridView1.DataSource, DataTable).GetChanges
End Sub

The problem is that GetChanges seems to return Nothing until I leave the edited row. I can hit tab and it returns Nothing. The moment I hit the down arrow, GetChanges starts producing valid results.

Any ideas why it would do that? Or should I be handling a different event than CellValueChanged?

Upvotes: 0

Views: 67

Answers (1)

Dan
Dan

Reputation: 149

I'm not sure I exactly understand why, but Jimi's comment is correct. Calling Me.Validate before GetChanges causes the changes to properly show up in the datasource.

Upvotes: 0

Related Questions