Upon clicking "Click here to add new row", how to display default custom field values?

4 posts, 1 answers
  1. Dexter
    Dexter avatar
    34 posts
    Member since:
    Dec 2012

    Posted 25 Jul 2014 Link to this post

    Hello, I would like to enquire on the scenario as per title. I have already managed to set the values, just that the grid didn't display these values to the user. In other words, when I click "Click here to add new row", the fields are displayed as all blank (or for int column, the value is 0). But my codes do work at the back end - if the user press enter without modifying anything, the custom values I set will be added to the database. So how can I let the user see the custom default values upon clicking "Click here to add new row"? Below is the code I have, which work perfectly back-end, but didn't display to user.

    private void GridCommsItem_OnPreparingCellForEdit(object sender, GridViewPreparingCellForEditEventArgs e)
            {
                ((CommsItem)e.Row.DataContext).Status = "Store";
                ((CommsItem)e.Row.DataContext).Quantity = 1;
            }
  2. Dexter
    Dexter avatar
    34 posts
    Member since:
    Dec 2012

    Posted 25 Jul 2014 Link to this post

    Update: I realized that my code above also hindered editings (keep setting to the values as per defined).

    So nevermind the whole thing, my question would be, how to set custom default values which will automatically be inputted for the user when "Click here to add new row" is clicked (then the user will edit whatever he wants BEFORE commiting the add), which will also not interfere with editing?
  3. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 28 Jul 2014 Link to this post

    Hi,

    You can try specifying values for the newly added row when the AddingNewDataItem event is raised.
    Like this:

    void MainWindow_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
     {
         e.NewObject = new Player("Name 1", 6, Position.DF, "Spain");
     }


    Regards,
    Didie
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  4. Dexter
    Dexter avatar
    34 posts
    Member since:
    Dec 2012

    Posted 28 Jul 2014 Link to this post

    Ah, looks like that did the trick, thanks! I didn't try to mess with that initially as I thought it would affect ItemID and certain ID fields that would be sent over to the database upon adding. But looks like instantiating them to all 0 is fine; they will be reflected correctly in the database.
Back to Top