Welcome to the Xceed Community | Help
Community Search  

Grouping and sorting XML data

Sort Posts: Previous Next
  •  02-01-2008, 11:57 AM Post no. 10724

    Grouping and sorting XML data

    For those of you who wanted to group and sort xml data, here are 2 classes that will allow you to do it:

    XmlPropertyDescriptor.cs: returns the typed value through its GetValue implementaion, which will allow the items to be sorted and grouped correctly.

    XmlDataGridItemProperty.cs : creates the XmlPropertyDescriptor in its constructor.

    How to use the classes

    <Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid">
       <Grid.Resources>
          <XmlDataProvider x:Key="xmlData"
                                    Source="Data\Northwind.xml"
                                    XPath="dataroot/Orders" />

           <xcdg:DataGridCollectionViewSource x:Key="cvs_xml" Source="{Binding Source={StaticResource xmlData}}">
               <xcdg:DataGridCollectionViewSource.ItemProperties>
                  <local:XmlDataGridItemProperty Name="ShipCountry" DataType="{x:Type s:String}" Title="Ship Country"/>
                  <local:XmlDataGridItemProperty Name="Freight" DataType="{x:Type s:Double}"/>
                  <local:XmlDataGridItemProperty Name="OrderDate" DataType="{x:Type s:DateTime}" />
               </xcdg:DataGridCollectionViewSource.ItemProperties>
          </xcdg:DataGridCollectionViewSource>
        </Grid.Resources>


        <xcdg:DataGridControl x:Name="XmlGrid" ItemsSource="{Binding Source={StaticResource cvs_xml}}"/>
    </Grid>

    You will need to rename the file extensions from .txt back to .cs.

    Those of you who are using .NET 3.5, you can also use LINQ to handle your XML data.

    Hope this solves some of the issues a couple of you were having :)


    Technical Writer - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
    Filed under:
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.