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

AddingNewDataItem and Default Value

3 Answers 172 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 03 May 2011, 03:43 PM
Hello everyone,

Well, it's wokring but I need explanation or a better way to achieve this.  When I add a new record in my RadGridView, I have to display some default values.

So, I have this code in the AddingNewDataItem event of the RadGridView

private void RadGridViewEtapes_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
{
        e.NewObject = new myentity.Web.Etapes
        {
            NoEtapeClient = 1,
            NoTypeEtape = 1
        };
}

And it's working fine (note that I use Entity Framework like DomainService.cs and DomainService.metadata.cs on server side)

And in the RowEditEnded this code :

private void RadGridViewEtapes_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)
{
    if (e.NewData != null)
    {
        if (e.EditAction == Telerik.Windows.Controls.GridView.GridViewEditAction.Commit)
        {
            RadDomainDataSourceEtapesAvantPendantApresEntree.DataView.Add(e.NewData);                    
            etapesavantpendantapresentreeDomainContext ctx = (etapesavantpendantapresentreeDomainContext)RadDomainDataSourceEtapesAvantPendantApresEntree.DomainContext;
            ctx.SubmitChanges(ResultatOperation =>
            {
                if (ResultatOperation.HasError)
                {
                    ResultatOperation.MarkErrorAsHandled();
                    ctx.RejectChanges();
                }
                else
                {
                    RadDomainDataSourceEtapesAvantPendantApresEntree.Load();
                }
            }, null);
        }
    }
}

In fact without the line

RadDomainDataSourceEtapesAvantPendantApresEntree.DataView.Add(e.NewData);  

the ctx.SubmitChanges never append because HasChanges (of ctx) is always False.
So, to force it, I have to add by code the new information (e.NewData).

After, that, my new data appear two time in the RadGridVIew, I have to Load the DomainDataSource :

RadDomainDataSourceEtapesAvantPendantApresEntree.Load();

And then, I see my new data in just one row.

Any idea to this more nicely?

Have wonderful day.

3 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 04 May 2011, 01:14 PM
Hi Louis Bouchard,

I have tested the scenario when adding a new item and whether the HasChanges property is changed. However, as expected, it is set to "True" on inserting it. Consequently, there is no need to add it directly to the DataView. Still, I am sending you the sample I used for the test. May you take a look at it and let me know in case of any misunderstandings according to your requirements ?
  

Greetings,
Maya
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 04 May 2011, 03:48 PM
A bg thank you Maya.

I change my DomainDataSource for telerik (change riaControls:DomainDataSource for telerik:RadDomainDataSource).

It's working.  Thank you for your demonstration.

But, on this Silverlight page I have two RadGridView.

The very first time when I arrived on the page, the second RadGridView is not showing the related records.  I have to go to the next record (in the first RadGridView) and return to the first record to see it.  See attachements.

Any idea? 

This is my DomainDataSources

Master :

<telerik:RadDomainDataSource x:Name="RadDomainDataSourceMaster"  QueryName="GetCategoriesR" AutoLoad="True"  PageSize="20">
    <telerik:RadDomainDataSource.DomainContext>
        <contextedomaine:categoriesrDomainContext />
    </telerik:RadDomainDataSource.DomainContext>
</telerik:RadDomainDataSource>


Detail:

<telerik:RadDomainDataSource x:Name="RadDomainDataSourceDetails"  QueryName="GetEtapesD" AutoLoad="True"  PageSize="20">
    <telerik:RadDomainDataSource.DomainContext>
        <contextedomaine:etapesDomainContext />
    </telerik:RadDomainDataSource.DomainContext>
    <telerik:RadDomainDataSource.QueryParameters >
        <telerik:QueryParameter ParameterName="intNo"  Value="{Binding Source={StaticResource RadDomainDataSourceMaster}, Path=DataView.No, Mode=TwoWay}"/>
    </telerik:RadDomainDataSource.QueryParameters>
</telerik:RadDomainDataSource>

0
Maya
Telerik team
answered on 09 May 2011, 09:26 AM
Hello Louis Bouchard,

May you try to set the IsSynchronizedWithCurrentItem property of the parent grid to "true" ? Does the issue still persist ?

Kind regards,
Maya
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
Maya
Telerik team
Louis Bouchard
Top achievements
Rank 1
Share this question
or