Wednesday, May 23, 2012

not-read-only DataGridView, but don't show input in datagridview after leaving, only show programmatical input

In my DataGridView users are able to input data. The DataGridView automatically changes its content when one of the properties of a correspondent list of objects changes with the help of events.



Now I want to give the DataGridView the following behavior: when the user inserts data, and then leaves the cell, the input should be validated. If the validation gives a positive result, the input is saved to an object. The datagridview should then show the input value in the correct format (eg. for a date).



I can make this work: the events between the list of objects and the datagridview can manage this.



The problem is: If the validation gives a negative result, the previous cell value should be restored.



I tried to use DataGridView.CellValidating event, but this doesn't work. What should I do?



SOLVED: I used e.Cancel. This doesn't really do what I thought it promissed. When I use DataGridView1.CancelEdit(), it works like I wanted.





No comments:

Post a Comment