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.
Add a comment
|
1 Answer
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>
2 Comments
Genelia D'Souza
Thank you :) can you please tell me how to add a button in DatGrid
Genelia D'Souza
So by using TemplateColumn we can add any control to the data grid and TextColumn is used for Text or Binding Text ? and what is the difference between 'x:Name' and normal 'Name'