Home Forums WPF controls Xceed DataGrid for WPF Linq Master Detail grid: Insert on Detail level

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #26933 |

    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

     

    Imported from legacy forums. Posted by Henry (had 3131 views)

    Xceed Support
    Member
    Post count: 5658

    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.

     

    Imported from legacy forums. Posted by Jenny [Xceed] (had 3276 views)

    User (Old forums)
    Member
    Post count: 23064

    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

    Imported from legacy forums. Posted by Henry (had 817 views)

    Xceed Support
    Member
    Post count: 5658

    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.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 581 views)

    User (Old forums)
    Member
    Post count: 23064

    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.

    Imported from legacy forums. Posted by Henry (had 815 views)

    Xceed Support
    Member
    Post count: 5658

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

    Imported from legacy forums. Posted by Jenny [Xceed] (had 2541 views)

    User (Old forums)
    Member
    Post count: 23064

    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

    Imported from legacy forums. Posted by Henry (had 834 views)

    Xceed Support
    Member
    Post count: 5658

    Not a problem! It happens to all of us [:)]

    Imported from legacy forums. Posted by Jenny [Xceed] (had 1724 views)

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.