Columns Property
See Also  Example
Xceed.Wpf.DataGrid Assembly > Xceed.Wpf.DataGrid Namespace > DataGridControl Class : Columns Property

Gets a list of the columns contained in the grid.

Syntax

Visual Basic (Declaration) 
Public ReadOnly Property Columns As ColumnCollection
C# 
public ColumnCollection Columns {get;}

Return Value

A reference to a ColumnCollection containing a list of the grid's columns. By default, a null reference (Nothing in Visual Basic).

Example

All examples in this topic assume that the grid is bound to the Orders or Employees table of the Northwind database, unless stated otherwise.
The following example demonstrates how to fix the ShipCountry and ShipCity columns.
XAMLCopy Code
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"> 
  <Grid.Resources> 
    <xcdg:DataGridCollectionViewSource x:Key="cvs_orders" 
                                    Source="{Binding Source={x:Static Application.Current}, 
                                                      Path=Orders}"/> 
  </Grid.Resources> 
   <xcdg:DataGridControl x:Name="OrdersGrid" 
                         ItemsSource="{Binding Source={StaticResource cvs_orders}}"> 
 
      <xcdg:DataGridControl.Columns> 
         <xcdg:Column FieldName="ShipCountry" VisiblePosition="0"/> 
         <xcdg:Column FieldName="ShipCity" VisiblePosition="1"/> 
      </xcdg:DataGridControl.Columns> 
      <xcdg:DataGridControl.View> 
 
        <xcdg:TableView FixedColumnCount="2"/> 
      </xcdg:DataGridControl.View> 
   </xcdg:DataGridControl> 
</Grid>
The following example demonstrates how to set routed view properties on detail configurations to change the width of their detail indicators as well as to fix columns and remove the fixed-column splitter.
XAMLCopy Code
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid" 
      xmlns:local="clr-namespace:Xceed.Wpf.Documentation"> 
  <Grid.Resources> 
     <xcdg:DataGridCollectionViewSource x:Key="cvs_employees" 
                                        Source="{Binding Source={x:Static Application.Current}, 
                                                    Path=Employees}" /> 
  </Grid.Resources> 
  <xcdg:DataGridControl x:Name="EmployeesGrid" 
                      ItemsSource="{Binding Source={StaticResource cvs_employees}}" 
                      AutoCreateDetailConfigurations="True"> 
     <xcdg:DataGridControl.Columns> 
        <xcdg:Column FieldName="Photo" 
                     Visible="False" /> 
     </xcdg:DataGridControl.Columns> 
     <xcdg:DataGridControl.DetailConfigurations> 
 
        <xcdg:DetailConfiguration RelationName="Employee_Orders" 
                                  Title="Employee Orders" 
                                  xcdg:TableView.DetailIndicatorWidth="50" 
                                  xcdg:TableView.FixedColumnCount="2"> 
           <xcdg:DetailConfiguration.Columns> 
              <xcdg:Column FieldName="EmployeeID" 
                           Visible="False" /> 
           </xcdg:DetailConfiguration.Columns> 
           <xcdg:DetailConfiguration.DetailConfigurations> 
              <xcdg:DetailConfiguration RelationName="Order_OrderDetails" 
                                        Title="Order Details" 
                                        xcdg:TableView.ShowFixedColumnSplitter="False" 
                                        xcdg:TableView.DetailIndicatorWidth="50"/> 
           </xcdg:DetailConfiguration.DetailConfigurations> 
        </xcdg:DetailConfiguration> 
     </xcdg:DataGridControl.DetailConfigurations> 
  </xcdg:DataGridControl> 
</Grid>

Remarks

All columns, regardless of their state, will be contained in the collection. To retrieve the columns that are only visible in the grid's viewport, consult the VisibleColumns property.

Requirements

Supported Frameworks: Microsoft .NET Framework version 3.5

See Also