Click here to Skip to main content
14,691,272 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,
i m new to .net.
i want to know how to change colors of rows in gridview for selected data..
please help me...

for example if i have a gridview having data like table of employees and i want change the color of salary of those whose name is started with "s"...
Posted
Updated 9-Jul-11 22:02pm
v2

   
Comments
Monjurul Habib 10-Jul-11 5:38am
   
nice link, my 5.
   
Comments
Monjurul Habib 10-Jul-11 5:41am
   
I don't think OP is looking for hover. "i want change the color of salary of those whose name is started with "s"... "...so first read the question carefully then answer. Anyway, the link is good.
Try
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
       {
           int colIndex = e.ColumnIndex;
           int rowIndex = e.RowIndex;

           if (rowIndex >= 0 && colIndex >= 0)
           {
               DataGridViewRow theRow = dataGridView1.Rows[rowIndex];
               if (theRow.Cells[colIndex].Value.ToString().StartsWith("S"))   // Check Cell Value is start with S
                   theRow.DefaultCellStyle.BackColor = Color.Red;       // write Color Name as you wish
           }
       }
   

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