you guys are super active on this board! you've got like 5 responses since yesterday afternoon on this
I actually got to work what Amber's original request was - I got the OnChange to fire for the underlying text box control that is in the control array of the datagrid. And if that's not confusing, it probably should be.
When I changed a text box - or when I typed anything into my text box, it fired my little OnChange for every single character typed in, which IMHO became an almost useless event handler, and I started to re-consider W.G.Ryan's original response (and to regret my response, and to hope that he didn't start a flame war on me). The OnCellChanged is probably the best place to handle a change to the data.
Here's a brief snippet from MSDN:
Private Sub DataGrid1_Curre ntCellChanged(B yVal sender As Object, ByVal e As System.EventArg s) Handles DataGrid1.Curre ntCellChanged
Dim myString As String = "CurrentCellCha nged event raised, cell focus is at "
' Get the co-ordinates of the focussed cell.
Dim myPoint As String = DataGrid1.Curre ntCell.ColumnNu mber.ToString() + "," + DataGrid1.Curre ntCell.RowNumbe r.ToString()
' Create the alert message.
myString = myString + "(" + myPoint + ")"
' Show Co-ordinates when CurrentCellChan ged event is raised.
MessageBox.Show (myString, "Current cell co-ordinates")
End Sub
---------------
Here's the ugly thing to associate an event with the underlying control:
' how to add the event listener for all the text boxes?
For i As Integer = 0 To Me.dgEquipment. Controls.Count - 1
Dim ctl As System.Windows. Forms.Control = Me.dgEquipment. Controls.Item(i )
System.Console. Write(ctl.GetTy pe().Name)
System.Console. Write(" ")
System.Console. Write(ctl.Text)
System.Console. WriteLine("")
If (ctl.GetType(). Name = "DataGridTextBo x") Then
AddHandler ctl.TextChanged , AddressOf txtQuantity_Nul lTextChanged
'OnTextChanged
End If
Next
Private Sub txtQuantity_Nul lTextChanged(By Val sender As Object, ByVal e As System.EventArg s) Handles txtQuantity.Nul lTextChanged
System.Windows. Forms.MessageBo x.Show(" changed ")
End Sub
I gave up on this approach in favor of W.G.Ryan's ... but you could associate any event you wanted, I suppose. And you could associate it only with certain columns, if you wanted.
This thread is turning out to be fruitful for me (I didn't know about the IsDirty thing , getting to the underlying controls was handy, and in the course of this I found some really cool stuff about putting all kinds of user controls in the data grid:
http://www.codeproject.com/cs/miscct...asp#xx983919xx (and their associated events)
But it is funny that while I did what Amber said she wanted, I didn't like it.
W.G.Ryan answered what she didn't ask, and I'm using it.
Amber actually meant something other than what she said, W.G. took care of that too, and it helped everybody.
And maybe more.
--
Message posted via
http://www.dotnetmonster.com