Click here to Skip to main content
15,904,155 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,

Is it to possible to validate cells of datagridview using regular expression? Also i am loading datagridview using combo box i.e table names are provided in the combo box depending on the selection corresponding tables data will be loaded on to the grid view. And all the tables do not have same number columns. How to validate this. Please provide the solution

Thank you
Posted

 
Share this answer
 
Comments
RaviRanjanKr 16-Oct-11 17:28pm    
Comment by- manu g m
I need like suppose there are 4 columns in first table say, id,ename,ph,addr,email so i need to validate each cell of DGV against a regular expression and also when user loads second table which contians say ordeid,product, quantity even this table shld be validated when user changes cell data in DGV. i.e tables are loaded dynamically to DGV the corresponding DGV cells needs to be validated.

And assume there are 10 tables in a database and each have different column name and different number of columns. One table will be loaded at a particular time. How to validate the cells of all these tables. Please help.
Hi,

I assume you not looking for another architectural answer so.
Each table creates its own set of templates on the fly so there's no easy way to use the template to define your validations.

However each row has a rowdatabind method which is fired when things get bound.
You could intercept this add a validation control progammatically to the cell (linking it properly of course), you would need to source the regular expression from somewhere and databind that in.

Basically your rowdatabind method would become quite heavy with code to create your validations.

Another possiblity may be to loop through your grid after its bound and add the validation control in.

Hope this helps...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900