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
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.
Thanks in advance,
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
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,
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.
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.
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
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.
This kind of responses and service make a huge difference. Please keep up that MO!
Thank you!
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
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.
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
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
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.
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
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.
and it works as expected when doing e.IsValid = false in RowValidating
Thank you