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

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

3 Answers 1050 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nicky
Top achievements
Rank 1
Nicky asked on 10 Oct 2007, 03:48 PM
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

3 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 11 Oct 2007, 11:55 AM
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
0
Tamás
Top achievements
Rank 1
answered on 04 Jul 2008, 08:27 AM
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

0
Jack
Telerik team
answered on 04 Jul 2008, 02:27 PM
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
Tags
GridView
Asked by
Nicky
Top achievements
Rank 1
Answers by
Jack
Telerik team
Tamás
Top achievements
Rank 1
Share this question
or