GridControl.DataSource Property

OBSOLETE

Instead use the ItemsSource property. For detailed information, see the list of breaking changes in DXperience v2011 vol 1.

Obsolete. Gets or sets the grid’s data source. This is a dependency property.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v21.1.dll

Declaration

[Obsolete("Instead use the ItemsSource property. For detailed information, see the list of breaking changes in DXperience v2011 vol 1.")]
[Browsable(false)]
[Bindable(true)]
public object DataSource { get; set; }

Property Value

Type Description
Object

An object that represents the data source from which the grid retrieves its data.

Remarks

Use the DataControlBase.ItemsSource property.

Example

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"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
        Title="Window1">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="30" />
        </Grid.RowDefinitions>

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

namespace DXGrid_BindingToXML {

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

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

}
See Also