I am trying to build a rad grid view dynamically and I have a slight issue with the column groups.
When the table is shown not all of the groups are shown but when I scroll they appear (only the first 10 get drawn when the grid is first loaded).
I have tried tow different approaches to make this work;
- Extending RadGridView and building the table based on a dependency property that contains the details of what columns/groups need to be added and,
- Moving the dependency property up a level and working with an out of the box RadGridView.
Do you have any suggestions of what I can do to get all of the column groups to be drawn when the grid view is first loaded?
Thanks,
Steven
4 Answers, 1 is accepted
From your description I cannot imagine the exact scenario you have. It would be helpful if you share some sample code showing how you have added the groups. Would you please attach as well an image showing how some of the column groups do not appear?
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
Sorry it took so long to reply.
private
void
AddColum(ColumnData column)
{
if
(column ==
null
)
{
return
;
}
// If the column group does not exist add it.
if
(!_columnGroupsAdded.Contains(column.GroupId))
{
ResultsGridView.ColumnGroups.Add(CreateColumnGroup(column.GroupId, column.GroupHeader));
_columnGroupsAdded.Add(column.GroupId);
}
// If the column group does exist but is not the last group added
// don't add the column as an exception is thrown.
if
(!_columnGroupsAdded.Last().Equals(column.GroupId))
{
return
;
}
ResultsGridView.Columns.Add(CreateColumn(column));
}
protected
internal
virtual
GridViewColumnGroup CreateColumnGroup(
string
id,
string
header)
{
return
new
GridViewColumnGroup
{
Header = header,
Name = id
};
}
protected
internal
virtual
GridViewDataColumn CreateColumn(ColumnData columnData)
{
if
(columnData ==
null
)
{
return
null
;
}
return
new
GridViewDataColumn
{
Header = columnData.ColumnHeader,
DataMemberBinding =
new
Binding {Path =
new
PropertyPath(
"["
+ columnData.ColumnId +
"]"
)},
ColumnGroupName = columnData.GroupId
};
}
I am using the same code to build multiple grids and the groups appear fine on the second grid, it is just the first one that there seems to be an issue. I have attached a screen shot of what the the grids look like when it is first drawn and what it looks like after it has been scrolled.
I am also experiencing another issue where if I try to add a column to a group that was not the last one added I am getting exception (InvalidOperationException - "Element is already a child of another element"). Although this is less than ideal there are a number of work arounds that I can do, e.g. ensure I create the columns in order with respect to their groups. (I was initially adding all of the groups before adding any columns) but if you could shed any light on why this happens that would be great.
Thanks,
Steven
Thank you for the better explanation of the problem. We have fixed some issues related to the merged headers recently. May I ask you to test with the latest binaries from the LIB?
As to the exception you get - such a problem would come from the fact you are setting visual as a header. Please note that during the lifecycle of the RadGridView, the common header cells are often recreated. Due to a framework limitation when a visual was once a child of a given container, it can no more be added to another one.
To resolve this, please place a TextBox in a DataTemplate and assign it to the HeaderTemplate of the column group. I hope this will help.
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
I set the HeaderTemplate on the ColumnGroup rather than the Header and this seems to fix the issues I was having.
Thanks,
Steven