Get cell text in CellEditEnding

Jun 18, 2009 at 10:31 AM

Hi All,

I am stumped on something that should be really simple. Brain is sleepy today though :)

I am trying to get the text just entered into a cell when the CellEditEnding event is fired. I cannot find out how to get the text from the cell though. The Microsoft.Windows.Controls.DataGridCellEditEndingEventArgs arguement passed into the event does not have a property for accessing the cell and its text. Only the column.

Please would someone assist.


Jun 18, 2009 at 10:44 AM


you can get the edited string using

TextBox txt = e.EditingElement as TextBox;

string  strTxt = txt.ToString();

in CellEditEnding Event method

I hope, this will helps

Jun 18, 2009 at 10:47 AM

Thank-you nanpal76. This works 100%. Much appreciated!

Jun 18, 2009 at 10:51 AM

Wouldn't that assume a DataGridTextColumn, though? I'd be worried about other column types not faring so well with that code in place. Null dereference bug waiting to happen on that second line... (also, I'd use txt.Text rather than txt.ToString(), but in this case that's probably largely a matter of taste.)

Jun 18, 2009 at 10:56 AM

You are correct mikj. I however took nanpal76's suggestion as a the route to follow and it works. You would just need to typecast appropriately depending on the cell you were reading.
As mentioned, I did use .Text instead of .ToString().

Jun 18, 2009 at 10:58 AM

One side affect I am however having, is the CellEditEnding event is fired TWICE when I hit TAB to exit the cell. This is painful and I suppose I would need to create a workaround to ignore subsequent events.

Does anyone know the reason for this?

Sep 29, 2009 at 1:55 PM

Hi any one find a work around to this issue with the TAB key. And one more thing after the CellEditEnding event is fire the RowEditEnding is also fire. This is the expected behavior?


sorry for my english ;)