Finding back which column was used to format GridGroupContentCellElement

4 posts, 0 answers
  1. Vincent
    Vincent avatar
    5 posts
    Member since:
    Jul 2012

    Posted 26 Feb 2013 Link to this post

    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?
  2. Stefan
    Admin
    Stefan avatar
    2911 posts

    Posted 01 Mar 2013 Link to this post

    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.
  3. Vincent
    Vincent avatar
    5 posts
    Member since:
    Jul 2012

    Posted 14 Mar 2013 Link to this post

    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;*/
                                }
                            }
                        }
                    }
                }
  4. Stefan
    Admin
    Stefan avatar
    2911 posts

    Posted 19 Mar 2013 Link to this post

    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.
Back to Top