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

[Solved] Hit <Insert> key to add a new row and commit at same time.

3 Answers 265 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Manas
Top achievements
Rank 1
Manas asked on 08 Sep 2009, 01:43 PM

Hi,

 

I have a hierarchical RadGridView, in child grid user can add new row, edit and delete.

To adding new row Telerik RadGridView has two steps like hit <INSERT> key then new row is created and appears on top (Execute BeginInsert() à RadGridView_AddingNewDataItem(object sender, GridViewAddingNewEventArgs e)),  again user hit <ENTER> or tabbed out to commit then new row goes to bottom of the grid ( Execute RadGridView_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)).

 

Now I need this two steps operation by single <Insert> button hit.

Is it possible?

If anybody has already done this, please help me.

 

Thanks,

Manas

3 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 10 Sep 2009, 02:22 PM
Hello Manas,

As I understand you want on Insert key press immediately add new item, this means without user to confirm it.
Generally, the described behavior is a little bit strange, so it is not supported by RadGridView out of the box. However you can work around this by handling RadGridView.BeginningEdit event and call RadGridView.CommitEdit() with a dispatcher (the only problem is to recognize new row by data item):

void radGridView_BeginningEdit(object sender, GridViewBeginningEditRoutedEventArgs e) 
    Func<bool> actionToExecute = this.radGridView.CommitEdit; 
    Dispatcher.BeginInvoke(actionToExecute); 


Greetings,
Nedyalko Nikolov
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
Michelle Bruce
Top achievements
Rank 1
answered on 10 Sep 2009, 05:24 PM
Nedyalko,
    I am a colleague of Manas' in the US.  Although I do not have full understanding of the in's and out's of this issue, I would like to make sure your answer is clear.... as to not waste a day.

I spoke with Manas last night and he mentioned that within the telerik .dll that the call to CommitEdit or something subsequent to that required some parameters in order to commit the correct row.  You have noted below a solution and then mentioned "(the only problem is to recognize new row by data item)".  Does this mean that you have provided somewhat of an answer and then said that it will not work?  Or have you given the answer and left a trivial problem for Manas to figure out himself (namely getting a handle on the correct data item)?

I hope that my limited understanding of the issue is enough to provide a description that makes sense.   Look forward to your answer..

Thanks!

0
Nedyalko Nikolov
Telerik team
answered on 11 Sep 2009, 06:52 AM
Hello Michelle Bruce,

As I say this functionality is a little bit strange, if you want to insert rows without end user confirmation, you should add them directly to the data source. When user adds a row with Insert key I believe he/she wants to confirm that this row should be added to the underlying data source.

That's why a partial solution for this case is a small hack, because when user hit Insert new added row automatically enters into edit mode, so BeginningEdit is fired. When you hook for this event you can call CommitEdit() without parameters, just have to call this only for the new added row, that's what I mean by "recognize", otherwise end user will be unable to edit any row.

I'm attaching a sample project which can give you an idea how to do that.

Hope this helps.

Kind regards,
Nedyalko Nikolov
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.
Tags
GridView
Asked by
Manas
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Michelle Bruce
Top achievements
Rank 1
Share this question
or