Best way of detecting if a row has been added to dataGrid

  • Thread starter Thread starter Randy
  • Start date Start date
R

Randy

Hello,
Can someone tell me what is the best way of implementing the detection of
adding a row to a datagrid. I looked at using a DataView as the datasource
and the ListChanged event, but that didn't seem to work like I expected. It
seemed to fire only when I changed to another row in the grid, not when I
clicked on the little pencil icon on the left margin of the grid. Is the
ListChanged suppose to be used for this? If so, how?
Thanks for any help
Cheers :)
 
Randy,

Well, I can definitely see why this is. When you click on the little
pencil icon on the right, the grid shows the UI for a new record, but it
hasn't tried to add one yet. Not until you move off the row can the record
be added to the underlying data source. If you want to figure out when the
little pencil is clicked (a new record is added) then, I would handle the
MouseDown event and then pass the coordinates to the HitTest method to
determine where the grid was clicked. If it was the row headers, then you
can check which row, and then see if the row is a new row, and then perform
the appropriate action.

Hope this helps.
 
Yes, that definitely puts me in the right direction. Thanks for the help!

Nicholas Paldino said:
Randy,

Well, I can definitely see why this is. When you click on the little
pencil icon on the right, the grid shows the UI for a new record, but it
hasn't tried to add one yet. Not until you move off the row can the record
be added to the underlying data source. If you want to figure out when the
little pencil is clicked (a new record is added) then, I would handle the
MouseDown event and then pass the coordinates to the HitTest method to
determine where the grid was clicked. If it was the row headers, then you
can check which row, and then see if the row is a new row, and then perform
the appropriate action.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Randy said:
Hello,
Can someone tell me what is the best way of implementing the detection of
adding a row to a datagrid. I looked at using a DataView as the datasource
and the ListChanged event, but that didn't seem to work like I expected. It
seemed to fire only when I changed to another row in the grid, not when I
clicked on the little pencil icon on the left margin of the grid. Is the
ListChanged suppose to be used for this? If so, how?
Thanks for any help
Cheers :)
 
Back
Top