I have a list of object bound to a DataGrid in a WPF page and I am looking to add an object directly after the current one if the value entered in a specific column is less than a certain number.
<my:DataGridTextColumn Binding="{Binding Path=Hours}"/>
I cannot for the life of me figure out how to bind to an event on the underlying TextBox. Various sites reference the ability to do this but none provide the associated code. For now I have been using a DataGridTemplateColumn with a TextBox inside of it but I don’t seem to the able to get the current row with that solution.
To accomplish this I used the
CellEditEndingevent on the data grid itself.In the method you can then use a
Dispatcherto delay the call to a method so the value is stored back in the bound object.You can also pass the
DataGridCellEditEndingEventArgsto the method to allow you to inspect the row and column of the cell that was edited along with the underlyingTextBox.Also since the data grid is concerned about objects the row index is not too relevant and therefore not easily obtainable (that I could find).