DataGridComboBoxColumn Class

.NET Framework (current version)
 

Represents a DataGrid column that hosts ComboBox controls in its cells.

Namespace:   System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)

System.Object
  System.Windows.Threading.DispatcherObject
    System.Windows.DependencyObject
      System.Windows.Controls.DataGridColumn
        System.Windows.Controls.DataGridComboBoxColumn

public class DataGridComboBoxColumn : DataGridColumn

NameDescription
System_CAPS_pubmethodDataGridComboBoxColumn()

Initializes a new instance of the DataGridComboBoxColumn class.

NameDescription
System_CAPS_pubpropertyActualWidth

Gets the current width of the column, in device-independent units (1/96th inch per unit).(Inherited from DataGridColumn.)

System_CAPS_pubpropertyCanUserReorder

Gets or sets a value that indicates whether the user can change the column display position by dragging the column header.(Inherited from DataGridColumn.)

System_CAPS_pubpropertyCanUserResize

Gets or sets a value that indicates whether the user can adjust the column width by using the mouse.(Inherited from DataGridColumn.)

System_CAPS_pubpropertyCanUserSort

Gets or sets a value that indicates whether the user can sort the column by clicking the column header.(Inherited from DataGridColumn.)

System_CAPS_pubpropertyCellStyle

Gets or sets the style that is used to render cells in the column.(Inherited from DataGridColumn.)

System_CAPS_pubpropertyClipboardContentBinding

Gets or sets the binding object to use when getting or setting cell content for the clipboard.(Overrides DataGridColumn.ClipboardContentBinding.)

System_CAPS_protpropertyDataGridOwner

Gets the DataGrid control that contains this column.(Inherited from DataGridColumn.)

System_CAPS_pubpropertySystem_CAPS_staticDefaultEditingElementStyle

Gets the default value of the EditingElementStyle property.

System_CAPS_pubpropertySystem_CAPS_staticDefaultElementStyle

Gets the default value of the ElementStyle.

System_CAPS_pubpropertyDependencyObjectType

Gets the DependencyObjectType that wraps the CLR type of this instance. (Inherited from DependencyObject.)

System_CAPS_pubpropertyDispatcher

Gets the Dispatcher this DispatcherObject is associated with. (Inherited from DispatcherObject.)

System_CAPS_pubpropertyDisplayIndex

Gets or sets the display position of the column relative to the other columns in the DataGrid.(Inherited from DataGridColumn.)

System_CAPS_pubpropertyDisplayMemberPath

Gets or sets a path to a value on the source object to provide the visual representation of the object.

System_CAPS_pubpropertyDragIndicatorStyle

Gets or sets the style object to apply to the column header during a drag operation.(Inherited from DataGridColumn.)

System_CAPS_pubpropertyEditingElementStyle

Gets or sets the style that is used when rendering the element that the column displays for a cell in editing mode.

System_CAPS_pubpropertyElementStyle

Gets or sets the style that is used when rendering the element that the column displays for a cell that is not in editing mode.

System_CAPS_pubpropertyHeader

Gets or sets the content of the column header.(Inherited from DataGridColumn.)

System_CAPS_pubpropertyHeaderStringFormat

Gets or sets the format pattern to apply to the content of the column header.(Inherited from DataGridColumn.)

System_CAPS_pubpropertyHeaderStyle

Gets or sets the style that is used when rendering the column header.(Inherited from DataGridColumn.)

System_CAPS_pubpropertyHeaderTemplate

Gets or sets the template that defines the visual representation of the column header.(Inherited from DataGridColumn.)

System_CAPS_pubpropertyHeaderTemplateSelector

Gets or sets the object that selects which template to use for the column header.(Inherited from DataGridColumn.)

System_CAPS_pubpropertyIsAutoGenerated

Gets a value that indicates whether the column is auto-generated.(Inherited from DataGridColumn.)

System_CAPS_pubpropertyIsFrozen

Gets a value that indicates whether the column is prevented from scrolling horizontally.(Inherited from DataGridColumn.)

System_CAPS_pubpropertyIsReadOnly

Gets or sets a value that indicates whether cells in the column can be edited.(Inherited from DataGridColumn.)

System_CAPS_pubpropertyIsSealed

Gets a value that indicates whether this instance is currently sealed (read-only).(Inherited from DependencyObject.)

System_CAPS_pubpropertyItemsSource

Gets or sets a collection that is used to generate the content of the combo box control.

System_CAPS_pubpropertyMaxWidth

Gets or sets the maximum width constraint of the column.(Inherited from DataGridColumn.)

System_CAPS_pubpropertyMinWidth

Gets or sets the minimum width constraint of the column.(Inherited from DataGridColumn.)

System_CAPS_pubpropertySelectedItemBinding

Gets or sets the binding for the currently selected item.

System_CAPS_pubpropertySelectedValueBinding

Gets or sets the value of the selected item, obtained by using SelectedValuePath.

System_CAPS_pubpropertySelectedValuePath

Gets or sets the path that is used to get the SelectedValue from the SelectedItem.

System_CAPS_pubpropertySortDirection

Gets or sets the sort direction (ascending or descending) of the column.(Inherited from DataGridColumn.)

System_CAPS_pubpropertySortMemberPath

Gets or sets a property name, or a period-delimited hierarchy of property names, that indicates the member to sort by.(Inherited from DataGridColumn.)

System_CAPS_pubpropertyTextBinding

Gets or sets the binding for the text in the text box portion of the ComboBox control.

System_CAPS_pubpropertySystem_CAPS_staticTextBlockComboBoxStyleKey

Gets the resource key for the style to apply to a read-only combo box.

System_CAPS_pubpropertyVisibility

Gets or sets the visibility of the column.(Inherited from DataGridColumn.)

System_CAPS_pubpropertyWidth

Gets or sets the column width or automatic sizing mode.(Inherited from DataGridColumn.)

NameDescription
System_CAPS_protmethodCancelCellEdit(FrameworkElement, Object)

Causes the column cell being edited to revert to the specified value.(Overrides DataGridColumn.CancelCellEdit(FrameworkElement, Object).)

System_CAPS_pubmethodCheckAccess()

Determines whether the calling thread has access to this DispatcherObject.(Inherited from DispatcherObject.)

System_CAPS_pubmethodClearValue(DependencyProperty)

Clears the local value of a property. The property to be cleared is specified by a DependencyProperty identifier. (Inherited from DependencyObject.)

System_CAPS_pubmethodClearValue(DependencyPropertyKey)

Clears the local value of a read-only property. The property to be cleared is specified by a DependencyPropertyKey. (Inherited from DependencyObject.)

System_CAPS_pubmethodCoerceValue(DependencyProperty)

Coerces the value of the specified dependency property. This is accomplished by invoking any CoerceValueCallback function specified in property metadata for the dependency property as it exists on the calling DependencyObject.(Inherited from DependencyObject.)

System_CAPS_protmethodCommitCellEdit(FrameworkElement)

Performs any required validation before exiting the editing mode.(Overrides DataGridColumn.CommitCellEdit(FrameworkElement).)

System_CAPS_pubmethodEquals(Object)

Determines whether a provided DependencyObject is equivalent to the current DependencyObject.(Inherited from DependencyObject.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_protmethodGenerateEditingElement(DataGridCell, Object)

Gets a combo box control that is bound to the column's SelectedItemBinding, SelectedValueBinding, and TextBinding values.(Overrides DataGridColumn.GenerateEditingElement(DataGridCell, Object).)

System_CAPS_protmethodGenerateElement(DataGridCell, Object)

Gets a read-only combo box control that is bound to the column's SelectedItemBinding, SelectedValueBinding, and TextBinding values.(Overrides DataGridColumn.GenerateElement(DataGridCell, Object).)

System_CAPS_pubmethodGetCellContent(DataGridRow)

Retrieves the Content property value for the cell at the intersection of this column and the specified row.(Inherited from DataGridColumn.)

System_CAPS_pubmethodGetCellContent(Object)

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

System_CAPS_pubmethodGetHashCode()

Gets a hash code for this DependencyObject.(Inherited from DependencyObject.)

System_CAPS_pubmethodGetLocalValueEnumerator()

Creates a specialized enumerator for determining which dependency properties have locally set values on this DependencyObject. (Inherited from DependencyObject.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodGetValue(DependencyProperty)

Returns the current effective value of a dependency property on this instance of a DependencyObject. (Inherited from DependencyObject.)

System_CAPS_pubmethodInvalidateProperty(DependencyProperty)

Re-evaluates the effective value for the specified dependency property(Inherited from DependencyObject.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethodNotifyPropertyChanged(String)

Notifies the DataGrid that contains this column that a column property has changed.(Inherited from DataGridColumn.)

System_CAPS_protmethodOnCoerceIsReadOnly(Boolean)

Determines the value of the IsReadOnly property based on property rules from the DataGrid that contains this column.(Overrides DataGridColumn.OnCoerceIsReadOnly(Boolean).)

System_CAPS_pubmethodOnCopyingCellClipboardContent(Object)

Raises the CopyingCellClipboardContent event.(Inherited from DataGridColumn.)

System_CAPS_pubmethodOnPastingCellClipboardContent(Object, Object)

Raises the PastingCellClipboardContent event.(Inherited from DataGridColumn.)

System_CAPS_protmethodOnPropertyChanged(DependencyPropertyChangedEventArgs)

Invoked whenever the effective value of any dependency property on this DependencyObject has been updated. The specific dependency property that changed is reported in the event data. (Inherited from DependencyObject.)

System_CAPS_protmethodOnSelectedItemBindingChanged(BindingBase, BindingBase)

Notifies the DataGrid when the SelectedItemBinding property changes.

System_CAPS_protmethodOnSelectedValueBindingChanged(BindingBase, BindingBase)

Notifies the DataGrid when the SelectedValueBinding property changes.

System_CAPS_protmethodOnTextBindingChanged(BindingBase, BindingBase)

Notifies the DataGrid when the TextBinding property changes.

System_CAPS_protmethodPrepareCellForEdit(FrameworkElement, RoutedEventArgs)

Called when a cell in the column enters editing mode.(Overrides DataGridColumn.PrepareCellForEdit(FrameworkElement, RoutedEventArgs).)

System_CAPS_pubmethodReadLocalValue(DependencyProperty)

Returns the local value of a dependency property, if it exists. (Inherited from DependencyObject.)

System_CAPS_protmethodRefreshCellContent(FrameworkElement, String)

Refreshes the contents of a cell in the column in response to a binding change.(Overrides DataGridColumn.RefreshCellContent(FrameworkElement, String).)

System_CAPS_pubmethodSetCurrentValue(DependencyProperty, Object)

Sets the value of a dependency property without changing its value source. (Inherited from DependencyObject.)

System_CAPS_pubmethodSetValue(DependencyProperty, Object)

Sets the local value of a dependency property, specified by its dependency property identifier. (Inherited from DependencyObject.)

System_CAPS_pubmethodSetValue(DependencyPropertyKey, Object)

Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property. (Inherited from DependencyObject.)

System_CAPS_protmethodShouldSerializeProperty(DependencyProperty)

Returns a value that indicates whether serialization processes should serialize the value for the provided dependency property.(Inherited from DependencyObject.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

System_CAPS_pubmethodVerifyAccess()

Enforces that the calling thread has access to this DispatcherObject.(Inherited from DispatcherObject.)

NameDescription
System_CAPS_pubfieldSystem_CAPS_staticDisplayMemberPathProperty

Identifies the DisplayMemberPath dependency property.

System_CAPS_pubfieldSystem_CAPS_staticEditingElementStyleProperty

Identifies the EditingElementStyle dependency property.

System_CAPS_pubfieldSystem_CAPS_staticElementStyleProperty

Identifies the ElementStyle dependency property.

System_CAPS_pubfieldSystem_CAPS_staticItemsSourceProperty

Identifies the ItemsSource dependency property.

System_CAPS_pubfieldSystem_CAPS_staticSelectedValuePathProperty

Identifies the SelectedValuePath dependency property.

NameDescription
System_CAPS_pubeventCopyingCellClipboardContent

Occurs after the cell clipboard content is prepared.(Inherited from DataGridColumn.)

System_CAPS_pubeventPastingCellClipboardContent

Occurs before the clipboard content is moved to the cell.(Inherited from DataGridColumn.)

Use DataGridComboBoxColumn to display data where there is a set of items to choose from, such as an enumeration. DataGridComboBoxColumn allows users to select an item from a drop-down list. The following illustration shows a DataGridComboBoxColumn.

A DataGridComboBoxColumn

To populate the drop-down list, first set the ItemsSource property for the ComboBox by using one of the following options:

Once the ItemsSource is set, bind the selected item in the ComboBox to the data item for the row that the cell is in. You can set the binding by using one of the following properties:

Property

Description

TextBinding

Sets the binding path of the text for the currently selected item.

SelectedItemBinding

Sets the binding path of the object that is currently selected.

SelectedValueBinding

Sets the binding path to the value of the selected item specified by the SelectedValuePath property.

When the IsReadOnly property is set to true, users cannot edit the column and they will not be able to see the drop-down list.

If you want to display other types of data, DataGrid provides the following column types:

Column Type

Data Display

DataGridHyperlinkColumn

Use to display URI data.

DataGridCheckBoxColumn

Use to display Boolean data.

DataGridTextColumn

Use to display text.

If you want to use other controls in your DataGrid, you can create your own column types by using DataGridTemplateColumn.

The following example shows how to populate the drop-down list for each ComboBox in the column with the values of an enumeration. The selected item in the drop-down list is bound by setting the SelectedItemBinding property to the property of the object displayed in each row.

<NavigationWindow x:Class="DataGrid_CustomColumns.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:core="clr-namespace:System;assembly=mscorlib"
    xmlns:local="clr-namespace:DataGrid_CustomColumns"
    Title="Customers" Height="300" Width="300" ShowsNavigationUI="False"  >

<NavigationWindow.Resources>
    <!--Create list of enumeration values-->
    <ObjectDataProvider x:Key="myEnum" MethodName="GetValues" ObjectType="{x:Type core:Enum}">
        <ObjectDataProvider.MethodParameters>
            <x:Type Type="local:OrderStatus"/>
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>
    <!--Create an instance of the converter for Email-->
    <local:EmailConverter x:Key="EmailConverter" />
</NavigationWindow.Resources>
<NavigationWindow.Content>  

<Grid>
    <DataGrid Name="DG1" ItemsSource="{Binding}" AutoGenerateColumns="False" >
        <DataGrid.Columns>
                <DataGridComboBoxColumn Header="Order Status"  SelectedItemBinding="{Binding Status}" ItemsSource="{Binding Source={StaticResource myEnum}}" />
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
    </NavigationWindow.Content>
</NavigationWindow>
public partial class Window1 : NavigationWindow
{
public Window1()
{
    InitializeComponent();

    //GetData() creates a collection of Customer data from a database
    ObservableCollection<Customer> custdata = GetData();

    //Bind the DataGrid to the customer data
    DG1.DataContext = custdata;

}
//Defines the customer object
public class Customer
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public Uri Email { get; set; }
    public bool IsMember { get; set; }
    public OrderStatus Status { get; set; }

}
public enum OrderStatus { None, New, Processing, Shipped, Received };

.NET Framework
Available since 4.0

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: