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
close icon

Row/Column Styles and cell styles

I've noticed that if a cell has a style and the row/column style changes the cells style always overrides. For example: Cell B3 is bold, if I change column B's style to Bold and then change it to not bold, B3 is still bold. What I'm wanting to do is for the column style change to reset the individual cells for the property being changed (like Excel does it). I've been using the CellStyles sample to look at this situation. Do you have any suggestions for what I can do? Thanks, Sue

7 Replies

AD Administrator Syncfusion Team April 21, 2003 08:32 PM UTC

Cell styles do take precedence over column styles. If you want to set the styles in a column so they override the individual cell styles, then one way you could do it is to call ChangeCells.
GridStyleInfo style = new GridStyleInfo();
style.Font.Bold = true;
this.gridControl1.ChangeCells(GridRangeInfo.Cells(1, 2, this.gridControl1.RowCount, 2), style, Syncfusion.Styles.StyleModifyType.Override);


SH Sue Harris April 22, 2003 10:18 PM UTC

That has certainly helped, I'm now facing the situation with virtual grids that if I make that call, the SaveCellInfo event passes me the style defined by the ChangeCells call and not the resultant cell style that I had originally expected. As a result I fetch the current cell style and call ModifyStyle with the provided style and modify flag. Is this expected behaviour? Do I need to call ModifyStyle in my SaveCellInfo event for any grid which I may change a style format in that way? (If so you may want to consider making a mention of it in the event documentation as a warning to the unwary.) Thanks, Sue > Cell styles do take precedence over column styles. If you want to set the styles in a column so they override the individual cell styles, then one way you could do it is to call ChangeCells. > >
> GridStyleInfo style = new GridStyleInfo();
> style.Font.Bold = true;
> this.gridControl1.ChangeCells(GridRangeInfo.Cells(1, 2, this.gridControl1.RowCount, 2), style, Syncfusion.Styles.StyleModifyType.Override);
> 
>


SH Sue Harris April 23, 2003 12:21 AM UTC

Another question while I'm on this topic, is there a way to get a list of what properties are set in a style object? I want to be able to change my save behaviour if only certain properties are being changed, but I can't see a way (without checking all the HasXValue properties) of determining that only a certain property has changed (is set). For example: I store the cell value separately from my formatting information (partially because it doesn't get correctly set from the ParseString method), so if the formatting is the only thing to change in the style, I don't want to have to run my storing cell value code, and if the cell value is the only thing to change, I don't want to run my storing formatting code. For the cell value I can check HasCellValue, but for formatting, I have to check all of the HasValue properties that I do store. Do you have any suggestions to help? Thanks, Sue


AD Administrator Syncfusion Team April 23, 2003 05:18 AM UTC

ChangeCells does change the cell style, so SaveCellInfo will get called with the modified styles. Since you are using a virtual grid, if you want the columnstyle to override the cellstyle, then you can do so in your QueryCellInfo. Take the ColStyle and use it to modify the e.Style. This, of course, would mean that there would never be any cell specific styles (unless later in QCI you apply a setting to e.Style or unless you only apply certain of the colstyle properties to e.Style). In this manner, SaveCellInfo would not get the changed styles. You can, if you like, modify a style in SaveCellInfo so the save style differs from the original passed in style.


SH Sue Harris April 23, 2003 07:06 PM UTC

Do I misunderstand? I'm calling ChangeCells with a range, a style I just created with just the bold property set, and the ModifyType as Override (basically exactly as you posted previously). In SaveCellInfo the style I get is the style with just the bold property set. If I previously had a cell value or back color or anything else that is NOT set in the style in SaveCellInfo, and I have to call ModifyStyle. Are you saying I should be getting the modified style in SaveCellInfo? Should I be getting a style with bold, cell value and back color (if it had a cell value and back color prior to the ChangeCell call)? Thanks, Sue


AD Administrator Syncfusion Team April 23, 2003 08:19 PM UTC

In a non-virtual GridControl, yes you should be getting the fully populated style in SaveCellInfo even if you call ChangeCells with only a bold change. But in a virtual grid control, this is not the case. All the information in the style normally has to come from QueryCellInfo. ChangeCells is not triggering a QueryCellInfo so there is no chance for the full style to be set since it must come from QueryCellInfo in a virtual grid. So, I don't think ChangeCells is a good choice for your original question. Can you not use your QueryCellInfo handler to dynamically reset the bold style?


SH Sue Harris April 23, 2003 08:58 PM UTC

Ah, that clarifies it a bit better. No I don't think I can use the QueryCellInfo because if a cell style occurs after the column/row style, I want that to override. (For example, if a cell is bold, and I make the column not bold, the column style overrides the cell styles. But if the column is not bold, and I then make the cell bold, the cell overrides the column style) same data, different order of occurance. However, now that I know the issue, I think I can work around the problem by calling QueryCellInfo on all the cells in the range I'm changing and updating them then calling refresh range, rather than calling ChangeCell. This just means I have different behaviour formatting non-virtual grids and virtual grids. Thanks, Sue

Loader.
Live Chat Icon For mobile
Up arrow icon