
When I add a new record in a RadGridView, I need to set a default value for one field. Someone can help me about that. I try to set it like this but the value disappear when I click in the cell :
private void RadGridViewFiches_BeginningEdit(object sender, GridViewBeginningEditRoutedEventArgs e)
{
e.Row.Cells[1].Content = "b5314c4b-4f37-4a48-8c56-f3ee1489aec8";
}
5 Answers, 1 is accepted
I would suggest to handle the GridView's AddingNewDataItem event. This gives you access to the actual data item that is being added and you can modify it as you see fit before it ends up in the GridView.
Another approach, although I wouldn't suggest it, is to trap the GridViewCell's editing element directly like so:
var elem = cell.GetEditingElement()
as
TextBox;
elem.Loaded += (o, e) =>
{
(o
as
TextBox).Text =
"Default Value"
;
};
Yavor Georgiev
the Telerik team

I try this wIithout success. Can you show me a complet example?
private
void RadGridViewFiches_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
{
e.NewObject =
new BusinessApplicationTest.Web.Fiches
{
NoFicheEspaceClos =
new Guid("b5314c4b-4f37-4a48-8c56-f3ee1489aec8")
};
}
Please find attached a sample project. Don't hesitate to let me know if you need any help.
Greetings,Yavor Georgiev
the Telerik team

Thank you for the demo. But I use a BusinessApplication with SL4. So, I got a edmx file and I don't know what kind of object I have to instanciate :
e.NewObject = new ???????????????? |
{ |
NoFiche = new Guid("afa339d4-a9a1-470c-a659-ce1abcaa0fd7") |
}; |
Your sample project don't use Entity Framework. Can you provide me more help about that.
It's very simple, I juste want to provide a default value for a specific field when the user add a new record with the RadGridView.
If you are using Entity Framework, all you need to do is set the Default Value property of the Entity's Scalar Property in the EDMX Designer, you don't need to handle AddingNewDataItem.
Kind regards,Yavor Georgiev
the Telerik team