Home Forums WPF controls Xceed DataGrid for WPF How to bind values(Collection) to Master/Detail grid?

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

    Hi,

    I’m using Xceed WPF datagrid2.0.
    How can I Bind datas(using collection like List) to a Master/Detail view?

    If i bind using Itemssource, only master updated and I’m not able to bind the values to detail.

    Then How can i bind values(using collection) to Detail?

    PLEASE GIVE ME SOLUTION ASAP

    Imported from legacy forums. Posted by Anand (had 11099 views)

    Xceed Support
    Member
    Post count: 5658

    Master/Details is only available when the grid is bound to a DataGridCollectionView[Source] that in turn is bound to a data source that contains detail information. You will also need to set the grid’s AutoCreateDetailConfigurations property to true.

    That said, I suggest you look in the documentation at the Master/Detail topic to get an overview of how to use it as well as under the How-to|Master/Detail section for examples.

    Note that Master/Detail in only available in the Professional Edition of the grid.

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

    User (Old forums)
    Member
    Post count: 23064

    Hi Jenny,

    I’m not sure that you answered the basic question here: Can you create Master/Detail relationships for Object Datasources with nested collections.

    e.g. Class1 – CollectionAttribute (Class2)
    Class2 – CollectionAttribute(Class3)
    and so on…

    The documentation uses a dataset – table – relation…no mention of anything else.

    Imported from legacy forums. Posted by Koch (had 895 views)

    Xceed Support
    Member
    Post count: 5658

    By default, detail descriptions are automatically created for:

    o every DataRelation in a DataTable (DataRelationDetailDescription)
    o every object that implements the IEnumerable interface (EnumerableDetailDescription)
    o every property marked with the PropertyDetailAttribute attribute (PropertyDetailDescription)

    Detail descriptions can also be explicitly defined by adding them to DetailDescriptions collection of their parent DataGridCollectionView, DataGridCollectionViewSource, or detail description.

    Although the most common types of detail relations are automatically detected, it is also possible to create and use custom detail descriptions that will return detail items for a parent item, whatever the definition of the detail relation is.

    That said, if you control your data source, then I suggest you set the PropertyRelation attribute on the properties that expose the detail data.

    If you want even more control, you can derive from DataGridDetailDescription class and override GetDetailsForParentItem. For an example, take a look at the ” Creating a custom detail description” example in the Advanced Concepts\Custom Detail Descriptions topic.

    I hope this helps 🙂

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

    User (Old forums)
    Member
    Post count: 23064

    Hi Jenny,

    Re:

    1 – every DataRelation in a DataTable (DataRelationDetailDescription)
    2 – every object that implements the IEnumerable interface (EnumerableDetailDescription)
    3 – every property marked with the PropertyDetailAttribute attribute (PropertyDetailDescription)

    Setting the [Xceed.Wpf.DataGrid.PropertyRelation] attribute on Detail Properties worked ok once I figured out the correct syntax (not listed in the documentation) — it’s “PropertyRelation” not “PropertyRelationAttribute”.

    Also, in order to get this to work I had to set: AutoCreateDetailConfigurations=”True” and AllowDetailToggle=”True” in the XAML — setting these attributes in the Class did not work.

    However, objects that implement IEnumerable DO NOT automatically create a detail grid at least not in the same way as methods 1 & 3. I’ve set-up several test cases with different types of Enumerable Lists & Collections and none of them worked without at least setting the PropertyDetailAttribute. Perhaps I have misread or misunderstood the meaning of item #2.

    I assumed that item #2 meant that if a class (e.g. Team) with public property (e.g. IEnumerable TeamMembers) was bound to a datagrid control then the grid would display a list of Teams with a Detail grid of Team Members.

    If you could supply a simple sample of #2 I think it would help those of us who insist on binding to Object datasources

    😉 David

    Imported from legacy forums. Posted by Koch (had 1848 views)

    Xceed Support
    Member
    Post count: 5658

    Here is the clarification about point #2: The EnumerableDetailDescription will be automatically created if the data item itself implements IEnumerable, not the properties of the data items.

    I have sent a request to clarify the documentation on this mater.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 1152 views)

    User (Old forums)
    Member
    Post count: 23064

    In the example I gave above, both Team(BindingList) & TeamMember(BindingList) implement IEnumerable.

    Class Structure:

    Teams(IEnumerable-IBindingList)<Team>
    Team(IEditableObject).TeamMembers(IEnumerable-IBindingList) <TeamMember>

    I believe this structure conforms to what you describe, but it does not automatically create a relationship and display it in the grid…unless you mark the TeamMembers property as a Detail Attribute.

    Sorry to be stubborn about this, but I think it’s important. Specifically, I think it would be better from a design context if we didn’t have to mark-up attributes of an object data source that may exist up-stream from the UI in a different tier. This would involve creating a reference to Xceed.WPF.DataGrid and refactoring the whole library.

    If the grid works as described then no problem, but if it doesn’t then we have a problem when binding to prexisting Object Data Sources. I’m not the sharpest knife in the set, but I have spent quite a bit of time trying to get this to work as advertised. It would be helpful to know if you have set up an example and tested this particular bit of functionality.

    I can send you the code I used to test it if you wish.

    David 😛

    Imported from legacy forums. Posted by Koch (had 1476 views)

    Xceed Support
    Member
    Post count: 5658

    Yes, your code would be helpful in determining the issue.

    You can sent your application over at <a href=”mailto:support@xceedsoft.com”>support</a> giving this forum thread as a reference.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 1324 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,

    I’m trying to do something similar to what David discribes. The master/detail sample supplied is verry complexe and does’nt seam to correspond to my needs.

    If you could just send an simple exemple that show a 2 level master/detail datagrid which is bind to a datasource, without any templates or anything… it would help a lot. I’m not realy familiar whit WPF, I’m only evaluating your product and all the explanation above makes me confused.

    Like David, I set the ItemsSource property and the master level appeared automaticaly, but I dont see how to add the detail. I assumed that it would be automaticaly like the master, and like some other product I evaluated. The Object data source is used in many different views in my application, I cant add mark-up attributes in it.

    Here is the structure I want to put in master detail
    List <AssetClass> -> Master

    public sealed class AssetMixClass
    {
    #region Properties

    public List<AssetMixClass> AssetClasses ->Detail
    {
    get { return this.assetClasses; }
    }

    public List<PortfolioPosition> Positions ->Detail
    {
    get { return this.positions; }
    }

    I would like to show 2 details groups at the same level. Can you tell me if it’s possible?

    ex

    Asset Class A
    |
    —–Second level classes
    | |
    | ——–Asset Class B
    | |
    | ——–Asset Class C
    |
    —–Positions
    |
    ——–Position A

    Imported from legacy forums. Posted by Karine (had 2100 views)

    User (Old forums)
    Member
    Post count: 23064

    Here is a sample that uses the [Xceed.Wpf.DataGrid.PropertyRelation] attribute to identify relationships.

    The point of this thread is that it should work w/o this attribute being set. I think the xceed team is going to clarify this point shortly.

    Enjoy! 🙂

    XAML
    ————————————————————————

    <Page x:Class=”WPFBrowser.TestPage”
    xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221;
    xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml&#8221;
    Title=”Test Page”
    xmlns:my=”clr-namespace:Xceed.Wpf.DataGrid;assembly=Xceed.Wpf.DataGrid”
    xmlns:xcdg=”http://schemas.xceed.com/wpf/xaml/datagrid&#8221;
    xmlns:my1=”clr-namespace:Xceed.Wpf.DataGrid.ThemePack;assembly=Xceed.Wpf.DataGrid.ThemePack.1″>
    <Grid>
    <xcdg:DataGridControl
    Margin=”0,0,0,0″
    Name=”theGrid”
    Height=”500″
    Width=”Auto”
    AutoCreateDetailConfigurations=”True”
    AllowDetailToggle=”True”>
    <xcdg:DataGridControl.View>
    <xcdg:TableView>
    <xcdg:TableView.Theme>
    <my1:Office2007BlueTheme />
    </xcdg:TableView.Theme>
    </xcdg:TableView>
    </xcdg:DataGridControl.View>
    </xcdg:DataGridControl>
    </Grid>
    </Page>

    ————————————————————————
    C#
    ————————————————————————

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using Xceed.Wpf.DataGrid;
    using System.Collections.ObjectModel;

    namespace WPFBrowser
    {

    public partial class TestPage : Page
    {

    ObservableCollection<Team> Teams = new ObservableCollection<Team>();

    public TestPage()
    {
    InitializeComponent();
    this.Loaded += new RoutedEventHandler(TestPage_Loaded);
    }

    void TestPage_Loaded(object sender, RoutedEventArgs e)
    {
    BindTeam();
    }

    public void BindTeam()
    {

    LoadTeams();

    DataGridCollectionView theView = new DataGridCollectionView(Teams);

    //Bind to the Grid
    theGrid.ItemsSource = theView;
    theGrid.AutoCreateDetailConfigurations = true;
    theGrid.AllowDetailToggle = true;

    }

    void LoadTeams()
    {

    Team T = new Team(“Development”, “Software Development Team”);

    Person P = new Person(“David”, “Koch”);

    P.Foibles.Add(new Foible(“Appearance”, “Too good looking.”));
    P.Foibles.Add(new Foible(“Intelligence”, “Too smart for his own good.”));
    P.Foibles.Add(new Foible(“Miscellaneous”, “Eats bugs.”));

    T.People.Add(P);

    P = new Person(“Adam”, “Smith”);

    P.Foibles.Add(new Foible(“Accent”, “Doesn’t speak the Queen’s english real good.”));
    P.Foibles.Add(new Foible(“Appearance”, “Snappy Dresser…in the 80s”));

    T.People.Add(P);

    Teams.Add(T);

    T = new Team(“TT”, “IT Support”);

    P = new Person(“Steve”, “Jones”);

    P.Foibles.Add(new Foible(“Appearance”, “Err ummm…”));
    P.Foibles.Add(new Foible(“Miscellaneous”, “Mouth Breather”));

    T.People.Add(P);

    Teams.Add(T);

    }

    }

    public class Team
    {

    protected String _TeamName = “”;
    protected String _TeamDescription = “”;

    protected ObservableCollection<Person> _People = new ObservableCollection<Person>();

    public Team() { }

    public Team
    (
    String newTeamName,
    String newTeamDescription
    )
    {
    _TeamName = newTeamName;
    _TeamDescription = newTeamDescription;
    }

    public String TeamName { get { return _TeamName; } set { _TeamName = value; } }
    public String TeamDescription { get { return _TeamDescription; } set { _TeamDescription = value; } }

    [Xceed.Wpf.DataGrid.PropertyRelation]
    public ObservableCollection<Person> People { get { return _People; } set { _People = value; } }

    }

    public class Person
    {

    protected String _FirstName = “”;
    protected String _LastName = “”;

    protected ObservableCollection<Foible> _Foibles = new ObservableCollection<Foible>();

    public Person() { }

    public Person
    (
    String newFirstName,
    String newLastName
    )
    {
    _FirstName = newFirstName;
    _LastName = newLastName;
    }

    public String FirstName { get { return _FirstName; } set { _FirstName = value; } }
    public String LastName { get { return _LastName; } set { _LastName = value; } }

    [Xceed.Wpf.DataGrid.PropertyRelation]
    public ObservableCollection<Foible> Foibles { get { return _Foibles; } set { _Foibles = value; } }
    SD

    Imported from legacy forums. Posted by Koch (had 1631 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Koch,

    Looking through your code, there is no problem to automatically detect the EnumerableDetailDescription since, as I explained before, it will be detected and added automatically if the Data Item implements IEnumerable (in this case: Team ).

    As for the automatic detection of a property that implements IEnumerable, IBindingList, IList, and the like, this is not supported in version 2.0 but we are strongly considering it for a service release or an ulterior version.

    However, as you demonstrated in your code, you can have the DataGridControl automatically detect some properties, if they are marked with the PropertyRelation attribute.

    If modifying the data classes is not a valid solution for your scenario (which seems to be the case), you can add PropertyDetailDescriptions manually to the DetailDescriptions to display details for any property.

    <a href=”http://doc.xceedsoft.com/products/XceedWpfDataGrid/Detail_Descriptions.html”>Here is a link to the documentation topic on DetailDescriptions</a>. You can refer to example 1 ( Defining DetailDescriptions ) to determine how this can be done ( just replace DataRelationDetailDescription by PropertyDetailDescription ).

    @Karine: the above sample should also answer your needs.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 8298 views)

    User (Old forums)
    Member
    Post count: 23064

    Marcus.  I am just picking up on this Thread, as I am having the same issues as the original poster.  Namely, that child collections that do implement IEnumerable are not automatically generated a EnumerableDetailDescription.  Your last post seems to suggest that the parent item, in this case ‘Team’ should implement IEnumerable.  Surely this can not be correct.  Why would an entity implement IEnumerable?  This does make make sense, as surely the whole point of IEnumerable is allow the iteration over a collection of entities.  The only possible reason for an entity to implement IEnumerable would be to iterate over it’s properties.

     Surely it would make more sense for the Detail grid to based on a property that implements IEnumerable?

    I have been trying to get Master/Detail working for my collection classes, and have so far not been able to get it working.  I have tried using the Xceed.Wpf.DataGrid.PropertyRelation attribute to no avail, and have event tried using a custom DataGridDetailDescription.  I have found when debugging that the overload of GetDetailsForParentItem is not called.

    Surely it is more common for people to use collection classes the bind to a grid rather than Datasets, and yet getting it work with objects is not very satisfactory. 

     

    Imported from legacy forums. Posted by Steven (had 1546 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Steven.

        EnumerableDetailDescription is indeed only for entities that implement IEnumerable. This scenario, while not being amongst the most popular, is used by some people. This design is usually used in contexts such as:

       //custom CLR objects, not the system classes, relating to mechanical engineering assemblies and sub-assemblies
       Assembly assembly = this.GetAssembly( partNo );
      
       string assemblyName = assembly.Name;

        foreach( SubAssembly subAssembly in assembly )
        {
           …
        }

        For entities that have properties for child relations, the PropertyDetailDescription was created. By default, we will not automatically detect ANY child relations for properpties unless they are marked with the PropertyRelation attribute.

        Since you did add the PropertyRelation attribute, the problem must be lying somewhere else. Have you set the AutoCreateDetailConfigurations property on the DataGridControl? (false by default).

    Imported from legacy forums. Posted by Marcus [Xceed] (had 2120 views)

    User (Old forums)
    Member
    Post count: 23064

    SD,

    Thanks for the great example. I don’t know why these guys don’t come up withe something similar which has real practical use. Who the &*#* uses datasets for real applications? This was a big help in providing an example of adding collections to a master / detail grid.
     

    Cheers, 

    Glenn 

    Imported from legacy forums. Posted by Glenn (had 1755 views)

    User (Old forums)
    Member
    Post count: 23064

    I may be dim, but i just do not get it yet. I have an ObservableCollection that I am making a linq query from. I am setting this as the itemsource on the grid. (pseudocode)

    grid.ItemsSource = from x in DataSouce

                                 select { x.A, x.B, x.C}

    x.C is a list property. How do I get it to create the enumerabledetaildescription?

    I have the autocreatedetail blah blah on the grid.

    Imported from legacy forums. Posted by chris (had 2127 views)

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