This is a mirror of official site: http://jasper-net.blogspot.com/

Different type of Columns in Silverlight Data Grid

| Sunday, October 10, 2010
In the previous article I described how to bind Silverlight data grid with different data sources. In this article I will try to explain what different column types are supported in data grid and how to change binding of columns in code behind….

There are three types of columns in data grid.

DataGridTextColumn
DataGridCheckBoxColumn
DataGridTemplateColumn
DataGridTextColumn

DataGridTextColumn can be used to display plain text. This is the default column when AutoGenerateColumns is marked as True.It uses a TextBlock to display it’s data and Texbox to allowing editing of data.

<sdk:DataGrid AutoGenerateColumns="False" Name="dataGrid1"
   <sdk:DataGrid.Columns>
       <sdk:DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True"
         Width="Auto" Binding="{Binding ItemNumber}"
         Header="ItemNumber"/>
   </sdk:DataGrid.Columns>
</sdk:DataGrid>

The code above is doing a few things:

It creates the Columns collection using the <sdk:DataGrid.Columns> tag.
Inside that collection it creates a new DataGridTextColumn
The content that you see in the column header is set to "ItemNumber" using the Header property
The column is data bound to the ItemNumber property using the Binding property.
DataGridCheckBoxColumn

DataGridCheckBoxColumn is used to display the value of a Boolean property.It provides a read-only CheckBox for displaying a boolean or nullable boolean value, and a normal CheckBox to allow editing of that value.

<sdk:DataGrid AutoGenerateColumns="False" Name="dataGrid1"
   <sdk:DataGrid.Columns>
       <sdk:DataGridCheckBoxColumn Header="Available" Binding="{Binding IsAvailable}" />
   </sdk:DataGrid.Columns>
</sdk:DataGrid>

Read more: Beyond Relational

Posted via email from .NET Info

0 comments: