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

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

3 Answers 28 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dexter
Top achievements
Rank 1
Dexter asked on 25 Jul 2014, 04:09 PM
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;
        }

3 Answers, 1 is accepted

Sort by
0
Dexter
Top achievements
Rank 1
answered on 25 Jul 2014, 05:32 PM
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?
0
Accepted
Dimitrina
Telerik team
answered on 28 Jul 2014, 07:08 AM
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.
 
0
Dexter
Top achievements
Rank 1
answered on 28 Jul 2014, 08:21 AM
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.
Tags
GridView
Asked by
Dexter
Top achievements
Rank 1
Answers by
Dexter
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or