Get group column in ViewCellFormatting event

5 posts, 2 answers
  1. Christoph
    Christoph avatar
    3 posts
    Member since:
    Jul 2016

    Posted 22 Jul Link to this post

    Hello,

    i use the ViewCellFormatting event to set an icon in the group header. It works, but how can i determining the group if i have more than one grouped column (something like the SummaryItem in the GroupSummaryEvaluationEventArgs).

    Here my event handler for th ViewCellFormattingEvent:

    private void OnGridViewCellFormatting(object sender, CellFormattingEventArgs e)
    {
      //Need the group here
      GridCellElement gce = e.CellElement;
      if (gce is GridGroupContentCellElement)
      {
        GridData gd = GetGridData(e); //Get the needed data
     
        gce.DrawFill = true;
        gce.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
        gce.BackColor = SystemColors.ControlLight;
        gce.Image = gd == null ? null : gd.Point.Marker ? _okImage : _nokImage;
      }
    }

    Thank you

    Christoph

  2. Answer
    Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 22 Jul Link to this post

    Hi Christoph,

    Thank you for writing.

    You can access the group through the GridViewRowInfo object. Please check my code snippet below: 
    private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
    {
        GridGroupContentCellElement cell = e.CellElement as GridGroupContentCellElement;
        if (cell != null)
        {
            int level = cell.RowInfo.Group.Level;
        }
    }

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms. For more information check out this blog post and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Christoph
    Christoph avatar
    3 posts
    Member since:
    Jul 2016

    Posted 22 Jul in reply to Hristo Merdjanov Link to this post

    HelloHristo,

    that will work for me because i used grouping by code. But only for my interest: what is the easiest way to get the grouped column to the level (if the user can grouping)?

    Thanks

    Christoph

  5. Answer
    Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 22 Jul Link to this post

    Hi Christoph,

    Thank you for writing back.

    The ViewCellFormatting will be raised as soon as a GridGroupContentCellElement becomes visible. By handling the GroupSummaryEvaluate you can also retrieve the group and its level: 
    private void radGridView1_GroupSummaryEvaluate(object sender, GroupSummaryEvaluationEventArgs e)
    {
        int level = e.Group.Level;
    }

    Additionally, you can check the following topics in our documentation: 
    I hope this information was useful. Please let me know if you need further assistance.

    Regards,
    Hristo Merdjanov
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms. For more information check out this blog post and share your thoughts.
  6. Christoph
    Christoph avatar
    3 posts
    Member since:
    Jul 2016

    Posted 22 Jul Link to this post

    Thanks for your support

    Christoph

Back to Top
UI for WinForms is Visual Studio 2017 Ready