Click here to Skip to main content
15,896,539 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm using datagridview having 11 columns and 10 rows.
I'm using cell click event:

C#
if (dataGridView1[e.ColumnIndex, e.RowIndex].Style.BackColor == Color.Empty)
    dataGridView1[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.Black;
else
    dataGridView1[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.Empty;


It applies the new backcolor to all 11 columns but I want apply this code only to 10 columns.
In the last 11th columns I use numbers only.
Posted
Updated 24-Sep-14 22:53pm
v3
Comments
Leo Chapiro 25-Sep-14 4:49am    
You do that in a loop, don't you? Show us the WHOLE relevant source code please!

1 solution

add this check in the cell click event

C#
if(e.ColumnIndex<=10)
   {
     ////ur code shown in above question
   }


good luck ;-)
 
Share this answer
 
Comments
cadsolution 25-Sep-14 5:08am    
ok,but my 11th coloumn is not editable.when i press number its not enter value
george4986 25-Sep-14 5:11am    
"////ur code shown in above question" means

if (dataGridView1[e.ColumnIndex, e.RowIndex].Style.BackColor == Color.Empty)
dataGridView1[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.Black;
else
dataGridView1[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.Empty;


only not all code in cell click

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