Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi,

DataGrid view has data populated from excel sheet.
I want to compare COLUMN 2[PR_NO] and COLUMN 3[STUDY_NO] in datagrid view for each row.
I used several events such as CELL_VALIDATING, CELL_VALIDATE, each ain't working.

Can you please help with event and piece of code so that i can learn.
Thanks in Advance.


P.S. In Gridview, this can be in RowDataBound event but couldn't find such event in DataGridview.
Posted
Updated 23-Sep-12 4:06am
v3
Comments
Sandeep Mewara 23-Sep-12 10:07am    
RowDataBound event is present for Grids in ASP.NET (web application). What you are trying is a Winforms.
Vineet_2109 23-Sep-12 14:01pm    
Yes, i know and i am asking about similar event for winForm which could help.
[no name] 23-Sep-12 10:11am    
"ain't working" is not a description of any kind of a problem. So you don't have a real question you are just looking for a tutor?
Vineet_2109 23-Sep-12 14:00pm    
Yes, if i can get a tutorial then its perfectly fine. Afterwards i will implement in my project.
Rajesh Kuramdasu 24-Sep-12 14:07pm    
Using a DataTable can help the comparisons a lot easier.

1 solution

Try this:
C#
var mylist = new[] {
                new{ A = 1, B = 1},
                new {A = 2, B = 2},
                new {A = 3, B = 2},
                new {A = 4, B = 4}};
            
dataGridView1.DataSource = mylist;
Load += (sender, e) =>
     {
        foreach (DataGridViewRow row in dataGridView1.Rows)
        {
          if((int)row.Cells["A"].Value != (int)row.Cells["B"].Value) 
              row.DefaultCellStyle.BackColor = Color.Red;
        }                
     };


Please remember that, the DefaultCellStyle.BackColor is set successfully for a particular row of datagridview only when the form is loaded. I searched for this before posting my code here for you.

Hope it helps!
 
Share this answer
 
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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