Xceed Toolkit Plus for WPF v5.1 Documentation
Xceed.Wpf.DataGrid.Toolkit Assembly / Xceed.Wpf.DataGrid Namespace / Column Class
Members Example


In This Topic
    Column Class
    In This Topic
    Represents a column, which defines information on how the Cells it contains are displayed and their content edited.
    Syntax
    'Declaration
     
    <DebuggerDisplayAttribute("FieldName = {FieldName}")>
    <TypeDescriptionProviderAttribute(MS.Internal.ComponentModel.DependencyObjectProvider)>
    <NameScopePropertyAttribute("NameScope", System.Windows.NameScope)>
    Public Class Column 
       Inherits ColumnBase
    'Usage
     
    Dim instance As Column
    [DebuggerDisplay("FieldName = {FieldName}")]
    [TypeDescriptionProvider(MS.Internal.ComponentModel.DependencyObjectProvider)]
    [NameScopeProperty("NameScope", System.Windows.NameScope)]
    public class Column : ColumnBase 
    Remarks

    The VisiblePosition property represents the visible position of the column in a grid and may, or may not, correspond to the Index property. A column's visible position can be regarded as the position the column will take when it is visible. Changing a column's visibility will not affect its visible position, allowing the visibility of columns to be changed without them being reordered. To retrieve the effective visible position of a column, the IndexOf method of the VisibleColumns collection can be used.

    When fixing columns in a table-view layout, columns will be fixed in the order represented by their VisiblePosition properties. For example, if the FixedColumnCount property is set to 2, then the columns whose VisiblePosition properties are 0 and 1 will be fixed.

    If a grid contains hidden columns, they will be ignored. For example, if the second and third columns are hidden and a fixed-column count of 2 is provided, the first and fourth columns will be fixed but their visible positions will not be modified to reflect their new positions.

    Example

    All examples in this topic assume that the grid is bound to the Orders table of the Northwind database, unless stated otherwise.

    The following example demonstrates how to provide a custom sort comparer that sorts addresses. The AddressComparer class (provided below) will first sort addresses which begin with numeric values by street name and then civic number. Address that do not have a civic number will be sorted alphabetically.
    <Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"
          xmlns:local="clr-namespace:Xceed.Wpf.Documentation">
       <Grid.Resources>
          <local:AddressComparer x:Key="addressComparer"/>
          <xcdg:DataGridCollectionViewSource x:Key="cvs_orders"
                                             Source="{Binding Source={x:Static Application.Current},
                                                              Path=Orders}"
                                             AutoCreateItemProperties="False">
             <xcdg:DataGridCollectionViewSource.ItemProperties>
                <xcdg:DataGridItemProperty Name="ShipCountry" />
                <xcdg:DataGridItemProperty Name="ShipCity" />
                <xcdg:DataGridItemProperty Name="ShipAddress"
                                           SortComparer="{StaticResource addressComparer}"/>
                <xcdg:DataGridItemProperty Name="ShipVia" />
             </xcdg:DataGridCollectionViewSource.ItemProperties>
          </xcdg:DataGridCollectionViewSource>
       </Grid.Resources>
       <xcdg:DataGridControl x:Name="OrdersGrid"
                             ItemsSource="{Binding Source={StaticResource cvs_orders}}">         
          <xcdg:DataGridControl.View>
             <xcdg:TableView ColumnStretchMode="StretchAll"/>
          </xcdg:DataGridControl.View>
       </xcdg:DataGridControl>
    </Grid>
    The following code provides the implementation of the AddressComparer class.
    Imports System
    Imports System.Collections
    Imports System.Data
    Namespace Xceed.Wpf.Documentation
    
      Public Class AddressComparer
                   Implements IComparer
    
        Public Sub New()
        End Sub
        Public Function Compare( x As Object, y As Object ) As Integer Implements IComparer.Compare
          Dim stringX As String = CType( x, String )
          Dim stringY As String = Ctyle( y, String )
          Const digits As String = "0123456789"
          If( ( digits.IndexOf( stringX( 0 ) ) >= 0 ) And ( digits.IndexOf( stringY( 0 ) ) >= 0 ) ) Then
            Dim index As Integer = 0
            Dim xNumber As System.Text.StringBuilder = New System.Text.StringBuilder()
            While( ( index < stringX.Length ) And ( digits.IndexOf( stringX( index ) ) >= 0 ) )
              xNumber.Append( stringX( index ) )
              index++
            End While
            index = 0
            Dim yNumber As System.Text.StringBuilder = New System.Text.StringBuilder()
            While( ( index < stringY.Length ) And ( digits.IndexOf( stringY( index ) ) >= 0 ) )
              yNumber.Append( stringY( index ) )
              index++
            End While
            Dim xValue = Long.Parse( xNumber.ToString() )
            Dim yValue As Long = Long.Parse( yNumber.ToString() )
            If( xValue > yValue ) Then
              Return 1
            End If
            If( xValue < yValue ) Then
              Return -1
            End If
            Return stringX.CompareTo( stringY )
          Else
            Return stringX.CompareTo( stringY )
          End If
        End Function
      End Class
    End Namespace
    The following code provides the implementation of the AddressComparer class.
    using System;
    using System.Collections;
    using System.Data;
    namespace Xceed.Wpf.Documentation
    {
     public class AddressComparer: IComparer
     {
       public AddressComparer()
       {
       }
    
       int IComparer.Compare( object x, object y )
       {
         string stringX = ( string )x;
         string stringY = ( string )y;
    
         const string digits = "0123456789";
         if( ( digits.IndexOf( stringX[ 0 ] ) >= 0 ) && ( digits.IndexOf( stringY[ 0 ] ) >= 0 ) )
         {
           int index = 0;
           System.Text.StringBuilder xNumber = new System.Text.StringBuilder();
    
           while( ( index < stringX.Length ) && ( digits.IndexOf( stringX[ index ] ) >= 0 ) )
           {
             xNumber.Append( stringX[ index ] );
             index++;
           }
    
           index = 0;
           System.Text.StringBuilder yNumber = new System.Text.StringBuilder();
    
           while( ( index < stringY.Length ) && ( digits.IndexOf( stringY[ index ] ) >= 0 ) )
           {
             yNumber.Append( stringY[ index ] );
             index++;
           }
    
           long xValue = long.Parse( xNumber.ToString() );
           long yValue = long.Parse( yNumber.ToString() );
    
           if( xValue > yValue )
             return 1;
    
           if( xValue < yValue )
             return -1;
    
           return stringX.CompareTo( stringY );
         }
         else
         {
           return stringX.CompareTo( stringY );
         }
       }
     }
    }
    Inheritance Hierarchy

    System.Object
       System.Windows.Threading.DispatcherObject
          System.Windows.DependencyObject
             System.Windows.Freezable
                Xceed.Wpf.DataGrid.ColumnBase
                   Xceed.Wpf.DataGrid.Column

    Public Constructors
     NameDescription
    Public Constructor  
    Top
    Public Fields
     NameDescription
    Public Fieldstatic (Shared in Visual Basic)Identifies the ForeignKeyConfiguration dependency property.  
    Top
    Public Properties
     NameDescription
    Public Property

    Gets the actual width of the column considering the Width, MinWidth, and MaxWidth properties.

    (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyOverridden. Gets or sets a value indicating if the values in the column can be grouped.  
    Public PropertyOverridden. Gets or sets a value indicating if the values in the column can be sorted.  
    Public PropertyGets or sets a value indicating whether cells in the column can receive focus when the parent column's ReadOnly property is set to true. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public Property (Inherited from System.Windows.Freezable)
    Public Property (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets or sets the DataTemplate used to display the cells' content. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets or sets a DataTemplateSelector that provides a way to apply a different CellContentTemplate based on custom logic. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets or sets the CellEditor that contains the information required to display the template that will be used to edit the content of the cells contained in the column as well as the activation gestures that activate the template. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets or sets a value indicating under what conditions the editors for the cells contained in the column are displayed. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public Property (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets or sets the style that will be used by the cells contained in the column when their content fails the validation process. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets or sets a value representing the horizontal content alignment of cells contained in the column. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public Property (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets the list of CellValidationRules against which the content of the cells contained in the column are validated before they exist edit mode. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets or sets a value representing the vertical content alignment of cells contained in the column. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets the column's parent data-grid control. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public Property (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public Property (Inherited from System.Windows.DependencyObject)
    Public Property (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public Property (Inherited from System.Windows.Threading.DispatcherObject)
    Public Property (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public Property (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public Property (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets or sets the binding information between a column and its corresponding field in the underlying data source.  
    Public Property (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets or sets the case-sensitive field name that uniquely identifies the column in a grid's column collection. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets or sets a ForeignKeyConfiguration through which the visual representation of a foreign key description can be configured.  
    Public PropertyGets or sets the group configuration that will be applied to the groups that are created from the values of this column. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets or sets the group description that is used whenever groups are created according to the values of this column. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public Property (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets or sets the template that will be used by a group to display its value when the group is created according the values of the column. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets or sets a DataTemplateSelector that provides a way to apply a different GroupValueTemplates based on custom logic. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets a value indicating whether the column has a fixed width. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets a value indicating whether the content of one of the cells contained in the column failed the validation process. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets the index of the column in a grid's Column collection. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public Property  
    Public PropertyGets a value indicating whether the column is the first visible column in a grid's. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public Property (Inherited from System.Windows.Freezable)
    Public PropertyGets a value indicating whether the column is the last visible column in a grid. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets or sets a value indicating whether the column is a grid's main (primary) column. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public Property (Inherited from System.Windows.DependencyObject)
    Public PropertyGets or sets the maximum width of the column, in device-independent units (1/96th inch per unit). (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets or sets the minimum width of the column, in device-independent units (1/96th inch per unit). (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets or sets a value indicating whether an InsertionRow can be edited regardless of the value of the ReadOnly property. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets or sets a value indicating whether the content of the cells in the column can be edited. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets a value indicating the direction in which the values contained in the column are sorted. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public Property (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets the sort index of the column. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public Property

    Gets or sets a value that indicates the text trimming behavior to employ when textual content overflows the content area.

    (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets or sets a value indicating how textual content should be wrapped. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets or sets the data displayed in a column's corresponding ColumnManagerCell and/or GroupByItem. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets or sets the DataTemplate used to display the Title's content. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets or sets a DataTemplateSelector that provides a way to apply a different TitleTemplates based on custom logic. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets or sets a value indicating whether the column is visible. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets or sets the visible position of the column. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Public PropertyGets or sets the width of the column, in device-independent units (1/96th inch per unit). (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Top
    Public Methods
    Public Events
     NameDescription
    Public Event (Inherited from System.Windows.Freezable)
    Public EventRaised when the value of a property changes. (Inherited from Xceed.Wpf.DataGrid.ColumnBase)
    Top
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also

    Reference

    Column Members
    Xceed.Wpf.DataGrid Namespace

    DataGrid Fundamentals

    Column_Class.html