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

New record and default value

5 Answers 112 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Louis Bouchard
Top achievements
Rank 1
Louis Bouchard asked on 27 Jun 2010, 03:46 AM
Hello,

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

Sort by
0
Yavor Georgiev
Telerik team
answered on 29 Jun 2010, 11:11 AM
Hi Louis Bouchard,

 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";
    };

All the best,
Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Louis Bouchard
Top achievements
Rank 1
answered on 30 Jun 2010, 10:41 PM
Thank Yavor,

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")

 

        };

}

0
Yavor Georgiev
Telerik team
answered on 01 Jul 2010, 09:43 AM
Hi Louis Bouchard,

 Please find attached a sample project. Don't hesitate to let me know if you need any help.

Greetings,
Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Louis Bouchard
Top achievements
Rank 1
answered on 02 Jul 2010, 06:07 PM
Hello Yavor,

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.

0
Yavor Georgiev
Telerik team
answered on 05 Jul 2010, 10:18 AM
Hello Louis Bouchard,

 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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Louis Bouchard
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
Louis Bouchard
Top achievements
Rank 1
Share this question
or