5 Answers, 1 is accepted
Thank you for writing us. As I understand you want to place a checkbox inside the group header row. This functionality is not build in RadGridView, so you have to use custom cell elements. The header row is not a data row and it has no representation in the underlying data source. However, you can use the Tag property to save the group state (on or off). Please consider the code snippet below:
void
radGridView1_CreateCell(
object
sender, GridViewCreateCellEventArgs e)
{
if
(e.Row
is
GridGroupHeaderRowElement && e.Column ==
null
)
{
e.CellType =
typeof
(MyGroupCell);
}
}
public
class
MyGroupCell: GridCellElement
{
RadCheckmark checkmark;
LightVisualElement label;
public
MyGroupCell(GridViewColumn column, GridRowElement row):
base
(column, row)
{
}
protected
override
Type ThemeEffectiveType
{
get
{
return
typeof
(GridCellElement); }
}
public
override
void
UpdateInfo()
{
base
.UpdateInfo();
if
(
this
.RowInfo.Tag !=
null
&& (
bool
)
this
.RowInfo.Tag ==
true
)
{
this
.checkmark.CheckState = Telerik.WinControls.Enumerations.ToggleState.On;
}
else
{
this
.checkmark.CheckState = Telerik.WinControls.Enumerations.ToggleState.Off;
}
}
protected
override
void
CreateChildElements()
{
base
.CreateChildElements();
checkmark =
new
RadCheckmark();
checkmark.Alignment = ContentAlignment.MiddleCenter;
checkmark.ShouldHandleMouseInput =
true
;
checkmark.MouseDown +=
new
MouseEventHandler(checkmark_MouseDown);
label =
new
LightVisualElement();
label.ShowHorizontalLine =
true
;
label.BindProperty(LightVisualElement.TextProperty,
this
, LightVisualElement.TextProperty, PropertyBindingOptions.OneWay);
StackLayoutPanel panel =
new
StackLayoutPanel();
panel.Orientation = Orientation.Horizontal;
panel.Children.Add(checkmark);
panel.Children.Add(label);
this
.Children.Add(panel);
}
protected
override
void
PaintText(Telerik.WinControls.Paint.IGraphics graphics)
{
}
private
void
checkmark_MouseDown(
object
sender, MouseEventArgs e)
{
if
(checkmark.CheckState == Telerik.WinControls.Enumerations.ToggleState.On)
{
checkmark.CheckState = Telerik.WinControls.Enumerations.ToggleState.Off;
this
.RowInfo.Tag =
false
;
CheckSubGroups(((GridViewGroupRowInfo)
this
.RowInfo).Group,
false
);
}
else
{
checkmark.CheckState = Telerik.WinControls.Enumerations.ToggleState.On;
this
.RowInfo.Tag =
true
;
CheckSubGroups(((GridViewGroupRowInfo)
this
.RowInfo).Group,
true
);
}
}
private
void
CheckSubGroups(DataGroup group,
bool
state)
{
foreach
(DataGroup subGroup
in
group.Groups)
{
subGroup.HeaderRow.Tag = state;
subGroup.HeaderRow.InvalidateRow();
CheckSubGroups(subGroup, state);
}
}
}
You should iterate the Groups collection of RadGridView to get the checked group rows:
List<GridViewGroupRowInfo> GetCheckedGroupRows(RadGridView grid)
{
List<GridViewGroupRowInfo> checkedRows =
new
List<GridViewGroupRowInfo>();
foreach
(DataGroup group
in
grid.Groups)
{
if
(group.HeaderRow.Tag !=
null
&& (
bool
)group.HeaderRow.Tag ==
true
)
{
checkedRows.Add(group.HeaderRow);
}
}
return
checkedRows;
}
If you have any further questions, I will be glad to answer them.
All the best,
Jack
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.

Hi,
I have a three level gridview in winform.
The parent(first level) and the third level gridviews have check box column. The second level gridview doesnot have checkbox column
1)How to change the togglestate of the checkboxes present in all the corresponding records of the third level gridview when the checkbox is checked in a particular row in the first level gridview
2) And Viceversa ...How to change the toggle state of the corresponding checkboxes in parent (first level ) gridview programmatically when the checkboxes are checked in the third level gridview
Thanks And Regards,
Bavya
Thank you for writing.
If I understand correctly you have set up the grid in a hierarchy. In order to accomplish your task, you would need to iterate the rows of the child template for a given hierarchy row. The following documentation article provides an example: http://docs.telerik.com/devtools/winforms/gridview/hierarchical-grid/how-to/iterating-the-child-rows-collection-of-a-chosen-parent-row-in-hierarchy-radgridview.
When you are in your third level you would need to iterate the rows in your master template. For the purpose you can handle the CellValueChanged event:
private
void
radGridView1_CellValueChanged(
object
sender, GridViewCellEventArgs e)
{
if
(e.Row.HierarchyLevel == 2)
{
foreach
(GridViewRowInfo row
in
this
.radGridView1.MasterTemplate.Rows)
{
//...
}
}
}
I hope this helps. Should you have further questions please do not hesitate to write back.
Regards,
Hristo Merdjanov
Telerik by Progress

Hi Hristo,
Thank you very much for the quick response.
When I check the check box in a parent row, the checkboxes in child records and corresponding grand child records are checked programmatically with the following code.
foreach (GridViewRowInfo r in e.Row.ChildRows)
{
r.Cells["column2"].Value = e.Value;
foreach (GridViewRowInfo i in r.ChildRows)
{
i.Cells["column3"].Value = e.Value;
}
}
Similarly how can I check or uncheck the check box of the parent row programmatically, when all the checkboxes of the corresponding child rows are checked or unchecked?
Thanks And Regards,
Bavya
Thank you for writing back.
The CellValueChanged event provides information about the hierarchy level of the cell. I can suggest accessing the grid templates depending on that level and perform the required custom logic.
I hope this information helps. Should you have further questions please do not hesitate to write back.
Regards,
Hristo Merdjanov
Telerik by Progress