Show / Hide Table of Contents

Class DataGridColumn

Represents a DataGrid column.

Inheritance
System.Object
DependencyObject
DataGridColumn
DataGridBoundColumn
DataGridTemplateColumn
Inherited Members
DependencyObject.GetValue(DependencyProperty)
DependencyObject.SetCurrentValue(DependencyProperty, Object)
DependencyObject.ReadLocalValue(DependencyProperty)
DependencyObject.SetValue(DependencyProperty, Object)
DependencyObject.SetValue(DependencyPropertyKey, Object)
DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs)
DependencyObject.CoerceValue(DependencyProperty)
DependencyObject.Dispatcher
DependencyObject.INTERNAL_OnAttachedToVisualTree()
DependencyObject.INTERNAL_OnDetachedFromVisualTree()
DependencyObject.ClearValue(DependencyProperty)
DependencyObject.ClearValue(DependencyPropertyKey)
DependencyObject.CheckAccess()
DependencyObject.GetAnimationBaseValue(DependencyProperty)
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: System.Windows.Controls
Assembly: OpenSilver.Controls.Data.dll
Syntax
[StyleTypedProperty(Property = "CellStyle", StyleTargetType = typeof(DataGridCell))]
[StyleTypedProperty(Property = "DragIndicatorStyle", StyleTargetType = typeof(ContentControl))]
[StyleTypedProperty(Property = "HeaderStyle", StyleTargetType = typeof(DataGridColumnHeader))]
public abstract class DataGridColumn : DependencyObject, IDependencyObject

Constructors

| Improve this Doc View Source

DataGridColumn()

Initializes a new instance of the DataGridColumn class.

Declaration
protected DataGridColumn()

Properties

| Improve this Doc View Source

ActualWidth

Actual visible width after Width, MinWidth, and MaxWidth setting at the Column level and DataGrid level have been taken into account

Declaration
public double ActualWidth { get; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

CanUserReorder

Gets or sets a value that indicates whether the user can change the column display position by dragging the column header.

Declaration
public bool CanUserReorder { get; set; }
Property Value
Type Description
System.Boolean

true if the user can drag the column header to a new position; otherwise, false. The default is the current CanUserReorderColumns property value.

| Improve this Doc View Source

CanUserResize

Gets or sets a value that indicates whether the user can adjust the column width using the mouse.

Declaration
public bool CanUserResize { get; set; }
Property Value
Type Description
System.Boolean

true if the user can resize the column; false if the user cannot resize the column. The default is the current CanUserResizeColumns property value.

| Improve this Doc View Source

CanUserSort

Gets or sets a value that indicates whether the user can sort the column by clicking the column header.

Declaration
public bool CanUserSort { get; set; }
Property Value
Type Description
System.Boolean

true if the user can sort the column; false if the user cannot sort the column. The default is the current CanUserSortColumns property value.

| Improve this Doc View Source

CellStyle

Gets or sets the style that is used when rendering cells in the column.

Declaration
public Style CellStyle { get; set; }
Property Value
Type Description
Style

The style that is used when rendering cells in the column. The default is null.

| Improve this Doc View Source

ClipboardContentBinding

The binding that will be used to get or set cell content for the clipboard.

Declaration
public virtual Binding ClipboardContentBinding { get; set; }
Property Value
Type Description
Binding
| Improve this Doc View Source

DisplayIndex

Gets or sets the display position of the column relative to the other columns in the DataGrid.

Declaration
public int DisplayIndex { get; set; }
Property Value
Type Description
System.Int32

The zero-based position of the column as it is displayed in the associated DataGrid. The default is the index of the corresponding System.Collections.ObjectModel.Collection<T>.Item[System.Int32] in the Columns collection.

Exceptions
Type Condition
System.ArgumentOutOfRangeException

When setting this property, the specified value is less than -1 or equal to System.Int32.MaxValue.

-or-

When setting this property on a column in a DataGrid, the specified value is less than zero or greater than or equal to the number of columns in the DataGrid.

System.InvalidOperationException

When setting this property, the DataGrid is already making DisplayIndex adjustments. For example, this exception is thrown when you attempt to set DisplayIndex in a ColumnDisplayIndexChanged event handler.

-or-

When setting this property, the specified value would result in a frozen column being displayed in the range of unfrozen columns, or an unfrozen column being displayed in the range of frozen columns.

| Improve this Doc View Source

DragIndicatorStyle

Gets or sets the style that is used to render the column while it is being dragged.

Declaration
public Style DragIndicatorStyle { get; set; }
Property Value
Type Description
Style

The style applied while the column is being dragged.

| Improve this Doc View Source

Header

Gets or sets the content of the column header.

Declaration
public object Header { get; set; }
Property Value
Type Description
System.Object

The column header content. The default is null.

| Improve this Doc View Source

HeaderStyle

Gets or sets the style that is used when rendering the column header.

Declaration
public Style HeaderStyle { get; set; }
Property Value
Type Description
Style

The style that is used when rendering the column header, or null to use the ColumnHeaderStyle setting. The default is null.

| Improve this Doc View Source

IsAutoGenerated

Gets a value that indicates whether the column is auto-generated.

Declaration
public bool IsAutoGenerated { get; }
Property Value
Type Description
System.Boolean

true if the column is auto-generated; otherwise, false.

| Improve this Doc View Source

IsFrozen

Gets a value that indicates whether the column is prevented from scrolling horizontally.

Declaration
public bool IsFrozen { get; }
Property Value
Type Description
System.Boolean

true if the column cannot be scrolled horizontally; otherwise, false.

| Improve this Doc View Source

IsReadOnly

Gets or sets a value that indicates whether cells in the column can be edited.

Declaration
public bool IsReadOnly { get; set; }
Property Value
Type Description
System.Boolean

true if cells in the column cannot be edited; otherwise, false. The default is false.

Exceptions
Type Condition
System.InvalidOperationException

When setting this property to false on a column derived from DataGridBoundColumn, the column Binding property indicates a data source that is read-only.-or-When setting this property to true on a column with a cell that is in edit mode, the cell edit cannot be committed or reverted.

| Improve this Doc View Source

MaxWidth

Gets or sets the maximum column width in pixels.

Declaration
public double MaxWidth { get; set; }
Property Value
Type Description
System.Double

The maximum column width in pixels. The default is System.Double.PositiveInfinity.

Exceptions
Type Condition
System.ArgumentOutOfRangeException

When setting this property, the specified value is less than 0.-or-The specified value is less than the MinWidth.-or-The specified value is less than the MinColumnWidth and the MinWidth is not set.

| Improve this Doc View Source

MinWidth

Gets or sets the minimum column width in pixels.

Declaration
public double MinWidth { get; set; }
Property Value
Type Description
System.Double

The minimum column width in pixels, or 0 if the value is not set. The default is 0.

Exceptions
Type Condition
System.ArgumentOutOfRangeException

When setting this property, the specified value is less than 0.-or-The specified value is greater than the MaxWidth.-or-The specified value is greater than the MaxColumnWidth and the MaxWidth is not set.

System.ArgumentException

The specified value is System.Double.NaN.-or-The specified value is System.Double.PositiveInfinity.

| Improve this Doc View Source

SortMemberPath

Holds the name of the member to use for sorting, if not using the default.

Declaration
public string SortMemberPath { get; set; }
Property Value
Type Description
System.String
| Improve this Doc View Source

Visibility

Gets or sets the visibility of the column.

Declaration
public Visibility Visibility { get; set; }
Property Value
Type Description
Visibility

An enumeration value that specifies the column visibility. The default is Visible.

| Improve this Doc View Source

Width

Gets or sets the column width or an automatic sizing mode.

Declaration
public DataGridLength Width { get; set; }
Property Value
Type Description
DataGridLength

A structure that represents the column width or an automatic sizing mode. The default is the ColumnWidth property value.

Methods

| Improve this Doc View Source

CancelCellEdit(FrameworkElement, Object)

When overridden in a derived class, causes the column cell being edited to revert to the unedited value.

Declaration
protected virtual void CancelCellEdit(FrameworkElement editingElement, object uneditedValue)
Parameters
Type Name Description
FrameworkElement editingElement

The element that the column displays for a cell in editing mode.

System.Object uneditedValue

The previous, unedited value in the cell being edited.

| Improve this Doc View Source

GenerateEditingElement(DataGridCell, Object)

When overridden in a derived class, gets an editing element that is bound to the column's Binding property value.

Declaration
protected abstract FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem)
Parameters
Type Name Description
DataGridCell cell

The cell that will contain the generated element.

System.Object dataItem

The data item represented by the row that contains the intended cell.

Returns
Type Description
FrameworkElement

A new editing element that is bound to the column's Binding property value.

| Improve this Doc View Source

GenerateElement(DataGridCell, Object)

When overridden in a derived class, gets a read-only element that is bound to the column's Binding property value.

Declaration
protected abstract FrameworkElement GenerateElement(DataGridCell cell, object dataItem)
Parameters
Type Name Description
DataGridCell cell

The cell that will contain the generated element.

System.Object dataItem

The data item represented by the row that contains the intended cell.

Returns
Type Description
FrameworkElement

A new, read-only element that is bound to the column's Binding property value.

| Improve this Doc View Source

GetCellContent(Object)

Gets the Content property value for the cell at the intersection of this column and the row that represents the specified data item.

Declaration
public FrameworkElement GetCellContent(object dataItem)
Parameters
Type Name Description
System.Object dataItem

The data item represented by the row that contains the intended cell.

Returns
Type Description
FrameworkElement

The cell content. Returns null if the row containing dataItem is not found.

Exceptions
Type Condition
System.ArgumentNullException

dataItem is null.

System.InvalidOperationException

This column has not been added to a DataGrid.

| Improve this Doc View Source

GetCellContent(DataGridRow)

Gets the Content property value for the cell at the intersection of this column and the specified row.

Declaration
public FrameworkElement GetCellContent(DataGridRow dataGridRow)
Parameters
Type Name Description
DataGridRow dataGridRow

The row that contains the intended cell.

Returns
Type Description
FrameworkElement

The cell content.

Exceptions
Type Condition
System.ArgumentNullException

dataGridRow is null.

System.InvalidOperationException

This column has not been added to a DataGrid.

| Improve this Doc View Source

GetColumnContainingElement(FrameworkElement)

Returns the column which contains the given element

Declaration
public static DataGridColumn GetColumnContainingElement(FrameworkElement element)
Parameters
Type Name Description
FrameworkElement element

element contained in a column

Returns
Type Description
DataGridColumn

Column that contains the element, or null if not found

| Improve this Doc View Source

NotifyPropertyChanged(String)

Called by a specific column type when one of its properties changed, and its current cells need to be updated.

Declaration
protected void NotifyPropertyChanged(string propertyName)
Parameters
Type Name Description
System.String propertyName

Indicates which property changed and caused this call

| Improve this Doc View Source

PrepareCellForEdit(FrameworkElement, RoutedEventArgs)

When overridden in a derived class, called when a cell in the column enters editing mode.

Declaration
protected abstract object PrepareCellForEdit(FrameworkElement editingElement, RoutedEventArgs editingEventArgs)
Parameters
Type Name Description
FrameworkElement editingElement

The element that the column displays for a cell in editing mode.

RoutedEventArgs editingEventArgs

Information about the user gesture that is causing a cell to enter editing mode.

Returns
Type Description
System.Object

The unedited value.

| Improve this Doc View Source

RefreshCellContent(FrameworkElement, String)

Called by the DataGrid control when a column asked for its elements to be refreshed, typically because one of its properties changed.

Declaration
protected virtual void RefreshCellContent(FrameworkElement element, string propertyName)
Parameters
Type Name Description
FrameworkElement element

Indicates the element that needs to be refreshed

System.String propertyName

Indicates which property changed and caused this call

Extension Methods

DependencyObjectHelper.GetSelfAndAncestors(DependencyObject)
VisualTreeExtensions.GetVisualAncestors(DependencyObject)
VisualTreeExtensions.GetVisualAncestorsAndSelf(DependencyObject)
VisualTreeExtensions.GetVisualChildren(DependencyObject)
VisualTreeExtensions.GetVisualChildrenAndSelf(DependencyObject)
VisualTreeExtensions.GetVisualDescendants(DependencyObject)
VisualTreeExtensions.GetVisualDescendantsAndSelf(DependencyObject)
VisualTreeExtensions.GetVisualSiblings(DependencyObject)
VisualTreeExtensions.GetVisualSiblingsAndSelf(DependencyObject)
  • Improve this Doc
  • View Source