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

Getting the actual Style for a cell

I would like to get a GridStyleInfo object for a cell which has the actual final style. I've tried this.gridControl.GetViewStyleInfo(rowIndex, colIndex); this.gridControl[rowIndex,colIndex]; and this.gridControl.GetCombinedStyle(GridRangeInfo.Cell( rowIndex, colIndex) ); All of them seem to only return the style for the cell. If I have a row/column or table style, the settings of these seem to be ignored. For example, if my row style backcolor is blue, my cell style still returns with a backcolor of white (HasBackColor is false) but it is painted in the grid as blue. The only way I can think of is to get the styles for the table, column and row and merging them. Is there a better way? Thanks, Sue

6 Replies

AD Administrator Syncfusion Team May 18, 2003 10:00 PM UTC

How are you setting the other styles? If I set this.gridControl1.ColStyles[1].BackColor = Color.Aqua; this.gridControl1.BaseStylesMap["Standard"].StyleInfo.Font.Bold = true; in FormLoad, then in a button handler, this code prints the expected values. Console.WriteLine(this.gridControl1[1,1].BackColor.ToString()); Console.WriteLine(this.gridControl1.BaseStylesMap["Standard"].StyleInfo.Font.Bold.ToString());


SH Sue Harris May 19, 2003 03:28 AM UTC

Sorry, I should have said this is a virtual grid. So I set the styles in the QueryCellInfo event (QueryCellInfo row = -1, col = 3) e.Style.TextColor = Blue and add a button event: Color textIsThisColor; GridStyleInfo style = this.gridControl1[2,3]; if ( style.HasTextColor ) { textIsThisColor = style.TextColor; } GridStyleInfo style1 = this.gridControl1.GetCombinedStyle(GridRangeInfo.Cell(2,3)); if ( style1.HasTextColor ) { textIsThisColor = style1.TextColor; } GridStyleInfo style2 = this.gridControl1.GetViewStyleInfo(2,3); if ( style2.HasTextColor ) { textIsThisColor = style2.TextColor; } None of the styles have the expected text color. Thanks, Sue


AD Administrator Syncfusion Team May 19, 2003 05:49 AM UTC

Comment out the check for if ( style.HasTextColor ) and I think all the ways you tried will show the Blue as the text color. The problem is that the cell style did not have TextColor explicitly set (it is inheriting it), so its style.HasTextColor was never explicitly set, and hence your code is skipping the textIsThisColor assignment. One comment is that a cell style will always appear to be fully populated since if there is not a style property explicitly set for it, it will inherit a setting from one of the parent styles (col, row, table, standard).


SH Sue Harris May 19, 2003 07:30 PM UTC

Thanks, thats seems to be the base of the problem. Does the copy constructor for GridStyleInfo ignore properties which aren't explicitly set? The actual problem is that I've got a custom TypeConverter which I'm using for displaying a limited number of the grid cells style properties (I used a sample you previously sent me). I have a class derived from GridStyleInfo: [TypeConverter(typeof(LimitedTypeConverter))] public class FormattableGridStyleInfo : Syncfusion.Windows.Forms.Grid.GridStyleInfo { public FormattableGridStyleInfo(Syncfusion.Windows.Forms.Grid.GridStyleInfo style) : base(style) { } } This class seems to lose all those non-explicitly set properties (I thought that it was never getting them, hence my original question). Is there a way to copy those non-explicitly set properties? Thanks, Sue


AD Administrator Syncfusion Team May 19, 2003 10:45 PM UTC

Hi Sue, change this line from > public FormattableGridStyleInfo(Syncfusion.Windows.Forms.Grid.GridStyleInfo style) : base(style) to > public FormattableGridStyleInfo(Syncfusion.Windows.Forms.Grid.GridStyleInfo style) : base(style.Identity, (GridStyleInfoStore) style.Store) > { > } I think that should work. The copy constructor otherwise does not initialize the "Identity" of the underlying style. Identity is needed to give the style object knowledge about the BaseStylesMap and the underlying grid. As soon as the style has its identity all properties will be able look up default values from their base style. Stefan


SH Sue Harris May 20, 2003 01:18 AM UTC

That did the trick. Thanks, Sue

Loader.
Up arrow icon