Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a datagridview with 5 columns. Based on first column selected I want to skip validation. In the following code, it is not hapenning. The error is shown as if no row is selected.

C#
validator = new Regex(@"^[0-9]{0}[0-9A-Z]$");
           if (!validator.IsMatch(dataGridView1.Text))
               errors.AppendLine("Select order No. from grid");


How to solve this?
Posted

1 solution

You should change the validation condition like bellow:

C#
if ( !(dataGridView1.CurrentCell.ColumnIndex  == 0 && dataGridView1.SelectedCells.Count > 0) && !validator.IsMatch(dataGridView1.Text))
    errors.AppendLine("Select order No. from grid");
 
Share this answer
 
v4
Comments
S.Rajendran from Coimbatore 31-Mar-14 1:40am    
I tried with your validation condition but still is not escaping.
Raul Iloc 31-Mar-14 1:44am    
Are you shore that you are talking about the selection of the first column and not about the selection of the first row or first cell?
S.Rajendran from Coimbatore 31-Mar-14 1:56am    
I intend to select the first cell of any row as per choice.
Raul Iloc 31-Mar-14 2:05am    
See my update in my solution!
S.Rajendran from Coimbatore 31-Mar-14 2:23am    
Now, what happens is that even if I dont select any rows, it escapes and not showing error. In short, if I select or dont select it is not validating.

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