Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i need to change every third cell color into red its a 4 by 4 datagrid i struggle with what to use as my row and column index? this is what ive got

C#
private void btnred_Click(object sender, EventArgs e)
{
    int teller;

    for (teller = 1; teller <= 16; teller++)
    {
        DataGridViewCellStyle CellStyle = new DataGridViewCellStyle();
        CellStyle.BackColor = Color.Red;
        dgvArray.Rows[(this parts i dont know)].Cells[].Style = CellStyle; 
        teller += 1;
    }
}
Posted
Updated 9-Sep-12 7:34am
v2

1 solution

C#
foreach (DataGridViewRow row in dgvArray.Rows)
{
    DataGridViewCellStyle CellStyle = new DataGridViewCellStyle();
    CellStyle.BackColor = Color.Red;

    row.Cells["Third_Column_Name"].Style = CellStyle;
}


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)



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