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

Programmatically add GidViewColumnGroup

3 Answers 98 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Dan asked on 12 Dec 2012, 10:59 PM
I'm creating all columns dynamically in code.  I"m creating groups but the groups are not being rendered. This logic seems to make sense, am I missing something?

_dataGrid.Columns.Clear();
            _dataGrid.ColumnGroups.Clear();
            foreach (var period in currentPeriods)
            {
 
                var periodGroupName = "test" + col;
                var periodGroup = new GridViewColumnGroup {Header = period.Name, Name = periodGroupName};
 
                var runGroupName = "test2" + col;
                var runGroup = new GridViewColumnGroup { Header = "Run", Name = runGroupName };
 
                periodGroup.ChildGroups.Add(runGroup);
 
                _dataGrid.ColumnGroups.Add(periodGroup);
 
                var origColumn = new GridViewDataColumn
                    {
                        ColumnGroupName = periodGroupName,
                        Header = "Orig",
                        DataMemberBinding = new Binding("OriginalValue")
                    };
 
                _dataGrid.Columns.Add(origColumn);
 
                var repeatColumn = new GridViewDataColumn
                {
                    ColumnGroupName = periodGroupName,
                    Header = "Repeat",
                    DataMemberBinding = new Binding("RepeatValue")
                };
 
                _dataGrid.Columns.Add(repeatColumn)
 
                col += 2;
            }

3 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 13 Dec 2012, 04:32 PM
Hi Dan,

You can check this forum thread which you may find useful.

Regards,
Yoan
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Dan
Top achievements
Rank 1
answered on 13 Dec 2012, 04:40 PM
No, that isn't helpful.  I'm adding columns basically the same way as identified in that post.  The columns are appearing but no column groups are being displayed.
0
Yoan
Telerik team
answered on 17 Dec 2012, 08:32 AM
Hello Dan,

 I already answered your support ticket on the subject. For convenience I will paste my answer here as well:

Actually, using the Loaded event is not good idea in this scenario. I have modified you project and now it is working as expected. Please find it attached. Note that I have replaced the GridViewDataColumn'sColumnGroupName with the child ColumnGroup than with the parent ColumnGroup.


Regards,
Yoan
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Dan
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Dan
Top achievements
Rank 1
Share this question
or