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

Add a new row problem

5 Answers 335 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sami Karaeen
Top achievements
Rank 1
Sami Karaeen asked on 15 Sep 2009, 07:04 AM
hi
iam trying to add some rows in code
the firsr row is added alone then ina loop all other rows are added
but the grid acts in very stupid way that its added the firts row and adds all other row on top of it
i have chnaged the way the new row added to buttom and also tried the top but nothing works
can u plz help couse iam very unhappy using this grid and if some more problems appears i will throw it away

5 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 15 Sep 2009, 10:03 AM
Hi Sami Karaeen,

When RadGridView is bound to a data source, the row order depends on the sorting that is applied. The row order can't be preserved in SQL in general. So, in this case you can change the sort order of your ID column for example. The following code snippet shows how to do this with code:

this.radGridView1.Columns["ID"].SortOrder = RadSortOrder.Descending; 
// or 
this.radGridView1.Columns["ID"].SortOrder = RadSortOrder.Ascending; 

When using RadGridView in unbound mode, you can insert rows at specific position by using Rows.Insert method:

GridViewDataRowInfo rowInfo = this.radGridView1.Rows.NewRow(); 
rowInfo.Cells[0].Value = k ++; 
rowInfo.Cells[1].Value = "Row " + k; 
rowInfo.Cells[2].Value = r.Next(10); 
this.radGridView1.Rows.Insert(this.radGridView1.Rows.Count, rowInfo); 

If you need more concrete suggestions, please send me your project and describe the desired behavior. I will be glad to help you further.

All the best,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
jerry
Top achievements
Rank 1
answered on 01 Feb 2010, 03:45 PM
Jack,

"When using RadGridView in unbound mode, you can insert rows at specific position by using Rows.Insert method:"

How can I add a blank row dynamically to a bound gridview at a specific location within that grid?

Thank You
0
Nick
Telerik team
answered on 02 Feb 2010, 09:45 AM
Hi jerry,

You cannot insert rows at concrete positions in a DataTable and for that reason you cannot insert rows at concrete positions in RadGridView (bound mode). In other words the limitation of the DataTable applies to RadGridView too.

Kind regards,
Nick
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
jerry
Top achievements
Rank 1
answered on 02 Feb 2010, 02:14 PM
Nick,
What would be the cleanest way around this issue?  Should I be populating my radgridview with my data by adding the each row through a for loop?  In your opinion what is the best way to have unbound data in the grid?

Thank You
0
Nick
Telerik team
answered on 04 Feb 2010, 09:32 AM
Hello jerry,

Thank you for contacting us. Yes, a for loop is necessary. I think that this help article covers your question in full.

Regards,
Nick
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
GridView
Asked by
Sami Karaeen
Top achievements
Rank 1
Answers by
Jack
Telerik team
jerry
Top achievements
Rank 1
Nick
Telerik team
Share this question
or