FlexGrid for WPF
選択モードを設定する
基本操作 > 選択 > 選択モードを設定する

C1FlexGrid は、SelectionMode プロパティで制御される豊富な選択モードを備えています。デフォルトの SelectionModeCellRange ですが、次の 5 つの選択モードを使用できます。

次は、各選択モードの実行例を示します。

[実行例] 単一セル、セル範囲の選択 (CellRange)

[実行例] 単一行の選択 (Row)

[実行例] 連続する複数行の選択 (RowRange)

[実行例] 行、複数行、連続しない複数行の選択 (ListBox)

コードのコピー
Private Sub selectMode_SelectionChanged(sender As Object, e As SelectionChangedEventArgs)
    Dim mode As C1.WPF.FlexGrid.SelectionMode = C1.WPF.FlexGrid.SelectionMode.Cell
    Select Case selectMode.SelectedIndex
        Case 0
            mode = C1.WPF.FlexGrid.SelectionMode.Cell
        Case 1
            mode = C1.WPF.FlexGrid.SelectionMode.CellRange
        Case 2
            mode = C1.WPF.FlexGrid.SelectionMode.Row
        Case 3
            mode = C1.WPF.FlexGrid.SelectionMode.RowRange
        Case 4
            mode = C1.WPF.FlexGrid.SelectionMode.ListBox
        Case Else
            mode = C1.WPF.FlexGrid.SelectionMode.Cell
    End Select
    Dim origionMode As C1.WPF.FlexGrid.ScaleMode = _flex.SelectionMode
    _flex.SelectionMode = mode
    If origionMode = C1.WPF.FlexGrid.SelectionMode.ListBox Then
        Dim selectedRows As List(Of C1.WPF.FlexGrid.Row) = _flex.Rows.Selected
        selectedRows.ForEach(AddressOf ChangeSelected)
    End If
End Sub

Shared Sub ChangeSelected(ByVal r As C1.WPF.FlexGrid.Row)
    r.Selected = False
End Sub
コードのコピー
private void selectMode_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    C1.WPF.FlexGrid.SelectionMode mode = C1.WPF.FlexGrid.SelectionMode.Cell;
    switch (selectMode.SelectedIndex)
    {
        case 0:
            mode = C1.WPF.FlexGrid.SelectionMode.Cell;
            break;
        case 1:
            mode = C1.WPF.FlexGrid.SelectionMode.CellRange;
            break;
        case 2:
            mode = C1.WPF.FlexGrid.SelectionMode.Row;
            break;
        case 3:
            mode = C1.WPF.FlexGrid.SelectionMode.RowRange;
            break;
        case 4:
            mode = C1.WPF.FlexGrid.SelectionMode.ListBox;
            break;
        default:
            mode = C1.WPF.FlexGrid.SelectionMode.Cell;
            break;
            
    }
    var origionMode = _flex.SelectionMode;
    _flex.SelectionMode = mode;
    if (origionMode == C1.WPF.FlexGrid.SelectionMode.ListBox)
    {
        var selectedRows = _flex.Rows.Selected;
        selectedRows.ForEach(r => r.Selected = false);
    }          
}