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

GridView ViewDefinition problem

1 Answer 139 Views
GridView
This is a migrated thread and some comments may be shown as answers.
paul
Top achievements
Rank 1
paul asked on 07 Aug 2010, 07:33 PM
Hi

In my project I have the following senario:



ColumnGroupsViewDefinition

 

view =  new ColumnGroupsViewDefinition();

 

 

 

 

view.ColumnGroups.Add(new GridViewColumnGroup("Group"));

view.ColumnGroups.Add(new GridViewColumnGroup("ID"));

view.ColumnGroups.Add(new GridViewColumnGroup("Amount"));

view.ColumnGroups.Add(new GridViewColumnGroup("Date "));

view.ColumnGroups.Add(new GridViewColumnGroup("method"));

view.ColumnGroups.Add(new GridViewColumnGroup("request"));

view.ColumnGroups[3].Rows.Add(new GridViewColumnGroupRow());

view.ColumnGroups[4].Rows.Add(new GridViewColumnGroupRow());

view.ColumnGroups[5].Rows.Add(new GridViewColumnGroupRow());

 

view.ColumnGroups[3].Rows[0].Columns.Add(this.grid1.Columns["Now"]);

view.ColumnGroups[3].Rows[0].Columns.Add(this.grid1.Columns["yesterday"]);

view.ColumnGroups[4].Rows[0].Columns.Add(this.grid1.Columns["now"]);

view.ColumnGroups[4].Rows[0].Columns.Add(this.grid1.Columns["yesterday"]);

view.ColumnGroups[5].Rows[0].Columns.Add(this.grid1.Columns["now"]);

view.ColumnGroups[5].Rows[0].Columns.Add(this.grid1.Columns["yesterday"]);

 

DataTable

 

 

 

table = new DataTable();

 

 

 

 

 

 

table.Columns.Add(

 

 

"grp",typeof(string));

 

 

 

 

table.Columns.Add("ID",typeof(string));
table.Columns.Add("Amt",typeof(string));
table.Columns.Add("date",typeof(string));
table.Columns.Add("metd",typeof(string));
table.Columns.Add("req",typeof(string));

 

grid1.MasterGridViewTemplate.AutoGenerateColumns = false;

 

grid1.DataSource = table;

grid1.ViewDefinition = view;






My problem is that I get "Object reference not set to an instance of an object." error on last line that is:
"grid1.ViewDefinition = view;"

I have tryed many things to solve this but I couldn't.


Any help will be appreciated.

Thanks In advance.

1 Answer, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 11 Aug 2010, 04:10 PM
Hi Paul,

Thanks for writing.

The issue appears because you are trying to define the view, before you have generated the columns of your RadGridView instance. I recommend defining the view after you have created and added the columns to your grid. Then you will be able to use the columns you need in order to create the view definition.

Let me know if you additional questions.

All the best,
Svett
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
paul
Top achievements
Rank 1
Answers by
Svett
Telerik team
Share this question
or