Adding Blank Row to Gridview at 5 row position or any where in middle.

4 posts, 0 answers
  1. Nicky
    Nicky avatar
    20 posts
    Member since:
    Aug 2007

    Posted 10 Oct 2007 Link to this post

    Hi ,

    I am trying to add blank row through programming to radgridview .
    Coudnt able to find property .

    Is there any way to add blank row to radGridview at  5 row position or any where in middle.


    Thanks
    Sushil

  2. Jack
    Admin
    Jack avatar
    2208 posts
    Member since:
    Sep 2012

    Posted 11 Oct 2007 Link to this post

    Hi Nicky,

    You can add a new row at the end of the Rows collection through the GridViewRowCollection.Add method. Here is the needed code:

    this.radGridView1.Rows.Add ( "John Smith", 25, 4.98, "555-345-345" );
    this.radGridView1.Rows.Add ( new object[] { "John Smith", 25, 4.98, "555-345-345" } );

    If you wish to insert a row at a specific position use the API of your binding source. For example if the grid is bound to a DataTable use the following code:

    DataRow row = table.NewRow();
    table.Rows.InsertAt(row, 5);

    If you have any further questions or troubles please feel free to write us.
     

    Kind regards,
    Jack
    the Telerik team


    Instantly find answers to your questions at the new Telerik Support Center

  3. Tamás
    Tamás avatar
    6 posts
    Member since:
    Jul 2008

    Posted 04 Jul 2008 Link to this post

    Hi Jack,

    I'm affraid, the solution you recommended doesn't work for me.

    Here is my code:

    DataTable

    dataTable1 = new DataTable();
    dataTable1.Columns.Add(
    "Id");
    dataTable1.Columns.Add(
    "Name");

    radGridView1.DataSource = dataTable1;

    DataRow
    dataRow1 = dataTable1.NewRow();
    dataRow1[
    "Id"] = 1;
    dataRow1[
    "Name"] = "Bob";

    DataRow dataRow2 = dataTable1.NewRow();
    dataRow2[
    "Id"] = 2;
    dataRow2[
    "Name"] = "Alice";

    dataTable1.Rows.InsertAt(dataRow1, 0);
    dataTable1.Rows.InsertAt(dataRow2, 0);


    At this point, radGridView1 freezes, and if I try to click on it, the whole form crashes with an exception at this point:

    Application
    .Run(new Form2());

    There seems to be an inconsitency between radGridView1 and its data source, dataTable1: dataTable1 contains two rows correctly, however, radGridView1 shows only the last inserted row ( {2, "Alice"} ), and crashes when attempting any further interaction on the GUI.

    I'd be glad to find out if there is a solution.

    Thanks,
    Tamás

  4. Jack
    Admin
    Jack avatar
    2208 posts
    Member since:
    Sep 2012

    Posted 04 Jul 2008 Link to this post

    Hi Tamás,

    Thank you for contacting us.

    I confirm that there is an issue in when inserting rows in RadGridView. You can work around this issue by setting the data source after inserting the rows. Take a look at the following code:

    DataTable dataTable1 = new DataTable(); 
    dataTable1.Columns.Add("Id"); 
    dataTable1.Columns.Add("Name"); 
     
    DataRow dataRow1 = dataTable1.NewRow(); 
    dataRow1["Id"] = 1; 
    dataRow1["Name"] = "Bob"
     
    DataRow dataRow2 = dataTable1.NewRow(); 
    dataRow2["Id"] = 2; 
    dataRow2["Name"] = "Alice"
     
    dataTable1.Rows.InsertAt(dataRow1, 0); 
    dataTable1.Rows.InsertAt(dataRow2, 0); 
     
    radGridView1.DataSource = dataTable1; 


    We will address this issue in our upcoming release later this month.

    I hope this helps. Do not hesitate to write me if you need further assistance.

    All the best,
    Jack
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

Back to Top