We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Column header conditional format in bound grid

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

5 Replies

CB Clay Burch Syncfusion Team September 4, 2002 04:47 PM UTC

> 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.


AK Andre King September 4, 2002 10:02 PM UTC

Thanks, I did as you suggested and the formatting works now. So I guess setting grid[r, c].Style is not allowed? Or are there other contexts where that can be used? There was a small typo, I think: this.grid[i, e.ColIndex] should be this.grid[i, e.ColIndex].CellValue ?


CB Clay Burch Syncfusion Team September 5, 2002 06:33 AM UTC

In most places you can use grid[r,c].CellValue = xxxx to set a cell value. The most common places you would not want to do this are in QueryCellInfo and when the cell r,c is actively being edited. In this latter case, the change you made to grid[r,c] will likely be zapped when the active cell ends editing, and you will not see the value you expect.


AK Andre King September 5, 2002 10:22 AM UTC

What about grid[r, c].Style ? What I saw when I tried to use this is the style would be set and then immediately over-written.


CB Clay Burch Syncfusion Team September 5, 2002 12:36 PM UTC

>>What about grid[r, c].Style ? grid[r,c] returns a GridStyleInfo object. And, GridStyleInfo does not have a Style property. So, I am not sure of how you are using grid[r, c].Style.

Loader.
Up arrow icon