Freigeben über


DataGridSelectionMode Enumeration

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Specifies constants that define the DataGrid selection modes.

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

Syntax

'Declaration
Public Enumeration DataGridSelectionMode
public enum DataGridSelectionMode
<object property="enumMemberName"/>

Members

Member name Description
Extended The user can select multiple items while holding down the SHIFT or CTRL keys.
Single The user can select only one item at a time.

Remarks

This enumeration is used by the DataGrid.SelectionMode property. You can programmatically allow single or multiple row selection by setting the DataGrid.SelectionMode property.

Examples

The following code example demonstrates how to use the DataGridSelectionMode enumeration. This example is part of a larger example available in the Walkthrough: Customizing the DataGrid Control Using Properties topic.

Private Sub cbSelectionMode_Changed(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
    Dim cb As CheckBox = sender
    If Me.dataGrid1 IsNot Nothing Then
        If cb.IsChecked = True Then
            Me.dataGrid1.SelectionMode = DataGridSelectionMode.Single
        ElseIf cb.IsChecked = False Then
            Me.dataGrid1.SelectionMode = DataGridSelectionMode.Extended
        End If
    End If
End Sub
private void cbSelectionMode_Changed(object sender, RoutedEventArgs e)
{
    CheckBox cb = sender as CheckBox;
    if (this.dataGrid1 != null)
    {
        if (cb.IsChecked == true)
            this.dataGrid1.SelectionMode = DataGridSelectionMode.Single;
        else if (cb.IsChecked == false)
            this.dataGrid1.SelectionMode = DataGridSelectionMode.Extended;
    }
}

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.