c# - DataGridView Cell value not available for validation when inserting a new row -


situation:

i'm writing winforms app using c# in vs2013 .net4.0.

to carry out cell level validation in datagridview handle cellvalidating event. when validating access user input values with

dgv.rows[e.rowindex].cells[e.columnindex].value 

for validation of existing rows works fine.

issue:

when user types cell on new row , presses, example, tab move next cell cellvalidating event fires value contains null.

question:

how access user has typed in these circumstances? i'm thinking should maybe endedit before validating thought cellvalidating inherently "while-editing" event.

edit

the validation takes place in validator class top end of looks this:

    public void validatecell(string tablename, datagridview datagrid, datagridviewcellvalidatingeventargs e, columncatalogue columncatalogue)     {         if (!(datagrid.rows[e.rowindex].cells[e.columnindex].value == null ||                datagrid.rows[e.rowindex].cells[e.columnindex].value == dbnull.value ||               string.isnullorwhitespace(datagrid.rows[e.rowindex].cells[e.columnindex].value.tostring()))             )         {             columndetails columndetails = columncatalogue.getcolumndetails(tablename, datagrid.columns[e.columnindex].name);              switch (columndetails.datatype)             {                 case "currency":                     this.validatecurrency(datagrid, columndetails, e);                     break;                 case "date":                     this.validatedate(datagrid, columndetails, e);                     break;                 case "email":                     this.validateemail(datagrid, columndetails, e);                     break;                 case "int":                     this.validateint(datagrid, columndetails, e);                     break;                 case "phone":                     this.validatephone(datagrid, columndetails, e);                     break;                 case "postcode":                     this.validatepostcode(datagrid, columndetails, e);                     break;                 default:                     break;             }          }     } 

as data not yet validated can't in cell's value field.

instead input, entered user, both in editedformattedvalue field of cell..:

dgv.rows[e.rowindex].cells[e.columnindex].editedformattedvalue 

..and formattedvalue field of parameter e..:

e.formattedvalue 

note both of type object, already, after (usually) being entered string textbox eding control.

also note existing , filled cells, testing value field testing old, unedited values! don't have problem value inserted rows, have rows!


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -