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

How can I set ColumnGroup-Header programmatically?

4 Answers 193 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 14 May 2012, 03:07 PM
Hello!

I have a grid with columns and columngroups, which I declare in XAML. According to the time periods of the data, which should be displayed, I have to change to header of the columngroups.

I tried something like ...

GridViewColumnGroup colGrp = rgvAbsaetze.FindName("xcolGrpMon" + i) as GridViewColumnGroup;
colGrp.Header = aktueller_Monat;

... but the colGrp stays null.

How can I achieve this?

Kind regards

Michael

P.S.: I'm new to WPF!

4 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 14 May 2012, 03:32 PM
Hello,

 You can get the GridViewColumnGroup by searching in the ColumnGroups collection of the RadGridView. For example if the name of the group is "Data", then you can find the group using a similar code:

var groups = clubsGrid.ColumnGroups.Where(t => t.Name == "Data");

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Michael
Top achievements
Rank 1
answered on 14 May 2012, 04:03 PM
Hello!

I don't no why, but although I can see by debugging the code, that there is a columngroup with the name "colGrpMon1", the code doesn't find it.

I tried ...
//i starts with 0
var colGrp = rgvAbsaetze.ColumnGroups.Where(t => t.Name == ("colGrpMon" + (i+1)));
GridViewColumnGroup colGrp2 = (GridViewColumnGroup)colGrp;
colGrp2.Header = aktueller_Monat;

... and  ...
GridViewGroupColumn colGrp = rgvAbsaetze.ColumnGroups.Where(t => t.Name == ("colGrpMon" + (i+1))) as GridViewColumnGroup;
colGrp.Header = aktueller_Monat;

.... because I thought, that the error lies in the object casting.

What I'm doing wrong?

Bye

Michael
0
Dimitrina
Telerik team
answered on 15 May 2012, 12:33 PM
Hi,

Would you please try using the following code:

var groups = clubsGrid.ColumnGroups.Where(t => t.Name == "Data");
// place the name of your GroupColumn above
if (groups.ToList().Count > 0)
{
    GridViewColumnGroup group = groups.FirstOrDefault();
    MessageBox.Show("Selected group: " + group.Name);
}

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Michael
Top achievements
Rank 1
answered on 16 May 2012, 08:30 AM
Hi Didie!

This code works. Thank you.

Before you post your solution, I iterated the columnsgroups like this, what also worked for me. Perhaps, your solution is a little bit "faster". ;-)
foreach (GridViewColumnGroup item in rgvAbsaetze.ColumnGroups)
{
   if (item.Name == Spaltenname)
      item.Header = aktueller_Monat;
}
Tags
GridView
Asked by
Michael
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Michael
Top achievements
Rank 1
Share this question
or