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

Get group column in ViewCellFormatting event

4 Answers 79 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Christoph
Top achievements
Rank 1
Christoph asked on 22 Jul 2016, 07:23 AM

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

4 Answers, 1 is accepted

Sort by
0
Accepted
Hristo
Telerik team
answered on 22 Jul 2016, 08:28 AM
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.
0
Christoph
Top achievements
Rank 1
answered on 22 Jul 2016, 09:40 AM

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

0
Accepted
Hristo
Telerik team
answered on 22 Jul 2016, 10:50 AM
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.
0
Christoph
Top achievements
Rank 1
answered on 22 Jul 2016, 11:17 AM

Thanks for your support

Christoph

Tags
GridView
Asked by
Christoph
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Christoph
Top achievements
Rank 1
Share this question
or