Saturday, March 1, 2014

Datagrid in wpf + custom columns

In Linq

var query = from table in database.tablename
select table;

datagridName.itemsource = query

This Should give all the fields in the database

If you want to show all the tadabase field. this should do it. (Make sure AutoGenerateColumns = "ture" in xaml )

Customize what u want to show in the datagrid

In XAML

<DataGrid x:Name="datagridName"  AutoGenerateColumns="False">
                <DataGrid.Columns>
                    <DataGridTextColumn Width="100" Header="First Beautyful Name" Binding="{Binding Name}" />
                </DataGrid.Columns>
 </DataGrid>


//Note the AutoGenerateColumns = "False" in the DataGrid, This is going to allow us not to show all the filled in the database

// Binding in the DatagridTextColumn = "{Binding Name}" Name is the column name that in my table

No comments:

Post a Comment