column grouping - multirow header

7 posts, 0 answers
  1. c
    c avatar
    3 posts
    Member since:
    Apr 2011

    Posted 13 May 2011 Link to this post

    I'm trying to follow Telerik's c# documentation to create column groups with multiple headers:

    private

     

     

    void InitializeGrid()

     

     

    {

     

     

     

     

     

    ColumnGroupsViewDefinition view = new ColumnGroupsViewDefinition();

     

     

    view.ColumnGroups.Add(

     

    new GridViewColumnGroup("Customer Contact"));

     

     

    view.ColumnGroups.Add(

     

    new GridViewColumnGroup("Details"));

     

     

    view.ColumnGroups[1].Groups.Add(

     

    new GridViewColumnGroup("Address"));

     

     

    view.ColumnGroups[1].Groups.Add(

     

    new GridViewColumnGroup("Contact"));

     

     

    view.ColumnGroups[0].Rows.Add(

     

    new GridViewColumnGroupRow());

     

     

    view.ColumnGroups[0].Rows[0].Columns.Add(

     

    this.radGridView1.Columns["CompanyName"]);

     

     

    view.ColumnGroups[0].Rows[0].Columns.Add(

     

    this.radGridView1.Columns["ContactName"]);

     

     

    view.ColumnGroups[0].Rows[0].Columns.Add(

     

    this.radGridView1.Columns["ContactTitle"]);

     

     

    view.ColumnGroups[1].Groups[0].Rows.Add(

     

    new GridViewColumnGroupRow());

     

     

    view.ColumnGroups[1].Groups[0].Rows[0].Columns.Add(

     

    this.radGridView1.Columns["Address"]);

     

     

    view.ColumnGroups[1].Groups[0].Rows[0].Columns.Add(

     

    this.radGridView1.Columns["City"]);

     

     

    view.ColumnGroups[1].Groups[0].Rows[0].Columns.Add(

     

    this.radGridView1.Columns["Country"]);

     

     

    view.ColumnGroups[1].Groups[1].Rows.Add(

     

    new GridViewColumnGroupRow());

     

     

    view.ColumnGroups[1].Groups[1].Rows[0].Columns.Add(

     

    this.radGridView1.Columns["Phone"]);

     

     

    view.ColumnGroups[1].Groups[1].Rows[0].Columns.Add(

     

    this.radGridView1.Columns["Fax"]);

     

     

    radGridView1.ViewDefinition = view;

     

    }

    The last line produces the error object reference not set to an instance of an object. Do you know what I'm doing wrong?

    Thanks.

  2. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 16 May 2011 Link to this post

    Hello c,

    Do you know if the grid has finished binding by the time you are doing all those operations on the columns? Please try the same code in the DataBindingComplete event.

    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga

    Telerik WinForms MVP
  3. UI for WinForms is Visual Studio 2017 Ready
  4. c
    c avatar
    3 posts
    Member since:
    Apr 2011

    Posted 17 May 2011 Link to this post

    Thanks for the response Emanuel.  I did as you suggested but still get the same error - object reference not set to an instance of an object. 
  5. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 18 May 2011 Link to this post

    Hello C,

    The described issue could be observed when the radGridView1 property is not yet associated with an instance of RadGridView object. Please could you confirm that this is the case. If not please send us your application and we will research the case in detail.

    I hope this helps. 
     
    All the best,
    Jack
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
  6. c
    c avatar
    3 posts
    Member since:
    Apr 2011

    Posted 18 May 2011 Link to this post

    Thanks very much.  I've figured it out now.
  7. Mohamed
    Mohamed avatar
    1 posts
    Member since:
    Apr 2013

    Posted 30 Jan 2014 in reply to c Link to this post

    excuse me how you solve it ,have been exposed to the same problem, 
  8. George
    Admin
    George avatar
    500 posts

    Posted 04 Feb 2014 Link to this post

    Hi Mohamed,

    Thank you for replying.

    I am not sure how the previous user resolved his problem, however my guess is that he either:
    1. Called this code before the InitializeComponent method in your Form's constructor which results in the RadGridView instance being null.
    2. You are accessing a column which you have not yet created, check your code structure.

    You can also read our help article: Column Groups View | UI for WinForms Documentation which may be of help.

    If this does not help, please provide me with some sample code which I can test locally. Also let me know of the version of our controls you are using.

    Looking forward to your response.

    Regards,
    George
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top
UI for WinForms is Visual Studio 2017 Ready