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.
Unfortunately, activation email could not send to your email. Please try again.

Styles not being applied to cells...!

Thread ID:

Created:

Updated:

Platform:

Replies:

62226 Jun 11,2007 08:09 AM Jun 14,2007 02:30 PM Windows Forms 8
loading
Tags: GridControl
Vivek Vashisht
Asked On June 11, 2007 08:09 AM

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.



haneefm [Syncfusion]
Replied On June 11, 2007 04:23 PM

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

Vivek Vashisht
Replied On June 12, 2007 07:17 AM

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

haneefm [Syncfusion]
Replied On June 12, 2007 05:35 PM

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

Vivek Vashisht
Replied On June 13, 2007 04:18 AM

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

Ishwar Jindal
Replied On June 13, 2007 06:28 AM

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

haneefm [Syncfusion]
Replied On June 13, 2007 05:57 PM

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

Vivek Vashisht
Replied On June 14, 2007 04:17 AM

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?


haneefm [Syncfusion]
Replied On June 14, 2007 02:30 PM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;