How to load DataTable into a DataGrid?

3

I have DataTable loaded with information in a WPF application.

I would like to get this DataTable and load it into a DataGrid . How can I do this the easy way?

DataGrid in XAML:

<Grid>
    <Button Content="Pedidos&#xD;&#xA;" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="91" Click="Button_Click" Height="27"/>
    <DataGrid Name="dataGrid" HorizontalAlignment="Left" Margin="10,42,0,0" VerticalAlignment="Top" Height="268" Width="558"/>
</Grid>
    
asked by anonymous 14.02.2015 / 23:23

1 answer

2

There are several ways to "populate" a DataGridView with a DataTable .

Here are two simple ways to do it.

Using a BindingSource :

BindingSource bs = new BindingSource();
bs.DataSource = seuDataTablePopulado;
datagrid.DataSource = bs;

"Playing" DataTable direct on the grid:

datagrid.DataSource = seuDataTable;

Between these two forms I'd rather use BindingSource for the filter options I have later.

    
17.02.2015 / 19:10