Welcome to the Xceed Community Sign in | Join | Help
Community Search  

Linq Master Detail grid: Insert on Detail level

Sort Posts: Previous Next
  •  04-25-2008, 3:31 AM Post no. 11728

    Linq Master Detail grid: Insert on Detail level

    Hi

     I've got a Master Detail grid bound to a BindingList of objects returned from Linq. I've got almost everything working. I can add items to the Master level, I can edit items in the master level etc. This was not easy. I had to override a bunch of classes to get this to work the way I wanted it to work.

    To get the details view, I've overriden the DataGridDetailDescription class as described in the examples. The problem is that the GetDetailsForParentItem returns an IEnumerable, so when I want to insert a new row in the details table I get the dreaded "An attempt was made to add a new data item to a source that does not support insertion." message.

    Is there any way that I can get bind to the details level to the child relationships of linq objects, and have these detail rows insertable?

    Without this functionality, the whole premise of what I'm trying to do with the grid falls flat.  

    Thank you

     

    Filed under: ,
  •  04-25-2008, 9:01 AM Post no. 11733 in reply to 11728

    Re: Linq Master Detail grid: Insert on Detail level

    IBindingList implements IEnumerable; therefore, as long as you are returning an IBindingList and its AllowNew property returns true you should have no issues inserting items in details.

    Take a look at the Creating a Custom Detail Description example in the documentation. In the GetDetailsForParentItem, I return a new BindingList as such (using the GetNewBindingList method):

           object details = foundProperty.GetValue( parentItem, null );
           Type detailsType = details.GetType();
           MethodInfo getNewBindingList = detailsType.GetMethod(
    "GetNewBindingList" );

           
    return ( IEnumerable )getNewBindingList.Invoke( details, null );

    Even if it is cast as an IEnumerable, I am still able to insert new data items.

     


    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
    Filed under: ,
  •  04-25-2008, 10:52 AM Post no. 11742 in reply to 11733

    Re: Linq Master Detail grid: Insert on Detail level

    Hi Jenny

    Thanks for your reply.

    I am using exactly that example: An IBindingList cast to IEnumerable, but I can not insert a row.

    Henry

  •  04-25-2008, 11:03 AM Post no. 11743 in reply to 11742

    Re: Linq Master Detail grid: Insert on Detail level

    Would it be possible for you to provide me with a repro application (support@xceedsoft.com)? I tested with the Employees table created from the Linq DataContext using the Northwind.mdf sample database and the LinqToSqlDetailDescription and was able to insert into details. The InsertionRow was located in the footers of the details.


    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
  •  04-25-2008, 11:15 AM Post no. 11744 in reply to 11743

    Re: Linq Master Detail grid: Insert on Detail level

    Hi Jenny

    If it is working on your side, then I'm clearly just messing up something on my side. I'll fool around a bit and see what I can come up with. If I can not fix it I'll try to build a reproducable sample.

    Could you perhaps just post the XAML of your details section?

    Thanks again for your quick replies.

  •  04-25-2008, 11:27 AM Post no. 11747 in reply to 11744

    Re: Linq Master Detail grid: Insert on Detail level

    <Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid">
    <Grid.Resources>


     <xcdg:DataGridCollectionViewSource x:Key="cvs_employees"
                                        Source="{Binding Source={x:Static Application.Current},
                                                     Path=Employees}">

        <xcdg:DataGridCollectionViewSource.DetailDescriptions>
           <xcdg:DataRelationDetailDescription RelationName="Employee_Orders"
                                               Title="Employee Orders">
              <xcdg:DataRelationDetailDescription.DetailDescriptions>
                 <xcdg:DataRelationDetailDescription RelationName="Order_OrderDetails"
                                                     Title="Order Details">
                    <xcdg:DataRelationDetailDescription.ItemProperties>
                       <xcdg:DataGridItemProperty Name="UnitPrice" />
                       <xcdg:DataGridItemProperty Name="Quantity" />
                       <xcdg:DataGridItemProperty Name="Discount" />
                    </xcdg:DataRelationDetailDescription.ItemProperties>
                    <xcdg:DataRelationDetailDescription.StatFunctions>
                       <xcdg:SumFunction ResultPropertyName="sum_quantity"
                                         SourcePropertyName="Quantity" />
                       <xcdg:AverageFunction ResultPropertyName="average_unitprice"
                                             SourcePropertyName="UnitPrice" />
                    </xcdg:DataRelationDetailDescription.StatFunctions>
                 </xcdg:DataRelationDetailDescription>
              </xcdg:DataRelationDetailDescription.DetailDescriptions>
           </xcdg:DataRelationDetailDescription>
        </xcdg:DataGridCollectionViewSource.DetailDescriptions>
     </xcdg:DataGridCollectionViewSource>
    </Grid.Resources>

    <xcdg:DataGridControl x:Name="EmployeesGrid"
                        ItemsSource="{Binding Source={StaticResource cvs_employees}}"
                        ItemsSourceName="Employee Information"
                        AutoCreateDetailConfigurations="True">
     <xcdg:DataGridControl.DefaultDetailConfiguration>
        <xcdg:DefaultDetailConfiguration>
           <xcdg:DefaultDetailConfiguration.Footers>
              <DataTemplate>
                 <xcdg:InsertionRow />
              </DataTemplate>
           </xcdg:DefaultDetailConfiguration.Footers>
        </xcdg:DefaultDetailConfiguration>
     </xcdg:DataGridControl.DefaultDetailConfiguration>
    </xcdg:DataGridControl>
    </Grid>


    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
  •  04-25-2008, 11:35 AM Post no. 11749 in reply to 11743

    Re: Linq Master Detail grid: Insert on Detail level

    Hi Jenny

    I found the error of my ways. I'm ashamed to admit it but my relation was just name incorrectly.

    Thanks for your help.

    Henry

  •  04-25-2008, 11:37 AM Post no. 11751 in reply to 11749

    Re: Linq Master Detail grid: Insert on Detail level

    Not a problem! It happens to all of us Smile
    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.