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

Styles not being applied to cells...!

I am using GGC.
I am trying to change the style of a cell through the following code...

gridGroupingControl.TableControl.Model.ChangeCells(range, style, StyleModifyType.Changes);

where range is the selected range of cells and style is a static GridStyleInfo object.

But the style is not getting applied onto the selected cells.



8 Replies

HA haneefm Syncfusion Team June 11, 2007 08:23 PM UTC

Hi Vivek,

You can do this by hanlding the TableControlPrepareViewStyleInfo event and set the selected cell 's celltype using e.Inner.Style property. Here is a code snippet that show this.

bool isSelected = e.TableControl.Model.SelectedRanges.AnyRangeIntersects(GridRangeInfo.Cell(e.Inner.RowIndex,e.Inner.ColIndex));
if (isSelected)
{
e.Inner.Style.CellType = "Static";
}

Best regards,
Haneef


VV Vivek Vashisht June 12, 2007 11:17 AM UTC

Hello,
I have not been able to get the desired results with the solution you provided. I would explain the problem in a bit detail to you.

I have a GGC. I select a few cells (randomly) and right click to get a context menu "Format". On clicking 'Format', the style object is retrieved by
style = ggc.TableControl.Model.GetCombinedStyle(rangeList);

and a modal window appears which has a property grid with gridFormattingWindow.SelectedObject = this.style;

now when i change any property value like back color, and click Ok on the modal window, the changed style should apply to the selected cell(s). For applying the style I am using the code
foreach (GridRangeInfo range in rangeList)
{
ggc.TableControl.Model.ChangeCells(range, style, StyleModifyType.Changes);
}

And it is not working. The style change is not being implemented in the grid.

Can you please provide a solution to it??

Thanks
Vivek


>Hi Vivek,

You can do this by hanlding the TableControlPrepareViewStyleInfo event and set the selected cell 's celltype using e.Inner.Style property. Here is a code snippet that show this.

bool isSelected = e.TableControl.Model.SelectedRanges.AnyRangeIntersects(GridRangeInfo.Cell(e.Inner.RowIndex,e.Inner.ColIndex));
if (isSelected)
{
e.Inner.Style.CellType = "Static";
}

Best regards,
Haneef


HA haneefm Syncfusion Team June 12, 2007 09:35 PM UTC

Hi Vivek,

You can not set any cell specific properties for the GroupingGrid other than the CellValue using ChangeCells method. You need to handle the TableControlPrepareViewStyleInfo (or QueryCellStyleInfo) event to do this. Through this event you can set the style properties for the grid. Here is a code snippet that set the IsChangeCells flag in Format's menu click event and check that flag in QueryCellStyleInfo event for setting the selected cell style ina grid. Please try the suggestion and let me know if this helps.

//global variable..
bool IsChangeCalls = false;
GridStyleInfo style;

//format menu click event.
style = ggc.TableControl.Model.GetCombinedStyle(rangeList);
foreach (GridRangeInfo range in rangeList)
{
IsChangeCalls = true;
ggc.TableControl.RefreshRange(range); //Refresh method does call the QueryCellStyleInfo event.
IsChangeCalls = false;
}

//QueryCellStyleInfo event.
e.Style.CellType = style.CellType;
e.Style.BackColor = style.BackColor;

Best regards,
Haneef


VV Vivek Vashisht June 13, 2007 08:18 AM UTC

Hi,

I am afraid but the solution hasn't worked as expected.

1. I do not want to assign individual style properties using style.backcolor = value. I want the whole of the style object to be implemented as the user is going to format the cells and can change n no. of properties.

2. Even individual style properties get implemented but only till the time the focus remains on the cell. the moment I select another cell, the style is lost.

3. How can I make the style persist? for e.g. i select two cells, make their font size = 10 through the formatting window. then i select another two cells and make their font color = red. the changes made to the previous two cells should persist.

4. i am attaching a sample which i tried on grid control earlier on. Can you please send a small sample application depicting the same functionality in grid grouping control...
just right click onto the grid and try formatting..
That would be of great help...

thanks
vivek


>Hi Vivek,

You can not set any cell specific properties for the GroupingGrid other than the CellValue using ChangeCells method. You need to handle the TableControlPrepareViewStyleInfo (or QueryCellStyleInfo) event to do this. Through this event you can set the style properties for the grid. Here is a code snippet that set the IsChangeCells flag in Format's menu click event and check that flag in QueryCellStyleInfo event for setting the selected cell style ina grid. Please try the suggestion and let me know if this helps.

//global variable..
bool IsChangeCalls = false;
GridStyleInfo style;

//format menu click event.
style = ggc.TableControl.Model.GetCombinedStyle(rangeList);
foreach (GridRangeInfo range in rangeList)
{
IsChangeCalls = true;
ggc.TableControl.RefreshRange(range); //Refresh method does call the QueryCellStyleInfo event.
IsChangeCalls = false;
}

//QueryCellStyleInfo event.
e.Style.CellType = style.CellType;
e.Style.BackColor = style.BackColor;

Best regards,
Haneef

GridControl_FormattingCells.zip


IJ Ishwar Jindal June 13, 2007 10:28 AM UTC

Hi,

Please ignore my previous questions and consider the following message.


I observed that TableControlPrepareViewStyleInfo and QueryCellStyleInfo event get fired every time there is any user interaction with the grid grouping control i.e. even on mouse move, mouse click.

This makes me believe that these two events are sort of routine that is invoked to read the values from cells. If we modify any specific cell's format settings in these two events then we need to persist that setting so that whenever the event fired again we can set the same format settings again.

I have also observed that if we leave any cell's style unchange in these two events then the cell retains default style of grid, which makes me believe that we need to persist changed value for each cell.

So if we go by the solution you suggested then it will become the order of nummber of cells, that is, if we have n cells then we may need to persist n setting value to apply back whenever these two event get fired.


One particular issue that I noticed after implementing your solution is that, in the first iteration the style changes get applied to cell # 1 but when I change the focus to another cell say cell #2, the value set in first iteration (i.e. to cell#1) disappear because that changed style was not available when the QueryCellStyleInfo fired again as part of user interaction with grid grouping control.

I suspect there is some misunderstanding about our requirements, so below I am reiterating what we need

1. We want the user to select some cells (probably random cells).

2. There is a menu item (say Change BackColor to Red) in our application's main menu bar which is supposed to change the back color of selected cells to Red.

I am expecting a solution where we can get hold of a particular cell in GGC using colIndex(range.right/left) and rowIndex(range.top/bottom) available for each selected cells in selected range (see point#1) and set it's style. i.e.

ggcControl.TableControl[rowIndex, colIndex].Style.BackColor = Color.Red;

and as matter of fact, If I have a style object containing all the style changes then

ggcControl.TableControl[rowIndex, colIndex].Style = changedStyle;

Please don't think that I am expecting indexer on TableControl. I have just used indexer to illustrate my point.

I would appreciate if you could send me some code samples to achieve the point # 1 and 2.

Ishwar


HA haneefm Syncfusion Team June 13, 2007 09:57 PM UTC

Hi Ishwar,

Here is a minimal sample that shows you "How to set the selected cell styles in a grid?".
GGCSelectedColorQueryCellInfo.zip

Best regards,
Haneef


VV Vivek Vashisht June 14, 2007 08:17 AM UTC

Further to the provided sample solution, how can we serilize the complete information about the ggc including the changed formatting, data etc so that the same ggc can be retrieved preserving its look n feel,cell styles, grouping information and data etc?



HA haneefm Syncfusion Team June 14, 2007 06:30 PM UTC

Hi Vivek,

Please refer the following forum thread for more details.
1. http://www.syncfusion.com/support/forums/message.aspx?MessageID=41724
2. http://www.syncfusion.com/support/forums/message.aspx?&MessageID=46772

Best regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon