Genelia D'Souza
Genelia D'Souza

Reputation: 77

How to bind database data to Datagrid columns?

i am doing a silverlight project and i added a datagrid to it, i added AutoGenerateColumns="True" property and binded database table using DataGrid.ItemSource propertyin code behind , but it shows all the colums in the table , what i want is i want to disable headers in datagrid and make some colums and then bind the particular columns data to the database table colum, Please explain with XAML.

Upvotes: 1

Views: 545

Answers (1)

santosh singh
santosh singh

Reputation: 28662

For hiding datagrid header add follwoing property to datagrid

HeadersVisibility="None"

If you do not want to show all the items in datagrid then first set AutogenerateColumn property to false and then add following xaml i

 <my:DataGrid.Columns>
        <my:DataGridTextColumn Binding="{Binding Group}" Header="Group"></my:DataGridTextColumn>
        <my:DataGridTextColumn Binding="{Binding Name}" Header="Name"></my:DataGridTextColumn>
        <my:DataGridTextColumn Binding="{Binding Quantity}" Header="Quantity"></my:DataGridTextColumn>
    </my:DataGrid.Columns>

Update::How to add button

<my:DataGridTemplateColumn>
  <my:DataGridTemplateColumn.CellTemplate>
   <DataTemplate>
    <StackPanel>
     <Button x:Name="UpdateButton" Content="Update" 
        Click="UpdateButton_Click"></Button>
    </StackPanel>
   </DataTemplate>
  </my:DataGridTemplateColumn.CellTemplate>
 </my:DataGridTemplateColumn>

Upvotes: 2

Related Questions