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

[Solved] Insert in Master-Detail on Detail-Data

3 Answers 247 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Paul Exler
Top achievements
Rank 1
Paul Exler asked on 02 Jun 2010, 10:12 AM
Hi everybody,

I don't get it... I use VS2010 and Silverlight 4 with Ria Services.
I use LinqToSql-DomainService's with my own classes.

I have a master-detail scenario. I have Products and ProductDatas
Every Product has a EntitySet of ProductDatas.

In my view, I can show the master and detail data. I also can insert/edit/delete Products. But I only can edit the ProductDatas. Insert and delete is not possible (from the RadGridView -> directly via DomainService, it works).

I also tried to set the "ShowInsertRow" property. The Row is displayed in my master and detail, but it only works in my master-grid. When I click this row on my detail-grid, nothing happend.

I post some code for a better understanding:

My class definitions on the server side:

    public class ProductDBItem 
    { 
        [Key]         
        public int ProductId { get; set; } 
        public string Productname { get; set; } 
        .... 
 
        private EntitySet<ProductDataDBItem> _ProductDatas; 
 
        [Include] 
        [Composition] 
        [AssociationAttribute("ProductDBItem_ProductDataDBItem","ProductId","ProductId")] 
        public EntitySet<ProductDataDBItem> ProductDatas 
        { 
            get 
            { 
                if (_ProductDatas == null) 
                    _ProductDatas = new EntitySet<ProductDataDBItem>(); 
                return _ProductDatas; 
            } 
            set  
            { 
                _ProductDatas = value;  
            } 
        } 
    } 
    public class ProductDataDBItem 
    { 
        [Key] 
        public int ProductDataId { get; set; } 
        public int ProductId { get; set; } 
        public int LanguageId { get; set; } 
        ... 
    } 

The auto-generated code for the ProductDBItem on client side looks like this:

    public sealed partial class ProductDBItem : Entity 
    {  
         
        private EntityCollection<ProductDataDBItem> _productDatas; 
         
        private int _productId; 
         
        .... 
         
        #region Extensibility Method Definitions 
 
        /// <summary> 
        /// This method is invoked from the constructor once initialization is complete and 
        /// can be used for further object setup. 
        /// </summary> 
        partial void OnCreated(); 
        partial void OnProductIdChanging(int value); 
        partial void OnProductIdChanged(); 
        .... 
 
        #endregion 
         
         
        /// <summary> 
        /// Initializes a new instance of the <see cref="ProductDBItem"/> class. 
        /// </summary> 
        public ProductDBItem() 
        { 
            this.OnCreated(); 
        } 
         
        /// <summary> 
        /// Gets the collection of associated <see cref="ProductDataDBItem"/> entities. 
        /// </summary> 
        [Association("ProductDBItem_ProductDataDBItem", "ProductId", "ProductId")] 
        [Composition()] 
        public EntityCollection<ProductDataDBItem> ProductDatas 
        { 
            get 
            { 
                if ((this._productDatas == null)) 
                { 
                    this._productDatas = new EntityCollection<ProductDataDBItem>(this, "ProductDatas", this.FilterProductDatas); 
                } 
                return this._productDatas; 
            } 
        } 
         
        /// <summary> 
        /// Gets or sets the 'ProductId' value. 
        /// </summary> 
        [DataMember()] 
        [Editable(false, AllowInitialValue=true)] 
        [Key()] 
        [RoundtripOriginal()] 
        public int ProductId 
        { 
            get 
            { 
                return this._productId; 
            } 
            set 
            { 
                if ((this._productId != value)) 
                { 
                    this.OnProductIdChanging(value); 
                    this.ValidateProperty("ProductId", value); 
                    this._productId = value
                    this.RaisePropertyChanged("ProductId"); 
                    this.OnProductIdChanged(); 
                } 
            } 
        } 
         
        ... 
         
        private bool FilterProductDatas(ProductDataDBItem entity) 
        { 
            return (entity.ProductId == this.ProductId); 
        } 
         
        /// <summary> 
        /// Computes a value from the key fields that uniquely identifies this entity instance. 
        /// </summary> 
        /// <returns>An object instance that uniquely identifies this entity instance.</returns> 
        public override object GetIdentity() 
        { 
            return this._productId; 
        } 
    } 

The XAML - Code of my master-detail view:

        <riaControls:DomainDataSource  
            AutoLoad="True" 
            LoadedData="DomainDataSource_LoadedData"  
            x:Name="ProductDomainDataSourceOriginal"  
            QueryName="GetProductDBItemsQuery"  
            SubmittedChanges="ProductDomainDataSource_SubmittedChanges" 
            LoadingData="ProductDomainDataSourceOriginal_LoadingData"
            <riaControls:DomainDataSource.DomainContext> 
                <service:ProductContext /> 
            </riaControls:DomainDataSource.DomainContext> 
            <riaControls:DomainDataSource.QueryParameters> 
                <riaControls:Parameter ParameterName="languageId" Value="{Binding ElementName=languageSelectOriginal, Path=SelectedLanguageID}"/>                 
            </riaControls:DomainDataSource.QueryParameters> 
        </riaControls:DomainDataSource> 
 
...... 
 
        <telerik:RadGridView AutoGenerateColumns="False"  
                             HorizontalAlignment="Stretch"  
                             Margin="0,70,0,0"  
                             Name="grdProductOriginal"  
                             VerticalAlignment="Stretch"  
                             ItemsSource="{Binding ElementName=ProductDomainDataSourceOriginal, Path=Data}"  
                             IsBusy="{Binding IsLoadingData, ElementName=ProductDomainDataSourceOriginal}"  
                             RowLoaded="grdProductOriginal_RowLoaded"  
                             Grid.Column="0"  
                             RowEditEnded="grdProductOriginal_RowEditEnded"  
                             ShowInsertRow="True"
            <telerik:RadGridView.Columns> 
                <telerik:GridViewToggleRowDetailsColumn /> 
                <telerik:GridViewDataColumn Header="Productname" DataMemberBinding="{Binding Productname, Mode=TwoWay}" Width="120"/> 
                <telerik:GridViewDataColumn Header="Maingroup" DataMemberBinding="{Binding GroupMainId, Mode=TwoWay}" Width="120"/> 
                <telerik:GridViewDataColumn Header="Subgroup" DataMemberBinding="{Binding GroupSubId, Mode=TwoWay}" Width="120"/> 
                <telerik:GridViewDataColumn Header="Pattern" DataMemberBinding="{Binding Pattern, Mode=TwoWay}" Width="120"/> 
                <telerik:GridViewDataColumn Header="Picture" DataMemberBinding="{Binding ImageId, Mode=TwoWay}" Width="120"/>                                 
            </telerik:RadGridView.Columns> 
            <telerik:RadGridView.RowDetailsTemplate> 
                <DataTemplate> 
                    <telerik:RadTabControl BackgroundVisibility="Collapsed" x:Name="tabProductData" Margin="10" VerticalAlignment="Center" Background="Transparent"
                        <telerik:RadTabItem Header="Daten" Margin="10,0,0,0" Height="24" Foreground="Black"
                            <Grid> 
                                <telerik:RadGridView Margin="0,5,0,0"  
                                                     AutoGenerateColumns="false"  
                                                     HorizontalAlignment="Stretch"  
                                                     Name="grdProductDataOriginal"  
                                                     VerticalAlignment="Stretch"  
                                                     ItemsSource="{Binding ProductDatas, Mode=TwoWay}"  
                                                     RowEditEnded="grdProductOriginal_RowEditEnded"  
                                                     CanUserInsertRows="True"  
                                                     CanUserDeleteRows="True"  
                                                     ShowInsertRow="True"
                                    <telerik:RadGridView.Columns> 
                                        <telerik:GridViewDataColumn Header="Order-No." DataMemberBinding="{Binding OrderNo, Mode=TwoWay}" Width="100"/> 
                                        <telerik:GridViewDataColumn Header="Caption" DataMemberBinding="{Binding ProductDataCaption, Mode=TwoWay}" Width="150"/> 
                                        <telerik:GridViewDataColumn Header="Text" DataMemberBinding="{Binding ProductDataText}" Width="320"
                                            <telerik:GridViewDataColumn.CellEditTemplate> 
                                                <DataTemplate> 
                                                    <TextBox Text="{Binding ProductDataText, Mode=TwoWay}" AcceptsReturn="True" KeyDown="TextBox_KeyDown"/> 
                                                </DataTemplate> 
                                            </telerik:GridViewDataColumn.CellEditTemplate> 
                                        </telerik:GridViewDataColumn> 
                                    </telerik:RadGridView.Columns> 
                                </telerik:RadGridView> 
                            </Grid> 
                        </telerik:RadTabItem> 
                        <telerik:RadTabItem Header="Vorschau" Margin="10,0,0,0" Height="24" Foreground="Black"
                        </telerik:RadTabItem> 
                        <telerik:RadTabItem Header="Menge" Margin="10,0,0,0" Height="24" Foreground="Black"
                        </telerik:RadTabItem> 
                    </telerik:RadTabControl> 
                </DataTemplate> 
            </telerik:RadGridView.RowDetailsTemplate> 
        </telerik:RadGridView> 
 

My Domainservice on server side:

    [RequiresAuthentication] 
    [EnableClientAccess()] 
    public class ProductService : LinqToSqlDomainService<ltsMainModelDataContext> 
    { 
        public IQueryable<ProductDBItem> GetProductDBItems(int languageId) 
        { 
            var result = new List<ProductDBItem>(); 
             
            .... 
            
            return result.AsQueryable(); 
        } 
 
        public void InsertProductDBItem(ProductDBItem item) 
        { 
            ...             
        }       
 
        public void UpdateProductDBItem(ProductDBItem item) 
        { 
            ... 
        } 
 
        public void DeleteProductDBItem(ProductDBItem item) 
        { 
            ... 
        } 
    } 




I don't have a seperate DomainService for the ProductDataDBItem (because I include them in the ProductDBItem-Domainservice)

I hope thats all you need to understand my problem.

So. What can I do? Why can't I insert a row in the detail-grid with the "InsertRow"?

3 Answers, 1 is accepted

Sort by
0
Accepted
Maya
Telerik team
answered on 02 Jun 2010, 12:16 PM
Hello Paul Exler,

Please take a look at this forum thread.
 

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.
0
Paul Exler
Top achievements
Rank 1
answered on 02 Jun 2010, 06:03 PM
Thank you for your answer.

I found a solution after reading the linked post: Blog post

I modified it in some way's and now I am able to insert and delete Detail-Data's. And I have asynchronous loads... really nice :)
0
Milind Raje
Top achievements
Rank 1
answered on 02 Feb 2011, 05:15 PM
hi Paul,
Can you please show me the ProductDatas domain datasource definition? I am trying to design a master-detail view, however, how do you send "selected" key values (such as productID) to the detail view?
thanks
milind
Tags
GridView
Asked by
Paul Exler
Top achievements
Rank 1
Answers by
Maya
Telerik team
Paul Exler
Top achievements
Rank 1
Milind Raje
Top achievements
Rank 1
Share this question
or