Programmatically add GidViewColumnGroup

4 posts, 0 answers
  1. Dan
    Dan avatar
    22 posts
    Member since:
    Jun 2011

    Posted 12 Dec 2012 Link to this post

    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;
                }
  2. Yoan
    Admin
    Yoan avatar
    1190 posts

    Posted 13 Dec 2012 Link to this post

    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.

  3. Dan
    Dan avatar
    22 posts
    Member since:
    Jun 2011

    Posted 13 Dec 2012 Link to this post

    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.
  4. Yoan
    Admin
    Yoan avatar
    1190 posts

    Posted 17 Dec 2012 Link to this post

    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.

Back to Top