1

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.

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you :) can you please tell me how to add a button in DatGrid
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'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.