DataControlBase.ItemsSource Property
Gets or sets the grid’s data source. This is a dependency property.
Namespace: DevExpress.Xpf.Grid
Assembly: DevExpress.Xpf.Grid.v19.2.Core.dll
Declaration
Property Value
Type | Description |
---|---|
Object | An object that represents the data source from which the grid retrieves its data. |
Remarks
The grid cannot operate without a data source. It can be bound to data from a database, from an XML file or to any data created at runtime. The grid can be bound to any object that implements the IEnumerable interface or its descendant (e.g. IList, ICollection). To bind a grid, you should assign a data source to the ItemsSource property. Note that the grid cannot be bound at design-time - only at runtime.
To learn more, see Binding to Data Overview.
Note
The GridControl.DataSource property is obsolete.
Example
This example demonstrates how to read data from an XML file and display it using the DXGrid control. If required, the changes made can be saved back to an XML file by clicking the button displayed below the grid.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-display-data-from-an-xml-file-e1506.
<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"
Height="292"
Width="533"
>
<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>
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the ItemsSource property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.