WinForms: Knowing when DataGrid is changing.

  • Thread starter Thread starter M O J O
  • Start date Start date
M

M O J O

(using vb.net)

Hi,

Is it possible to get notified when a DataGrid has changed?

I've tried the MyDataTable.ColumnChanging/RowChanging, but they are only
triggered when the focus leaves the cell.

I want to get notified when the cell data is changing. That is when the
first key is pressed.

I need to enable a Save-button and it should be enabled when the first key
is pressed and not when cell focus is changed.

Any idea??

Thanks!

M O J O
 
Hi MOJO,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to get notified when text in
the DataGrid cell is changed. If there is any misunderstanding, please feel
free to let me know.

Based on my experience, we have to achieve this by handling the TextChanged
event of each textbox of the cell. When textboxes are added to the DataGrid
Control, a ControlAdded event will be fired. There we can get the reference
to each added control. And then register the event handler for each
textbox's TextChanged event. Here I have written some sample code. HTH.

Private Sub DataGrid1_ControlAdded(ByVal sender As Object, ByVal e As
System.Windows.Forms.ControlEventArgs) Handles DataGrid1.ControlAdded
AddHandler e.Control.TextChanged, AddressOf Me.CellText_Changed
End Sub

Private Sub CellText_Changed(ByVal sender As Object, ByVal e As
EventArgs)
MessageBox.Show("Changed")
End Sub

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top