Update changes in a cell of a DataGridView to datatable without move to next cell

aboobackerpm

Member
Joined
Oct 23, 2007
Messages
5
Programming Experience
5-10
I am using a binded dgv with datatable my problem is how i can update the changes in a cell of a dgv to datatable without move to next cell

my dgv's allow addnew property is false because of that if user is in last row he cannot go to next row after changes, without go to next row dgv data does not updating the datatable.



Thanks in Advance
 
Use the CellValueChanged event handler for that:

VB.NET:
Private Sub DataGridView1_CellValueChanged(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
Dim changes As DataTable = dt.GetChanges
  If Not changes Is Nothing Then
      da.Update(changes)
      dt.AcceptChanges()
  End If
End Sub
 
I just gave you sample. da stands for dataadapter while dt stands for datatable. so reread the post. Maybe you will see what it actually does?
 
Re: Update..........

I read your replay, and try but in cell value changed event dt.getchanges always nothing only after leave from the current row the dt.getchanges is active, any other solution
 
Hi

After make changes in datagridview cell, without moving to the next row it is unable to save the data if I am using toolbar button for save operation but I can save if I click any command button or textbox proir to toolbar button click.

That means lost focus is required from the datagridview for saving any data.

I tried the endedit of dgv still datatable getchanges is nothing

Is there any solution to resolve this problem?

Is this a bug in datagridview?



Regards
 
you can do a sort first to effect a datagridview refresh on datatable, then update the dataadapter. E.g.
dgv.Sort(dgv.Columns("Code"), ListSortDirection.Ascending)
da.Update(dt)
 
Back
Top