Hi,
I want to change a columns background color: dgvtxbQty.DefaultCellStyle.BackColor = System.Drawing.Color.White;
But on the Grid I have a AlternatingRowsDefaultCellStyle which set every other row format.
The problem is it overides the dgvtxbQty.DefaultCellStyle.BackColor & the backcolor only works for the rows not being set by the AlternatingRowsDefaultCellStyle
Is there a way around this?
Regards
Loading

Trinity105 reputationPosted Sep 29, 2009, 7:32 AM EDT
define an instance of DataGridviewcell cell in your code behind and define its background color
then assign it to the DataGridColum.celltemplate property
Roei BarRank #1,271 · 1.4K reputationPosted Sep 29, 2009, 10:21 AM EDT
on the Item_Create Event you can overwrite the Color
or on Item.DataBound
or you can do it all in the OnPreRender Event, that is the Last event for the Page to load and all Controls are already there, you can then go to the GridViewObject and alter the cell colors
ic ic80 reputationPosted Sep 30, 2009, 12:41 AM EDT
I'm not sure how to the instance on the codebehind (i'm a beginner) - please provide some code?
I also don't have a onPreRender Event on my DatagridView?
Please Assist!
Nagesh R14 reputationPosted Sep 30, 2009, 1:21 AM EDT
DataGridviewcell cell;
and then set the background color as required...
ic ic80 reputationPosted Sep 30, 2009, 2:28 AM EDT
DataGridView dgv = sender as DataGridView;
e.CellStyle.BackColor = dgv.Columns[e.ColumnIndex].DefaultCellStyle.BackColor;
but unfortunately the alternatingrowdefaultcellstyle still overides it
I removed the alternatingrowdefaultcellstyle but the RowSelectionColor is now overiding the cell background color.
??