开发者

How to cancel datagrid edit

I have a view that uses a usercontrol that contains a datagrid. The requirements for the view state that if a user deletes the value out of the "Customer Name" column then leaves the cell, don't commit the edit and change the value back t开发者_运维知识库o its original value - i.e. don't allow blank customer names. The usercontrol is shared code and is used between multiple applications. The edit cancellation requirement is specifically for the view mentioned above (not all applications that use the usercontrol). How do i detect the value for the Customer Name cell has been deleted and cancel the edit if the value is empty?


You can handle CellEditEnding - its Occurs before a cell edit is committed or canceled. Here you can validate current value of the cell, and if it satisfy your condition[s] you can do what ever you want. MSDN


Edit: Its my suggestions, but I can't approve it. You can get your new value via e.Row.Item, and cast it to object you put on DataGrid. Another way is cast sender object right way to get access for new cell value.

+1 is to DataGridCellEditEndingEventArgs.EditingElement. Its FrameworkElement, and I think you know what it is (probably TextBox, or something else).

also I think you know what you should to do!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜