Adding NewRow question

19 posts, 0 answers
  1. Marjeta Segrec
    Marjeta Segrec avatar
    18 posts
    Member since:
    May 2006

    Posted 15 Apr 2009 Link to this post

    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.
  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 17 Apr 2009 Link to this post

    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.
  3. DevCraft banner
  4. D. Omar
    D. Omar avatar
    29 posts
    Member since:
    Mar 2009

    Posted 27 Apr 2009 Link to this post

    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,
     
  5. Todd Anglin
    Todd Anglin avatar
    2040 posts
    Member since:
    Aug 2005

    Posted 28 Apr 2009 Link to this post

    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
  6. D. Omar
    D. Omar avatar
    29 posts
    Member since:
    Mar 2009

    Posted 28 Apr 2009 Link to this post

    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
     
  7. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 30 Apr 2009 Link to this post

    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.
  8. Virendra
    Virendra avatar
    50 posts
    Member since:
    Aug 2012

    Posted 30 Apr 2009 Link to this post

    Sorry,

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

    I am using your 13Apr09 build.

    Thanks
    virendra
  9. D. Omar
    D. Omar avatar
    29 posts
    Member since:
    Mar 2009

    Posted 30 Apr 2009 Link to this post

    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.
  10. D. Omar
    D. Omar avatar
    29 posts
    Member since:
    Mar 2009

    Posted 01 May 2009 Link to this post

    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
  11. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 04 May 2009 Link to this post

    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.
  12. D. Omar
    D. Omar avatar
    29 posts
    Member since:
    Mar 2009

    Posted 04 May 2009 Link to this post

    You guys rock!!

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

    Thank you!
  13. Marco
    Marco avatar
    23 posts
    Member since:
    Apr 2009

    Posted 29 May 2009 Link to this post

    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
  14. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 30 May 2009 Link to this post

    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.
  15. Marco
    Marco avatar
    23 posts
    Member since:
    Apr 2009

    Posted 01 Jun 2009 Link to this post

    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
  16. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 26 Jan 2010 Link to this post

    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
  17. Nedyalko Nikolov
    Admin
    Nedyalko Nikolov avatar
    871 posts

    Posted 27 Jan 2010 Link to this post

    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.
  18. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 27 Jan 2010 Link to this post

    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
  19. Nedyalko Nikolov
    Admin
    Nedyalko Nikolov avatar
    871 posts

    Posted 27 Jan 2010 Link to this post

    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.
  20. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 27 Jan 2010 Link to this post

    Now it's clear with the RowValidating event. 
    and it works as expected when doing e.IsValid = false in RowValidating

    Thank you
Back to Top
DevCraft banner