DataGridComboBoxColumn 類別

定義

表示將 DataGrid 控制項裝載於其儲存格內的 ComboBox 資料行。

public ref class DataGridComboBoxColumn : System::Windows::Controls::DataGridColumn
public class DataGridComboBoxColumn : System.Windows.Controls.DataGridColumn
type DataGridComboBoxColumn = class
    inherit DataGridColumn
Public Class DataGridComboBoxColumn
Inherits DataGridColumn
繼承

範例

下列範例示範如何使用 列舉值,填入資料行中每個 ComboBox 的下拉式清單。 下拉式清單中的選取專案會藉由將 SelectedItemBinding 屬性設定為每個資料列中所顯示物件的 屬性來系結。

<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
{
Class Window1
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;
}
Public Sub New()
    ' This call is required by the Windows Form Designer.
    InitializeComponent()
    ' Add any initialization after the InitializeComponent() call.

    'GetData() creates a collection of Customer data from a database
    Dim custdata As ObservableCollection(Of Customer) = GetData()

    'Bind the DataGrid to the customer data
    DG1.DataContext = custdata

End Sub
//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; }
}
'Defines the customer object
Public Class Customer
    Public Property FirstName() As String
    Public Property LastName() As String
    Public Property Email() As Uri
    Public Property IsMember() As Boolean
    Public Property Status() As OrderStatus
End Class
public enum OrderStatus { None, New, Processing, Shipped, Received };
Public Enum OrderStatus
    None
    [New]
    Processing
    Shipped
    Received
End Enum

備註

用來 DataGridComboBoxColumn 顯示有一組專案可供選擇的資料,例如列舉。 DataGridComboBoxColumn 允許使用者從下拉式清單中選取專案。 下圖顯示 DataGridComboBoxColumn

DataGridComboBoxColumn

若要填入下拉式清單,請先使用下列其中一個選項來設定 ItemsSource 的 屬性 ComboBox

ItemsSource設定 之後,將 中 ComboBox 選取的專案系結至資料格所在的資料列資料項目。 您可以使用下列其中一個屬性來設定系結:

屬性 描述
TextBinding 設定目前選取專案的文字系結路徑。
SelectedItemBinding 設定目前選取之物件的系結路徑。
SelectedValueBinding 將系結路徑設定為 屬性所 SelectedValuePath 指定之選取專案的值。

IsReadOnly當 屬性設定為 true 時,使用者無法編輯資料行,而且將無法看到下拉式清單。

如果您想要顯示其他類型的資料, DataGrid 請提供下列資料行類型:

資料行類型 資料顯示
DataGridHyperlinkColumn 用來顯示 URI 資料。
DataGridCheckBoxColumn 用來顯示布林資料。
DataGridTextColumn 使用 來顯示文字。

如果您想要在 中使用其他控制項 DataGrid ,您可以使用 來建立自己的資料行類型 DataGridTemplateColumn

建構函式

DataGridComboBoxColumn()

初始化 DataGridComboBoxColumn 類別的新執行個體。

欄位

DisplayMemberPathProperty

識別 DisplayMemberPath 相依性屬性。

EditingElementStyleProperty

識別 EditingElementStyle 相依性屬性。

ElementStyleProperty

識別 ElementStyle 相依性屬性。

ItemsSourceProperty

識別 ItemsSource 相依性屬性。

SelectedValuePathProperty

識別 SelectedValuePath 相依性屬性。

屬性

ActualWidth

取得資料行的目前寬度,以裝置獨立單位 (為單位,每單位 1/96 英吋) 。

(繼承來源 DataGridColumn)
CanUserReorder

取得或設定值,該值指出使用者是否可藉由拖曳欄標題來變更欄顯示位置。

(繼承來源 DataGridColumn)
CanUserResize

取得或設定值,這個值表示使用者是否可以使用滑鼠來調整資料行寬度。

(繼承來源 DataGridColumn)
CanUserSort

取得或設定值,該值指出使用者是否可藉由按一下欄標題來排序欄。

(繼承來源 DataGridColumn)
CellStyle

取得或設定用於呈現資料行中儲存格的樣式。

(繼承來源 DataGridColumn)
ClipboardContentBinding

取得或設定當取得或設定剪貼簿的儲存格內容時,要使用的繫結物件。

DataGridOwner

取得包含此資料行的 DataGrid 控制項。

(繼承來源 DataGridColumn)
DefaultEditingElementStyle

取得 EditingElementStyle 屬性的預設值。

DefaultElementStyle

取得 ElementStyle 的預設值。

DependencyObjectType

DependencyObjectType取得包裝這個實例之 CLR 型別的 。

(繼承來源 DependencyObject)
Dispatcher

取得與這個 Dispatcher 關聯的 DispatcherObject

(繼承來源 DispatcherObject)
DisplayIndex

取得或設定相對於 DataGrid 中之其他資料行的資料行位置。

(繼承來源 DataGridColumn)
DisplayMemberPath

取得或設定來源物件上某值的路徑,以提供物件的視覺表示方式。

DragIndicatorStyle

取得或設定在拖曳作業期間要套用至資料行標題的樣式物件。

(繼承來源 DataGridColumn)
EditingElementStyle

取得或設定樣式,當呈現資料行針對處於編輯模式之儲存格所顯示的項目時,會使用這個樣式。

ElementStyle

取得或設定樣式,當呈現資料行針對不處於編輯模式之儲存格所顯示的項目時,會使用這個樣式。

Header

取得或設定欄標題的內容。

(繼承來源 DataGridColumn)
HeaderStringFormat

取得或設定格式模式,以套用到欄標題的內容。

(繼承來源 DataGridColumn)
HeaderStyle

取得或設定呈現欄標題時所用的樣式。

(繼承來源 DataGridColumn)
HeaderTemplate

取得或設定範本,以定義欄標題的視覺表示方式。

(繼承來源 DataGridColumn)
HeaderTemplateSelector

取得或設定物件,以選取要用於欄標題的範本。

(繼承來源 DataGridColumn)
IsAutoGenerated

取得值,這個值會指出資料行是否自動產生。

(繼承來源 DataGridColumn)
IsFrozen

取得值,這個值會指出資料行是否會避免水平捲動。

(繼承來源 DataGridColumn)
IsReadOnly

取得或設定值,該值指出是否可編輯欄中的儲存格。

(繼承來源 DataGridColumn)
IsSealed

取得值,這個值表示此執行個體目前是否已密封 (唯讀)。

(繼承來源 DependencyObject)
ItemsSource

取得或設定用來產生下拉式方塊控制項內容的集合。

MaxWidth

取得或設定資料行的最大寬度條件約束。

(繼承來源 DataGridColumn)
MinWidth

取得或設定資料行的最小寬度條件約束。

(繼承來源 DataGridColumn)
SelectedItemBinding

取得或設定目前選取項目的繫結。

SelectedValueBinding

取得或設定所選取項目的值,這個值是藉由使用 SelectedValuePath 而取得。

SelectedValuePath

取得或設定路徑,這個路徑會用來從 SelectedValue 取得 SelectedItem

SortDirection

取得或設定欄的排序方向 (遞增或遞減)。

(繼承來源 DataGridColumn)
SortMemberPath

取得或設定屬性名稱或以句號分隔的屬性名稱階層,要當做排序依據成員。

(繼承來源 DataGridColumn)
TextBinding

針對 ComboBox 控制項的文字方塊部分,取得或設定其中文字的繫結。

TextBlockComboBoxStyleKey

取得要套用至唯讀下拉式方塊之樣式的資源索引鍵。

Visibility

取得或設定欄的可見性。

(繼承來源 DataGridColumn)
Width

取得或設定欄寬或自動調整模式。

(繼承來源 DataGridColumn)

方法

CancelCellEdit(FrameworkElement, Object)

造成正在編輯的資料行儲存格還原成指定的值。

CancelCellEdit(FrameworkElement, Object)

造成正在編輯的儲存格還原成原始、未編輯的值。

(繼承來源 DataGridColumn)
CheckAccess()

判斷呼叫的執行是否可以存取這個 DispatcherObject

(繼承來源 DispatcherObject)
ClearValue(DependencyProperty)

清除屬性的區域數值。 要清除的屬性是由 DependencyProperty 識別項所指定。

(繼承來源 DependencyObject)
ClearValue(DependencyPropertyKey)

清除唯讀屬性的區域數值。 要清除的屬性是由 DependencyPropertyKey 所指定。

(繼承來源 DependencyObject)
CoerceValue(DependencyProperty)

強制轉型所指定相依性屬性的值。 完成方式是叫用存在於呼叫 DependencyObject 之相依性屬性的屬性中繼資料中所指定的任何 CoerceValueCallback 函式。

(繼承來源 DependencyObject)
CommitCellEdit(FrameworkElement)

在結束編輯模式之前執行任何必要的驗證。

CommitCellEdit(FrameworkElement)

在結束儲存格編輯模式之前執行任何必要的驗證。

(繼承來源 DataGridColumn)
Equals(Object)

判斷提供的 DependencyObject 和目前的 DependencyObject 是否相等。

(繼承來源 DependencyObject)
GenerateEditingElement(DataGridCell, Object)

取得下拉式方塊控制項,這個控制項繫結至資料行的 SelectedItemBindingSelectedValueBindingTextBinding 值。

GenerateElement(DataGridCell, Object)

取得唯讀下拉式方塊控制項,這個控制項繫結至資料行的 SelectedItemBindingSelectedValueBindingTextBinding 值。

GetCellContent(DataGridRow)

針對位於這個資料行與所指定資料列交集處的儲存格,擷取該儲存格的 Content 屬性值。

(繼承來源 DataGridColumn)
GetCellContent(Object)

如果儲存格與這個資料行以及表示指定之資料項目的資料列相交,則取得該儲存格的 Content 屬性值。

(繼承來源 DataGridColumn)
GetHashCode()

取得這個 DependencyObject 的雜湊碼。

(繼承來源 DependencyObject)
GetLocalValueEnumerator()

建立特定的列舉值,以判斷哪些相依性屬性在此 DependencyObject 上具有本機設定的值。

(繼承來源 DependencyObject)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
GetValue(DependencyProperty)

傳回 DependencyObject 的這個執行個體上之相依性屬性的目前有效值。

(繼承來源 DependencyObject)
InvalidateProperty(DependencyProperty)

重新評估指定相依性屬性的有效值。

(繼承來源 DependencyObject)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
NotifyPropertyChanged(String)

通知包含此資料行的 DataGrid,資料行屬性已變更。

(繼承來源 DataGridColumn)
OnCoerceIsReadOnly(Boolean)

根據包含此資料行之 IsReadOnly 的屬性規則,判斷 DataGrid 屬性的值。

OnCopyingCellClipboardContent(Object)

引發 CopyingCellClipboardContent 事件。

(繼承來源 DataGridColumn)
OnPastingCellClipboardContent(Object, Object)

引發 PastingCellClipboardContent 事件。

(繼承來源 DataGridColumn)
OnPropertyChanged(DependencyPropertyChangedEventArgs)

每當這個 DependencyObject 上任何相依性屬性的有效值已更新時叫用。 已變更的特定相依性屬性會在事件資料中報告。

(繼承來源 DependencyObject)
OnSelectedItemBindingChanged(BindingBase, BindingBase)

DataGrid 屬性值變更時通知 SelectedItemBinding

OnSelectedValueBindingChanged(BindingBase, BindingBase)

DataGrid 屬性值變更時通知 SelectedValueBinding

OnTextBindingChanged(BindingBase, BindingBase)

DataGrid 屬性值變更時通知 TextBinding

PrepareCellForEdit(FrameworkElement, RoutedEventArgs)

在資料行中的儲存格進入編輯模式時呼叫。

ReadLocalValue(DependencyProperty)

傳回相依性屬性的區域值 (如果存在)。

(繼承來源 DependencyObject)
RefreshCellContent(FrameworkElement, String)

為了回應繫結變更而重新整理資料行中的儲存格內容。

SetCurrentValue(DependencyProperty, Object)

設定相依性屬性的值,而不需要變更其值來源。

(繼承來源 DependencyObject)
SetValue(DependencyProperty, Object)

設定相依性屬性的區域值 (由相依性屬性的識別碼所指定)。

(繼承來源 DependencyObject)
SetValue(DependencyPropertyKey, Object)

設定唯讀相依性屬性的區域數值 (由相依性屬性的 DependencyPropertyKey 識別項所指定)。

(繼承來源 DependencyObject)
ShouldSerializeProperty(DependencyProperty)

傳回值,這個值表示序列化程序是否應該序列化所提供相依性屬性的值。

(繼承來源 DependencyObject)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)
VerifyAccess()

請強制執行可以存取這個 DispatcherObject 的呼叫執行緒。

(繼承來源 DispatcherObject)

事件

CopyingCellClipboardContent

發生於準備好儲存格剪貼簿內容之後。

(繼承來源 DataGridColumn)
PastingCellClipboardContent

發生在將 [剪貼簿] 內容移至儲存格之前。

(繼承來源 DataGridColumn)

適用於