8 Answers, 1 is accepted
If you are refering to the main headers please take a look at this help article.
Hope this helps, if you have any other questions or comments, please let me know,
Best Regards,
Emanuel Varga
Telerik WinForms MVP
Thanks for the tip.
But I still have a problem.
I bound the DataSource of the grid to a DataTable.
Data is displayed.
Once the datasource is set.
I use the following code:
ColumnGroupsViewDefinition view = new ColumnGroupsViewDefinition();
view.ColumnGroups.Add(new GridViewColumnGroup("Date"));
view.ColumnGroups[0].Groups.Add(new GridViewColumnGroup("01"));
view.ColumnGroups[0].Groups.Add(new GridViewColumnGroup("02"));
RadGV.ViewDefinition = view;
Then the grid shows nothing more.
Why?
Can it be that there is a view definition, already?
(set by the Data Source)
Yes, you are correct, if you are using a custom view definition you should define all the columns you want to display there.
Hope this helps, if you have any other questions or comments, please let me know,
Best Regards,
Emanuel Varga
Telerik WinForms MVP
Can you give me an example?
This is my code:
private
void
button1_Click(
object
sender, EventArgs e)
{
DataTable dataSource =
new
DataTable(
"Test"
);
dataSource.Columns.Add(
"ID"
,
typeof
(
int
));
dataSource.Columns.Add(
"ParentID"
,
typeof
(
int
));
dataSource.Columns.Add(
"Art"
,
typeof
(
string
));
dataSource.Columns.Add(
"WC"
,
typeof
(
string
));
dataSource.Columns.Add(
"SP2"
,
typeof
(
string
));
dataSource.Columns.Add(
"SP3"
,
typeof
(
string
));
dataSource.Columns.Add(
"01"
,
typeof
(
string
));
dataSource.Columns.Add(
"02"
,
typeof
(
string
));
int
LfdNr = 1;
int
ParentNr;
/// ID / ParentID / Art / WC / area / Status Color / Status desc;
dataSource.Rows.Add(LfdNr,
null
,
"WC"
,
"T01"
, -16711936,
"Normal"
);
ParentNr = LfdNr;
LfdNr += 1;
dataSource.Rows.Add(LfdNr, ParentNr ,
"A"
,
"Test"
, -16711936,
"Normal"
);
LfdNr += 1;
dataSource.Rows.Add(LfdNr,
null
,
"WC"
,
"T02"
, -16711936,
"Normal"
);
LfdNr += 1;
dataSource.Rows.Add(LfdNr,
null
,
"WC"
,
"T03"
, -16711936,
"Normal"
);
LfdNr += 1;
radGridView1.DataSource = dataSource;
this
.radGridView1.Relations.AddSelfReference(
this
.radGridView1.MasterTemplate,
"ID"
,
"ParentID"
);
this
.radGridView1.Columns[
"ID"
].IsVisible =
false
;
this
.radGridView1.Columns[
"ParentID"
].IsVisible =
false
;
this
.radGridView1.Columns[
"Art"
].IsVisible =
false
;
//ColumnGroupsViewDefinition view = new ColumnGroupsViewDefinition();
//view.ColumnGroups.Add(new GridViewColumnGroup("Date"));
//view.ColumnGroups[0].Groups.Add(new GridViewColumnGroup("01"));
//view.ColumnGroups[0].Groups.Add(new GridViewColumnGroup("02"));
//radGridView1.ViewDefinition = view;
}
To show the main Date Header and with 01 and 02 under it change your code like so:
ColumnGroupsViewDefinition view =
new
ColumnGroupsViewDefinition();
var dateGroup =
new
GridViewColumnGroup(
"Date"
);
view.ColumnGroups.Add(dateGroup);
dateGroup.Rows.Add(
new
GridViewColumnGroupRow());
dateGroup.Rows[0].Columns.Add(radGridView1.Columns[
"01"
]);
dateGroup.Rows[0].Columns.Add(radGridView1.Columns[
"02"
]);
radGridView1.ViewDefinition = view;
Hope this helps, if you have any other questions or comments, please let me know,
Best Regards,
Emanuel Varga
Telerik WinForms MVP
Thank you for writing.
Emanuel's solution should cover your case. Remember to mark it as an answer, so other can find the solution to their question quicker. If this is not what you want or you have other questions, feel free to write again and we will try to help the best way we can.
Ivan Petrov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Now I have a problem.
By this code:
DataTable dataSource =
new
DataTable(
"Test"
);
dataSource.Columns.Add(
"ID"
,
typeof
(
int
));
dataSource.Columns.Add(
"ParentID"
,
typeof
(
int
));
dataSource.Columns.Add(
"Art"
,
typeof
(
string
));
dataSource.Columns.Add(
"WC"
,
typeof
(
string
));
dataSource.Columns.Add(
"SP2"
,
typeof
(
string
));
dataSource.Columns.Add(
"SP3"
,
typeof
(
string
));
dataSource.Columns.Add(
"01"
,
typeof
(
string
));
dataSource.Columns.Add(
"02"
,
typeof
(
string
));
int
LfdNr = 1;
int
ParentNr;
/// ID / ParentID / Art / WC / area / Status Color / Status desc;
dataSource.Rows.Add(LfdNr,
null
,
"WC"
,
"T01"
, -16711936,
"Normal"
);
ParentNr = LfdNr;
LfdNr += 1;
dataSource.Rows.Add(LfdNr, ParentNr ,
"A"
,
"Test"
, -16711936,
"Normal"
);
LfdNr += 1;
dataSource.Rows.Add(LfdNr,
null
,
"WC"
,
"T02"
, -16711936,
"Normal"
);
LfdNr += 1;
dataSource.Rows.Add(LfdNr,
null
,
"WC"
,
"T03"
, -16711936,
"Normal"
);
LfdNr += 1;
radGridView1.DataSource = dataSource;
ColumnGroupsViewDefinition view =
new
ColumnGroupsViewDefinition();
var wcGroup =
new
GridViewColumnGroup(
"WC"
);
var dateGroup =
new
GridViewColumnGroup(
"Date"
);
view.ColumnGroups.Add(wcGroup);
view.ColumnGroups.Add(dateGroup);
dateGroup.Rows.Add(
new
GridViewColumnGroupRow());
dateGroup.Rows[0].Columns.Add(radGridView1.Columns[
"01"
]);
dateGroup.Rows[0].Columns.Add(radGridView1.Columns[
"02"
]);
wcGroup.Rows.Add(
new
GridViewColumnGroupRow());
wcGroup.Rows[0].Columns.Add(radGridView1.Columns[
"ID"
]);
wcGroup.Rows[0].Columns.Add(radGridView1.Columns[
"ParentID"
]);
wcGroup.Rows[0].Columns.Add(radGridView1.Columns[
"WC"
]);
wcGroup.Rows[0].Columns.Add(radGridView1.Columns[
"Art"
]);
wcGroup.Rows[0].Columns.Add(radGridView1.Columns[
"SP2"
]);
wcGroup.Rows[0].Columns.Add(radGridView1.Columns[
"SP3"
]);
radGridView1.ViewDefinition = view;
this
.radGridView1.Relations.AddSelfReference(
this
.radGridView1.MasterTemplate,
"ID"
,
"ParentID"
);
When grouping, he shows no sign of plus more.
Grouping I do with this code:
this
.radGridView1.Relations.AddSelfReference(
this
.radGridView1.MasterTemplate,
"ID"
,
"ParentID"
);
Thank you for writing back.
Creating a self-reference hierarchy in grid is not the same as grouping. For a self-reference grid you need a data source with hierarchical data in it. For your case where the data source is a flat table you should use a group descriptor. To make the descriptor work, you just have to add it to the RadGridView GroupDescriptors collection. Just substitute the following line of your code:
this
.radGridView1.Relations.AddSelfReference(
this
.radGridView1.MasterTemplate,
"ID"
,
"ParentID"
);
this
.radGridView1.GroupDescriptors.Add(
new
GroupDescriptor(
"ParentID"
));
I hope this will help you. if you have further questions, I would be glad to help. Greetings,
Ivan Petrov
the Telerik team
Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.