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

object ref not set to an instance of a class for radgrid in windows form app

4 Answers 76 Views
General Discussion
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Vinod
Top achievements
Rank 1
Vinod asked on 13 Jan 2015, 11:05 AM
            Hi Team,           
            Am new to radgrid and am  trying as follows but am getting an error that object ref not set to an instance of a class .
and am trying the headers and banded header from other tables in the example u have given the header directly to the templates i need a basic example for the headers and banded headers from db.





public partial class Radgrid : Form
{
ColumnGroupsViewDefinition view= new ColumnGroupsViewDefinition();
TableViewDefinition tableView;
public Radgrid()
{
InitializeComponent();

InitializeGrid();

}
private void InitializeGrid()
{
this.tableView = (TableViewDefinition)this.radGridView1.ViewDefinition;
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;

}


}

}

4 Answers, 1 is accepted

Sort by
0
cmasdev
Top achievements
Rank 2
answered on 13 Jan 2015, 12:15 PM
Hi Vinod, in wich line do you have the exception?
Anyway, will be ok if you verify your tableViewDefinition:
01.public partial class Radgrid : Form
02.{
03.    ColumnGroupsViewDefinition view= new ColumnGroupsViewDefinition();
04.    TableViewDefinition tableView;
05.    public Radgrid()
06.    {
07.        InitializeComponent();
08.        InitializeGrid();
09.    }
10.    private void InitializeGrid()
11.    {
12.        this.tableView = (TableViewDefinition)this.radGridView1.ViewDefinition;
13.        if (this.tableView != null//Verify your value first
14.        {
15.            view = new ColumnGroupsViewDefinition();
16.            view.ColumnGroups.Add(new GridViewColumnGroup("Customer Contact"));
17.            view.ColumnGroups.Add(new GridViewColumnGroup("Details"));
18.            view.ColumnGroups[1].Groups.Add(new GridViewColumnGroup("Address"));
19.            view.ColumnGroups[1].Groups.Add(new GridViewColumnGroup("Contact"));
20. 
21.            view.ColumnGroups[0].Rows.Add(new GridViewColumnGroupRow());
22.            view.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns["CompanyName"]);
23.            view.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns["ContactName"]);
24.            view.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns["ContactTitle"]);
25. 
26.            view.ColumnGroups[1].Groups[0].Rows.Add(new GridViewColumnGroupRow());
27.            view.ColumnGroups[1].Groups[0].Rows[0].Columns.Add(this.radGridView1.Columns["Address"]);
28.            view.ColumnGroups[1].Groups[0].Rows[0].Columns.Add(this.radGridView1.Columns["City"]);
29.            view.ColumnGroups[1].Groups[0].Rows[0].Columns.Add(this.radGridView1.Columns["Country"]);
30. 
31.            view.ColumnGroups[1].Groups[1].Rows.Add(new GridViewColumnGroupRow());
32.            view.ColumnGroups[1].Groups[1].Rows[0].Columns.Add(this.radGridView1.Columns["Phone"]);
33.            view.ColumnGroups[1].Groups[1].Rows[0].Columns.Add(this.radGridView1.Columns["Fax"]);
34.            radGridView1.ViewDefinition = view;
35.        }
36.        else
37.        {
38.            MessageBox.Show("Your tableView is null");
39.        }
40.    }
41.}
Hope it helps.
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 16 Jan 2015, 08:41 AM
Hello,

Thank you for contacting us.

Note that it is important to specify columns that are present in the RadGridView.Columns collection when setting up the ColumnGroupsViewDefinition. Please find attached a sample project which result is illustrated on the provided picture.

If you are still experiencing any difficulties, it would be greatly appreciated if you provide a sample code snippet for populating the RadGridView with data and applying the ColumnGroupsViewDefinition. Once we reproduce the issue on our end, we would be able to investigate the precise case and assist you further.

I hope this information helps. Should you have further questions, I would be glad to help.
 
Regards,
Desislava
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Vinod
Top achievements
Rank 1
answered on 20 Jan 2015, 01:03 PM
Hi Desislava,
                     I want to bind multiple headers as parent and child's.
For example:
1.InterestCalculation would be parent and  Year-month will be the child header.
2.AMOUNT for deduction would be parent header and jan , feb ,march, april, may ,june ,july,august,sep,oct,nov,dec would be the multiple child's headers.
3. i want add these headers dynamically from the code.

In the same manner the parent and child headers would repeat multiple times in single Grid.

You could find my actual requirement in the attached file.  




 
              
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 23 Jan 2015, 10:05 AM
Hello Vinod,

Thank you for writing back.

In order to set up the ColumnGroupsViewDefinition as illustrated on the provided screenshot it is necessary all the child columns to be added to the RadGridView.Columns collection. Afterwards, you can specify each GridViewColumnGroup (parent column) with a custom name which columns is actually not present in the grid.

I hope this information helps. If you have any additional questions, please let me know.

Regards,
Desislava
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
General Discussion
Asked by
Vinod
Top achievements
Rank 1
Answers by
cmasdev
Top achievements
Rank 2
Dess | Tech Support Engineer, Principal
Telerik team
Vinod
Top achievements
Rank 1
Share this question
or