> In a bound grid, I would like to set the formatting of the column header based on the values in the column. For example, if any of the columns contains a true, value, set the header text to bold. I tried doing this in the PrepareViewStyleInfo event by referring to the row 0 of the current column in the event. The header did change briefly but then was reset by something - can you help me find what is resetting the header?
>
> for example:
> col0 col1 _col2_ col3
> _thing1_ F _T_ F
> thing2 F F F
> _thing3_ F _T_ F
>
> where the _ _ represent the format applied.
>
> thanks
In your PrepareViewStyleInfo, you should only set the style of the row.col being requested through the EventArgs. So, you might have code such as:
if(e.RowIndex == 0 && e.ColIndex > 0)
{
//somehow decide whether this column should be bold
bool b = false;
for (int i = 1; i <= this.grid.Model.RowCount; ++i)
{
if( (bool) this.grid[i, e.ColIndex] )
{
b = true;
break;
}
}
if(b)
{
e.Style.Font.Bold = true;
}
}
I did not check the syntax above, so you may have to modify things. But the idea is to only set e.Style and not set something like grid[0,3].
Now if the above calculation takes too long, then you might consider caching whether a column needs to be formated, and then retrieve the format decision in the PrepareViewStyleInfo from the cache. You would then recompute the cached values when the data changed.