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

Can't i group data when using XELEMENT DATASOURCE?

3 Answers 13 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Zhang
Top achievements
Rank 1
Zhang asked on 27 Dec 2013, 02:03 AM
I use ObservableCollection<XElement> as ItemsSource. I found that the Group Panel does not accept selected column headers. Is there any possibilities that i can still use XElement as DataSource.

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 27 Dec 2013, 02:54 PM
Hi,

Please note that our data engine uses LINQ for all data operations. So for example, when you group on the Country column, something like this will be executed:
var results = customersCollection.GroupBy(customer => customer.Country);

You can bind directly to a collection of XElement however lots of  types will be unknown and you will not able to sort, filter and group.

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Zhang
Top achievements
Rank 1
answered on 31 Dec 2013, 02:10 AM
Finally i find a way to solve it and still use XElement, the way is to define a customized XElement Class like below:
    public class MyXElement : XElement
    {
        public MyXElement(XName name, object content) : base(name, content) { }
        public MyXElement(XName name, params object[] content) : base(name, content) 
        {
            ElementDic = new Dictionary<string, string>();
            foreach (XElement x in content) 
            {
                ElementDic.Add(x.Name.LocalName, x.Value);
            }
        }

        public Dictionary<string, string> ElementDic { get; set; }
    }

Populate data as below:
  List<MyXElement> myList = new List<MyXElement>();
            myList.Add(new MyXElement("Emp", new MyXElement("FirstName", "Maria"), new MyXElement("LastName", "Anders"), new MyXElement("IsMarried", true)));
            myList.Add(new MyXElement("Emp", new MyXElement("FirstName", "Ana"), new MyXElement("LastName", "Trujillo"), new MyXElement("IsMarried", true)));
            myList.Add(new MyXElement("Emp", new MyXElement("FirstName", "Antonio"), new MyXElement("LastName", "Moreno"), new MyXElement("IsMarried", true)));
            myList.Add(new MyXElement("Emp", new MyXElement("FirstName", "Thomas"), new MyXElement("LastName", "Hardy"), new MyXElement("IsMarried", false)));
            this.rgd1.ItemsSource = myList;

And bind it this way:
     <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=ElementDic[FirstName]}" Header="FirstName" UniqueName="FirstName" />

0
Dimitrina
Telerik team
answered on 31 Dec 2013, 09:57 AM
Hi,

Thank you for sharing your solution with the community.

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Zhang
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Zhang
Top achievements
Rank 1
Share this question
or