Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
In the cellpainting event of the datagridview I have this code:
C#
private void dgvMain_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            
            if ((e.ColumnIndex == 0) && (e.RowIndex >= 0))
            {
		...
		}

the program does not get into the if statements because after I populate the datagridview, I use:
dgvMain.Columns["ID"].Visible = false;

Question: What is the solution please?
Thanks
Posted
Updated 1-Jun-12 4:47am
v2

1 solution

"What is the solution please?"
Don't check for column 0 if you hide it - because it won't get painted if it isn't visible. Hidiing doesn't re-order columns, or delete them - it just makes them invisible to the user (and thus not painted).

Try using the second column, or whichever one you do want to paint specially.
 
Share this answer
 
Comments
Maciej Los 1-Jun-12 10:50am    
+5!
arkiboys 1-Jun-12 10:55am    
Thank you
OriginalGriff 1-Jun-12 11:06am    
You're welcome!
VJ Reddy 3-Jun-12 8:21am    
Good answer. 5!

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