6 Answers, 1 is accepted
The same insert functionality like in SQL in not supported by the GridView. You may achieve something close though by handling the RowEditEdit event of the GridView.
private
void
clubsGrid_RowEditEnded(
object
sender, GridViewRowEditEndedEventArgs e)
{
RadGridView grid = sender
as
RadGridView;
if
(grid.SelectedItem == e.Row.Item && grid.Items.IndexOf(e.Row.Item) == (grid.Items.Count - 1))
{
grid.BeginInsert();
}
}
That way every time when you finish editing of a new row (by Enter or Tab buttons click), one more new row will be added.
Of course you may always use the Insert button to add a new row.
I have prepared a sample project, showing the described suggestion.
Regards,
Didie
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!
Very helpful
May I ask you to update the attached sample project with the change you have done? Does it work fine with our previous version?
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
RadGridView grid = sender
as
RadGridView;
if
(grid ==
null
)
return
;
if
(grid.Items.IndexOf(e.Row.Item) == (grid.Items.Count - 1) && e.EditOperationType == GridViewEditOperationType.Insert)
{
grid.BeginInsert();
}
The original code had this condition in the if(), which was always false for me (no matter what I did):
grid.SelectedItem == e.Row.Item
I added the condition check on the "E.EditOperationType" just to make sure this was only happening after a new row was already inserted. I don't see how that could cause a problem. The exception happens on the "grid.BeginInsert()" call.
I can't tell you if it worked with previous versions, this is the first time I've tried to do this. =)
Thank you for the code snippet. I have changed the project to use the suggested code together with the latest binaries. So far I was not able to encounter any problem.
Please find the changed project attached.
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>