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

column grouping - multirow header

6 Answers 263 Views
GridView
This is a migrated thread and some comments may be shown as answers.
c
Top achievements
Rank 1
c asked on 13 May 2011, 05:29 PM
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.

6 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 16 May 2011, 08:29 AM
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
0
c
Top achievements
Rank 1
answered on 17 May 2011, 09:08 PM
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. 
0
Jack
Telerik team
answered on 18 May 2011, 04:48 PM
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.
0
c
Top achievements
Rank 1
answered on 18 May 2011, 09:43 PM
Thanks very much.  I've figured it out now.
0
Mohamed
Top achievements
Rank 1
answered on 30 Jan 2014, 03:38 PM
excuse me how you solve it ,have been exposed to the same problem, 
0
George
Telerik team
answered on 04 Feb 2014, 09:25 AM
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 >>
Tags
GridView
Asked by
c
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
c
Top achievements
Rank 1
Jack
Telerik team
Mohamed
Top achievements
Rank 1
George
Telerik team
Share this question
or