Skip to main content

How to: Bind a Grid to an XML File

  • 2 minutes to read

This example demonstrates how to display data from an XML file with the GridControl. Follow these steps:

  • Load data from the file to the client application in any way you prefer.
  • Bind the grid’s ItemsSource property to the collection.

In this example, a DataTable object is used to load data from an XML file.

This example demonstrates how to read data from an XML file and display it using the GridControl. If required, the changes made can be saved back to an XML file by clicking the button displayed below the grid.

View Example

<Window x:Class="DXGrid_BindingToXML.Window1"
            <RowDefinition />
            <RowDefinition Height="30" />

                <dxg:GridColumn FieldName="FirstName" />
                <dxg:GridColumn FieldName="LastName" />
                <dxg:GridColumn FieldName="Company" />
                <dxg:GridColumn FieldName="City" />
                <dxg:TableView AutoWidth="True" />
        <Button Margin="5" Grid.Row="1" Click="Button_Click" 
                VerticalAlignment="Bottom" HorizontalAlignment="Left" 
                Content="Post Data to an XML File"/>
using System.Windows;
using System.Data;

namespace DXGrid_BindingToXML {

    public partial class Window1 : Window {
        static string path = @"..\..\Contacts.xml";
        public Window1() {
            grid.ItemsSource = GetDataFromXML();
        private DataTable GetDataFromXML() {
            DataSet ds = new DataSet();
            return ds.Tables[0];
        private void PostDataToXML() {

        private void Button_Click(object sender, RoutedEventArgs e) {
            MessageBox.Show("Changes have been successfully saved to an XML file.", "Info");