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

5 posts, 0 answers
  1. Vinod
    Vinod avatar
    4 posts
    Member since:
    Jan 2015

    Posted 13 Jan 2015 Link to this post

                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()


    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[1].Groups[0].Rows.Add(new GridViewColumnGroupRow());

    view.ColumnGroups[1].Groups[1].Rows.Add(new GridViewColumnGroupRow());
    radGridView1.ViewDefinition = view;



  2. christianamado
    christianamado avatar
    8 posts
    Member since:
    May 2014

    Posted 13 Jan 2015 in reply to Vinod Link to this post

    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
    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"));
    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"]);
    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"]);
    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.    }
    Hope it helps.
  3. Dess
    Dess avatar
    1561 posts

    Posted 16 Jan 2015 Link to this post


    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.

    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.

  4. Vinod
    Vinod avatar
    4 posts
    Member since:
    Jan 2015

    Posted 20 Jan 2015 in reply to Dess Link to this post

    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.  

  5. Dess
    Dess avatar
    1561 posts

    Posted 23 Jan 2015 Link to this post

    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.


    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.

Back to Top