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

Finding back which column was used to format GridGroupContentCellElement

3 Answers 78 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Vincent
Top achievements
Rank 1
Vincent asked on 26 Feb 2013, 02:20 PM
Dears,

Despite my investigations on the forums and in my debugger, I didn't find the right way to do what I need.

What I need to do is to change the text present in a GridGroupContentCellElement according to some information present in the column which was selected to create this grouping. Basically cells contain numerical codes as values, but the visual needs to display corresponding labels. This works great with the CellFormatting event but in the ViewCellFormatting, I catch the GridGroupContentCellElement element and then I really wonder how to get back the corresponding column header (at least its Name property).

Do you have any solution for this?

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 01 Mar 2013, 12:39 PM
Hello Vincent,

Thank you for writing.

To get the column name from the GridGroupContentCellElement, you should first access its RowInfo > the Group > the GroupDescriptor > the SortDescriptor and from there the column name (see attached image):
string s = e.CellElement.RowInfo.Group.GroupDescriptor.GroupNames[0].PropertyName;

I hope that you find this information useful.
 

Kind regards,
Stefan
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Join us for a FREE webinar to see all the new stuff in action.

Interested, but can’t attend? Register anyway and we’ll send you the recording.
0
Vincent
Top achievements
Rank 1
answered on 14 Mar 2013, 06:17 PM
It works but now I have another issue : if I click on the group header or expand / collapse the group, it displays the original value and not the label I put.
The most bizarre thing is that the label comes back when I click on another cell.

Screenshot 43 : initial state
Screenshot 44 : group header is selected, the label is replaced by the original value
Screenshot 45 : re-selecting an element gives me back my label

My code is located in the ViewCellFormatting event handler and is this:

if(e.CellElement is GridGroupContentCellElement)
            {
                GridGroupContentCellElement groupCell = e.CellElement as GridGroupContentCellElement;
                if (groupCell.RowInfo.Group.GroupDescriptor.GroupNames.Count > 0)
                {
                    string colName = groupCell.RowInfo.Group.GroupDescriptor.GroupNames[0].PropertyName;
                    if (!string.IsNullOrEmpty(colName) && this.coldescs.ContainsKey(colName))
                    {
                        BOColumn desc = this.coldescs[colName];
                        if (desc.Marker == BOColumnMarker.Property) //routes only if property
                        {
                            if (desc.PropertyDef.TypeDef.IsEnum /*&& groupCell.Tag == null*/) //routes only for enumerations
                            {
                                groupCell.Text = string.Format("{0}: {1}",
                                    _T(string.Format("m_property_{0}", desc.PropertyDef.Name)),
 
                                    string.IsNullOrEmpty(groupCell.RowInfo.Group.Header) ?
                                    _T("m_Null") :
                                    _T(string.Format("m_{0}_{1}", desc.PropertyDef.TypeDef.Name, groupCell.RowInfo.Group.Header))
                                    );
                               /* groupCell.Tag = desc;*/
                            }
                        }
                    }
                }
            }
0
Stefan
Telerik team
answered on 19 Mar 2013, 11:54 AM
Hi Vincent,

You are right about this case. 

May I please suggest using the GroupSummaryEvaluate event of RadGridView instead:
void radGridView1_GroupSummaryEvaluate(object sender, GroupSummaryEvaluationEventArgs e)
{
    if (e.SummaryItem.Name == "ComboColumn")
    {
        string colName = e.Group.GroupDescriptor.GroupNames[0].PropertyName;
        e.FormatString = colName;
    }
}

More information and examples are available here: http://www.telerik.com/help/winforms/gridview-grouping-formatting-group-header-row.html.

Let me know how this works for you.
 

Kind regards,
Stefan
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
Tags
GridView
Asked by
Vincent
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Vincent
Top achievements
Rank 1
Share this question
or