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

add new rows by default

6 Answers 128 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Avi Avni
Top achievements
Rank 1
Avi Avni asked on 04 Jul 2011, 02:47 PM

Hello

Is there option add new rows by default

 When the users get to the end of the row Like in SQL?

Best regards

Ehud

6 Answers, 1 is accepted

Sort by
0
Accepted
Dimitrina
Telerik team
answered on 06 Jul 2011, 01:42 PM
Hello Ehud Pinchas,

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!

0
Avi Avni
Top achievements
Rank 1
answered on 06 Jul 2011, 01:58 PM
Thank you
Very helpful
0
Joe Sharp
Top achievements
Rank 1
answered on 26 Jun 2012, 08:04 PM
I'm trying to implement something similar with the newest release (Q2 '12) and when I do this I get an exception in the GridViewBoundColumnBase.GetValidationErrors().  It seems to be complaining that the "dataItem" (first parameter to the method) is null.  Any quick ideas, I'm guessing this has something to do with some changes to the GridView since june of last year.
0
Dimitrina
Telerik team
answered on 27 Jun 2012, 01:03 PM
Hello,

May I ask you to update the attached sample project with the change you have done? Does it work fine with our previous version?
 

Regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Joe Sharp
Top achievements
Rank 1
answered on 27 Jun 2012, 10:13 PM
This is the only change that I made:

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. =)
0
Dimitrina
Telerik team
answered on 28 Jun 2012, 09:05 AM
Hello,

 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.

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Avi Avni
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Avi Avni
Top achievements
Rank 1
Joe Sharp
Top achievements
Rank 1
Share this question
or