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

Adding NewRow question

18 Answers 335 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marjeta Segrec
Top achievements
Rank 1
Marjeta Segrec asked on 15 Apr 2009, 09:13 PM
Hello.

How can I handle adding NewRow when user press Insert Key ?

I need that option because I must proceed my own code for Adding New Row and Not generated from GridViewItemsControl.
I am using C1.Silverlight.Data.DataView for ItemsSource.

Thanks for your answer.

18 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 17 Apr 2009, 12:53 PM
Hello Marjeta Segrec,

You will need to subscirbe to the RadGridView.AddingNewDataItem event.

for example:

this.radGridView1.AddingNewDataItem += new System.EventHandler<Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs>(radGridView1_AddingNewDataItem); 


In the event handler you may write your custom code. Here you may create the new dataitem and feed it to the e.NewObject.

for example:

void radGridView1_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)  
        {  
            //Write your custom code here to create a new data item instance   
            e.NewObject = NewDataItemInstance;//this provides the newly created instance to the grid  
        } 


Sincerely yours,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
D. Omar
Top achievements
Rank 1
answered on 27 Apr 2009, 08:19 PM
It looks like the Insert key never fires KeyDown and also there is no way to turn that functionality off or cancel it from the AddingNewDataItem event. Is that correct? 

Thanks in advance,
 
0
Todd Anglin
Top achievements
Rank 2
answered on 28 Apr 2009, 07:23 PM
Omar-

Unfortunately, it seems you're correct. The KeyDown/KeyUp events do not get raised when you press the Insert key- only the AddingNewDataItem event. And that event does not currently provide a "Handled" or "Cancel" option in the event args. It would seem this is some somthing that needs to be addressed in the control's API. I'd expect that you'd like:

A) The KeyDown/Up events to fire for the Insert key before the AddingNewDataItem event fires
B) The AddingNewDataItem has an option to "Cancel" the insert
C) The GridView offers some property (like AllowInsert) to easily enable disabling of the insert feature

Does that sound right?

-Todd
0
D. Omar
Top achievements
Rank 1
answered on 28 Apr 2009, 07:56 PM
I think your engineers and their expertise writing APIs, along with hearing customer feedback for so long are be the best people to answer your questions but here are my 2 cents:

A) The KeyDown/Up events to fire for the Insert key before the AddingNewDataItem event fires
- Correct. Plus, I would also consider maybe not even firing the "Insert" process in the grid if the e.Handled is set to true in the KeyDown event (or some other implementation that enables me to do that). 

B) The AddingNewDataItem has an option to "Cancel" the insert
- Correct

C) The GridView offers some property (like AllowInsert) to easily enable disabling of the insert feature
- I would have the AllowInsert property but also another one where I can define the key for the grid to interpret as the InsertKey. I am working on an application where we want to enable the user to do as much as possible with the numerik keypad so the plus sign (+) is probably a better key for my application than the Insert key. But I don't have all my detailed requirements yet so I'd rather the grid let me define the key to use.

I would also like to be able to trigger this action programmatically. I would not mind if all the grid provides is a method for me to call when the time comes to add a new row. But I know I would not use that either, at least with the current implementation, because I am adding records in the middle of the grid, my requirement is to let the user insert rows at particular locations so what I am doing right now is insert a new object to the bound collection at the desired position.

Hope that helps!

-Omar
 
0
Pavel Pavlov
Telerik team
answered on 30 Apr 2009, 09:43 AM

HI,

Thank you for the constructive feedback! It is very helpful for us as we are now planning the improvements which should be made to the CRUD operations in RadGridView and especially when inserting new records.  We are planning to implement an MS Access like mode for adding new records. We are also going to improve the UI with the options of placing the "new row" UI element anywhere and not only at the top of the grid. We will definitely consider the scenario of inserting a new record "in the middle".  The API for inserting the new row is also a candidate for improvement. The aim is to utilize the commands pattern as well as provide a mapping mechanism between those commands and keyboard/mouse events.

This features will be gradually be added in our upcoming releases.

Regards,

Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Virendra
Top achievements
Rank 1
answered on 30 Apr 2009, 10:09 AM
Sorry,

I am *not* able to see the "AllowInsert" property. 
It is grid level property?

I am using your 13Apr09 build.

Thanks
virendra
0
D. Omar
Top achievements
Rank 1
answered on 30 Apr 2009, 02:58 PM
Virendra,

The AllowInsert is not currently a property of the control. That is one of the reasons we are exchanging thoughts in this thread. Todd mentioned in present tense in his (C) bullet but those bullets were preceeded by a "you'd like" statement. Hopefully they will have that soon.
0
D. Omar
Top achievements
Rank 1
answered on 01 May 2009, 04:39 PM
Pavel,

May I request that a way to completely turn off that feature be prioritized for the next release? (i.e. the AllowInsert) property.

Thanks in advance,

-Omar
0
Pavel Pavlov
Telerik team
answered on 04 May 2009, 01:56 PM
Hi Omar,

I have taken care and the team is already adding the missing API for disabling the insertion. This is of high priority.

Please excuse us for the inconvenience caused.

Sincerely yours,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
D. Omar
Top achievements
Rank 1
answered on 04 May 2009, 02:21 PM
You guys rock!!

This kind of responses and service make a huge difference. Please keep up that MO!

Thank you!
0
Marco
Top achievements
Rank 1
answered on 29 May 2009, 06:00 PM
Hi,
Do you know when this solution is going to be available? (if not already in Q1 2009 SP2)
Any of the solutions that Todd mentioned is ok to me :)

Thanks,
Marco
0
Vlad
Telerik team
answered on 30 May 2009, 06:23 AM
Hi Marco,

You can find our new property CanUserInsertRows in the latest official service pack.
More info:
http://www.telerik.com/products/silverlight/whats-new/release-history/q1-2009-sp2-version-2009-1-526.aspx

Best wishes,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Marco
Top achievements
Rank 1
answered on 01 Jun 2009, 02:51 PM
Cool!
By the time I read this update I had installed and tried that property.   That is exactly what I needed.

Thanks for your quick response, as usual :)
Marco
0
Marc Roussel
Top achievements
Rank 2
answered on 26 Jan 2010, 03:50 PM
Hi,

I'm looking for the knowledge for cancelling an add new row from the grid.
When the user click on "Click here to add new item"
I'm getting as mentioned above, in the AddingNewDataItem and set the e.NewObject

and once the user gets in the RowEditEnded, I have to look if he set all the values otherwise I need to cancel
that means the new empty row should disapear.
I tried : e.EditAction = GridViewEditAction.Cancel;

But it says it's readonly but in the comment it's written Gets Or Sets.....

How it's done ?
Thank you
0
Nedyalko Nikolov
Telerik team
answered on 27 Jan 2010, 08:51 AM
Hello Marc Roussel,

You can use RadGridView validation mechanism in order to validate the row content. If you do not want to enforce user to input all needed data, you can call RadGridView.CancelEdit(). You can take a look at this online help topic for a reference.

Sincerely yours,
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
Marc Roussel
Top achievements
Rank 2
answered on 27 Jan 2010, 11:04 AM
Hi,

That's cool but not what.  I don't need to validate the values.  I just want to cancel edit and when I call CancelEdit()
the row added by the grid to add values stays there after the CancelEdit() call.  Is there anything else I need to do to make the grid remove the blank line it added ?

Since I don't want to force the user to enter values, if he doesn't enter something, there's no need to keep the blank row added by the grid.  Thank you
0
Nedyalko Nikolov
Telerik team
answered on 27 Jan 2010, 12:49 PM
Hello Marc Roussel,

The RowEditEnded event is fired when row is already committed to the underlying data source. In order to achieve the described behavior you have to check row data in the RowValidating event handler. This event is fired when row is about to be committed, so at this stage RadGridView.CancelEdit() will remove the newly added item.
 
Best wishes,
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
Marc Roussel
Top achievements
Rank 2
answered on 27 Jan 2010, 02:13 PM
Now it's clear with the RowValidating event. 
and it works as expected when doing e.IsValid = false in RowValidating

Thank you
Tags
GridView
Asked by
Marjeta Segrec
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
D. Omar
Top achievements
Rank 1
Todd Anglin
Top achievements
Rank 2
Virendra
Top achievements
Rank 1
Marco
Top achievements
Rank 1
Vlad
Telerik team
Marc Roussel
Top achievements
Rank 2
Nedyalko Nikolov
Telerik team
Share this question
or