Partager via


DataGrid.SelectionMode Property

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

Gets or sets the selection behavior of the data grid.

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

Syntax

'Declaration
Public Property SelectionMode As DataGridSelectionMode
public DataGridSelectionMode SelectionMode { get; set; }
<sdk:DataGrid SelectionMode="dataGridSelectionModeValue"/>

XAML Values

  • dataGridSelectionModeValue
    A named constant of the DataGridSelectionMode enumeration, such as Extended.

Property Value

Type: System.Windows.Controls.DataGridSelectionMode
One of the enumeration values specifying the selection behavior. The default is Extended.

Remarks

Dependency property identifier field: SelectionModeProperty

Set the SelectionMode to specify whether users can select multiple rows or only a single row at a time.

Examples

The following code example demonstrates how to set the SelectionMode property in code. 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.

See Also

Reference

Other Resources