16 Answers, 1 is accepted
Yes, this is possible. Please look at the following KB article - it describes how to add a checkbox element inside GridHeaderCellElement. You should add RadComboBoxElement instead. If you want to use the combobox control (which is not preferred), you should host it inside RadHostItem.
Greetings,
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.
Private
Sub radgridView1_CreateCell(ByVal sender As Object, ByVal e As GridViewCreateCellEventArgs) Handles radgridView1.CreateCell
If TypeOf e.Row Is GridGroupHeaderRowElement AndAlso e.Column.Equals(Me.radgridView1.Columns(1)) Then
e.CellElement =
New GroupHeaderComboBox(e.Column, e.Row, bsFactors)
End If
End Sub
I think this is due to the column collection in the Group Header row being different than the table header. How can I work around this? Thanks!
Yes, you are correct. Group header row is a system row that has no representation in the underlying data source, and it affects cells differently. For example it contains only one cell of type GridCellElement. So, you should not access the column index, but the column type. Here is a sample:
Private Sub radGridView1_CreateCell(ByVal sender As Object, ByVal e As GridViewCreateCellEventArgs) |
If e.CellType Is GetType(GridCellElement) AndAlso TypeOf e.Row Is GridGroupHeaderRowElement Then |
e.CellType = GetType(CustomGroupHeaderCellElement) |
End If |
End Sub |
I prepared also a sample combobox cell element. Please take a look:
Public Class CustomGroupHeaderCellElement |
Inherits GridCellElement |
Private comboBox As RadComboBoxElement |
Public Sub New(ByVal column As GridViewColumn, ByVal row As GridRowElement) |
MyBase.New(column, row) |
End Sub |
Protected Overloads Overrides Sub CreateChildElements() |
MyBase.CreateChildElements() |
comboBox = New RadComboBoxElement() |
comboBox.MinSize = New Size(100, 20) |
comboBox.Items.Add(New RadComboBoxItem("Item 1")) |
comboBox.Items.Add(New RadComboBoxItem("Item 2")) |
comboBox.Items.Add(New RadComboBoxItem("Item 3")) |
Me.Children.Add(comboBox) |
ApplyThemeToElement(comboBox, "Vista") |
End Sub |
Protected Overloads Overrides Function ArrangeOverride(ByVal finalSize As SizeF) As SizeF |
Dim size As SizeF = MyBase.ArrangeOverride(finalSize) |
Dim rect As RectangleF = GetClientRectangle(finalSize) |
If Me.comboBox IsNot Nothing Then |
Me.comboBox.Arrange(New RectangleF(rect.Right - Me.comboBox.DesiredSize.Width - 5, rect.Top + (rect.Height - comboBox.DesiredSize.Height) / 2, Me.comboBox.DesiredSize.Width, comboBox.DesiredSize.Height)) |
End If |
Return size |
End Function |
Private Sub ApplyThemeToElement(ByVal item As RadItem, ByVal themeName As String) |
Dim builder As DefaultStyleBuilder = TryCast(ThemeResolutionService.GetStyleSheetBuilder(DirectCast(item.ElementTree.Control, RadControl), item.GetThemeEffectiveType().FullName, String.Empty, themeName), DefaultStyleBuilder) |
If builder IsNot Nothing Then |
item.Style = builder.Style |
End If |
End Sub |
End Class |
I hope this helps. If you need further assistance, I will be glad to help.
Greetings,
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.
Thank you for writing me back.
You can use the Group property of the GridViewGroupRowInfo that owns your cell. It contains a Rows collection with all rows that belong to the group. Please consider the sample below:
Private Sub comboBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) |
Dim groupRow As GridViewGroupRowInfo = DirectCast(Me.RowInfo, GridViewGroupRowInfo) |
For Each row As GridViewDataRowInfo In groupRow.Group.Rows |
'... |
Next |
End Sub |
Should you have any further questions, don't hesitate to contact us.
Greetings,
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.
You should check whether the group parent is the root group of MasterGridViewTemplate. Check the sample below:
if (groupRow.Group.Parent =
Me
.radGridView1.MasterGridViewTemplate.Root)
{
'...
}
Please contact me if you need further assistance with this.
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.
(in the CreateCell event)
Dim groupRow As GridViewGroupRowInfo = CType(e.Row.RowInfo, GridViewGroupRowInfo) |
If groupRow.Group.Level > 2 Then |
... |
End If |
Let me know if you see any problems with this. Thanks!
It was my mistake. I tested the case with our latest release - Q3 2009. The Parent property is available only in this version of RadControls. However, using the Level property is a good idea. If you have any other questions, please write me back.
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.
I need to add Checkbox to group header.
iwas able to do so, altering the code you provided to inherit from
GridGroupContentCellElement
classbut, the checkbox is appearing on the rifht most side and also i cannot attach to its check state toggle event.
Thank you in advance for your help
Thank you for contacting us.
Yes, using a custom GridGroupContentCellElement is the correct way for implementing this scenario. Please send me your project and I will optimize it. You can find additional information in this KB article.
Please note that you have to open a new support ticket in order to be able to attach your files.
I will be glad to help further and I am looking forward to your project.
Kind regards,
Jack
the Telerik team
The Link(KB article) you have mentioned is not working.Can you share some other project or link where checkbox is adding to group header.
Regards
The link to the article is now correct. You should be able to navigate to it without any issues.
Let us know if you have additional questions.
Nikolay
the Telerik team
Hi,
I have added checkBox in Grid GroupHeader but i am not able to assign the text to that chekbox.
I have did code as below whicch is working ,but i want to assign text at time of creation of "GridViewColumnGroup".
protected override void CreateChildElements()
{
base.CreateChildElements();
checkbox = new RadCheckBoxElement();
checkbox.Text = "testing.....";
checkbox.CheckAlignment = ContentAlignment.MiddleLeft;
checkbox.ToggleStateChanged += new StateChangedEventHandler(checkbox_ToggleStateChanged);
this.Children.Add(checkbox);
}​
Thank you for writing.
Here is a sample code snippet demonstrating how to create a custom group cell containing a RadCheckBoxElement with text:
private
void
radGridView1_CreateCell(
object
sender, Telerik.WinControls.UI.GridViewCreateCellEventArgs e)
{
if
(e.CellType ==
typeof
(GridGroupContentCellElement))
{
e.CellElement =
new
CustomGridGroupContentCellElement(e.Column, e.Row);
}
}
public
class
CustomGridGroupContentCellElement : GridGroupContentCellElement
{
public
CustomGridGroupContentCellElement(GridViewColumn column, GridRowElement row) :
base
(column, row)
{
}
protected
override
Type ThemeEffectiveType
{
get
{
return
typeof
(GridGroupContentCellElement);
}
}
RadCheckBoxElement checkbox;
LightVisualElement groupInfo;
DockLayoutPanel container;
protected
override
void
CreateChildElements()
{
base
.CreateChildElements();
container =
new
DockLayoutPanel();
groupInfo =
new
LightVisualElement();
checkbox =
new
RadCheckBoxElement();
checkbox.Text =
"check-box text....."
;
checkbox.CheckAlignment = ContentAlignment.MiddleLeft;
checkbox.ToggleStateChanged +=
new
StateChangedEventHandler(checkbox_ToggleStateChanged);
container.Children.Add(checkbox);
container.Children.Add(groupInfo);
container.LastChildFill =
true
;
groupInfo.TextAlignment = ContentAlignment.MiddleLeft;
this
.Children.Add(container);
}
public
override
void
SetContent()
{
base
.SetContent();
this
.Text =
string
.Empty;
groupInfo.Text =
this
.RowInfo.Group.Header;
}
private
void
checkbox_ToggleStateChanged(
object
sender, StateChangedEventArgs args)
{
}
}
I hope this information helps. Should you have further questions I would be glad to help.
Dess
Telerik