开发者

How to validate a DataGridView Cell is not empty, when the user never enters the cell?

开发者 https://www.devze.com 2023-01-03 16:26 出处:网络
I just want to check and make sure that a cell has some data in it.My situation is I have 3 columns in a DataGridView.When someone adds a new record the rows are blank.The first column is a ComboBox,

I just want to check and make sure that a cell has some data in it. My situation is I have 3 columns in a DataGridView. When someone adds a new record the rows are blank. The first column is a ComboBox, the next two are just plain text. If someone just enters in one of the text boxes and doesn't select from the combobox, when they press save an exception is thrown since the DB wants that combobox value. How can I check that cell and make sure there is a value? CellValidating won't work since the cell never gets focus and loses focus.

I did end up checking the column in the RowValidating event and looped through the开发者_运维技巧 columns, checking if they are empty. This feels dirty, is that the only way?


Validating controls? They can give you both client side and server side validation.

http://msdn.microsoft.com/en-us/library/aa479013.aspx

0

精彩评论

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