This is a migrated thread and some comments may be shown as answers.

How can I change back color of group panel?

9 Answers 547 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Raymond
Top achievements
Rank 1
Raymond asked on 28 Dec 2010, 01:45 PM

Hi

How can I change back color of group panel?

(This panel wit text: „Drag a column here to group by this column.”)

 

Regards

9 Answers, 1 is accepted

Sort by
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 28 Dec 2010, 07:56 PM
Hello Raymond,

you can change the back colour of this area by setting the back colour of the GroupPanelElement as shown below
Me.RadGridView1.TableElement.GridViewElement.GroupPanelElement.BackColor = Color.Green
Me.RadGridView1.TableElement.GridViewElement.GroupPanelElement.GradientStyle = GradientStyles.Solid

Hope that helps
Richard
0
Raymond
Top achievements
Rank 1
answered on 29 Dec 2010, 09:20 PM
Thanks, works fine.

I have additional question.

When I drop some column on panel with groups, new subpanel with column name is created.

How can I change color of this subpanel?

Regards

0
Richard Slade
Top achievements
Rank 2
answered on 30 Dec 2010, 12:39 AM
Hi Raymond,

If you mean the column header that appears as the GroupFieldElement in the Group Header Panel then as far as I know this needs to be changed using the Visual Style Builder but I will look into if this is possible to change and let you know if I find a way.
Thanks
Richard
0
Raymond
Top achievements
Rank 1
answered on 30 Dec 2010, 08:36 AM

I mean that field that is in GroupPanelElement (or fields if we group by many columns).

 

Currently I can change color of GroupPanelElement but I cannot change color of his children controls (fields).

 

0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 30 Dec 2010, 09:43 AM
Hi,

Yes, this is the GroupFieldElement. I will look if there is a way to change it, but it may be only possible to change this via VSB. I'll let you know if/when I find out how to do this.
Thanks
Richard
0
Raymond
Top achievements
Rank 1
answered on 05 Jan 2011, 09:59 AM

Hi

I still cannot change color of GroupFieldElement.

I used this tool RadControlSpyForm to find this element. I change back color of this element but still color on the screen doesn`t change.

I can change back color of this element from RadControlSpyForm.

 

In handler of event ViewCellFormatting I do this:

 

 

GroupPanelContainer groupPanelContainer = e.CellElement.TableElement.GridViewElement.GroupPanelElement.Children[0].Children[1].Children[2].Children[3] as GroupPanelContainer;
if (groupPanelContainer.Children.Count > 0)
{
    TemplateGroupsElement templateGroupsElement = groupPanelContainer.Children[0] as TemplateGroupsElement;
    if (templateGroupsElement.Children.Count > 0)
    {
        GroupElement groupElement = templateGroupsElement.Children[0] as GroupElement;
        if (groupElement != null)
        {
            if (groupElement.Children.Count > 0)
            {
                StackLayoutPanel stackLayoutPanel = groupElement.Children[0] as StackLayoutPanel;
                if (stackLayoutPanel != null)
                {
                    if (stackLayoutPanel.Children.Count > 0)
                    {
                        GroupFieldElement groupFieldElement = stackLayoutPanel.Children[0] as GroupFieldElement;
                        if (groupFieldElement != null)
                        {
                            groupFieldElement.BackColor = Color.Red;
                            groupFieldElement.GradientStyle = GradientStyles.Solid;
                            groupFieldElement.ForeColor = Color.Blue;
                        }
                    }
                }
            }
        }
    }
}

Does anybody know what is wrong?

 

Regards

0
Richard Slade
Top achievements
Rank 2
answered on 05 Jan 2011, 10:20 AM
Hi,

Well, your code is kind of working. Group by a column and then expand one of the groups and the header changes colour. But it will not change if you group by a further column because it will no longer reach your code. I still think that the only way to change this correctly is to do it via the VSB.
Regards,
Richard
0
Martin Vasilev
Telerik team
answered on 07 Jan 2011, 04:06 PM
Hello guys,

Thank you writing.

Actually, there is a way to format all GroupFieldElements through code using the element hierarchy. Please consider the following method which changes all group fields:
private void FormatAllGroupElements()
{
    TemplateGroupsElement groupsElement = (TemplateGroupsElement)this.radGridView1.GridViewElement.GroupPanelElement.PanelContainer.Children[0];
    foreach (RadElement element in groupsElement.Children)
    {
        if (element is GroupElement)
        {
            GroupFieldElement fieldElement = (GroupFieldElement)element.Children[0].Children[0];
            fieldElement.NumberOfColors = 1;
            fieldElement.BackColor = Color.Red;
        }
    }
}

To apply the desired format, you can simply subscribe to the grid's GroupByChanged event:
void radGridView1_GroupByChanged(object sender, GridViewCollectionChangedEventArgs e)
{
    FormatAllGroupElements();
}

I hope this is helpful. Let me know if there are any additional questions.

Greetings,
Martin Vasilev
the Telerik team
Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
0
Richard Slade
Top achievements
Rank 2
answered on 07 Jan 2011, 04:10 PM
thanks for posting this Martin. I was very curious how it would be done properly. It seems more obvious now I've seen it.
All the best
Richard
Tags
GridView
Asked by
Raymond
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Raymond
Top achievements
Rank 1
Martin Vasilev
Telerik team
Share this question
or