2017-05-29 90 views
-1

一部の列を無効にして(DataGridCellにIsEnabled = falseスタイルを適用する)WPF Datagridを使用しているため、セルがグレー表示され、編集が許可されません。WPF Datagridで無効なセルの行選択を許可する

しかし、無効なセルをユーザーがクリックすると、完全な行選択を許可する必要があります。 これは可能ですか?あなたがDataGridRowためPreviewMouseLeftButtonDownイベントを処理することができ

+2

はい、それは可能です。 – Karolis

+0

@ mm8:はい、完璧に、ありがとうございます。 –

+1

@カロリス:ええ、本当に便利な答え... –

答えて

1

<DataGrid x:Name="dg" SelectionUnit="FullRow"> 
    <DataGrid.RowStyle> 
     <Style TargetType="DataGridRow"> 
      <EventSetter Event="PreviewMouseLeftButtonDown" Handler="dg_PreviewMouseLeftButtonDown" /> 
     </Style> 
    </DataGrid.RowStyle> 
    <DataGrid.Columns> 
     <DataGridTextColumn Binding="{Binding}" /> 
     <DataGridTextColumn Binding="{Binding}"> 
      <DataGridTextColumn.CellStyle> 
       <Style TargetType="DataGridCell"> 
        <Setter Property="IsEnabled" Value="False" /> 
       </Style> 
      </DataGridTextColumn.CellStyle> 
     </DataGridTextColumn> 
    </DataGrid.Columns> 
</DataGrid> 

private void dg_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) 
{ 
    DataGridRow row = sender as DataGridRow; 
    dg.SelectedItem = row.DataContext; 
} 
関連する問題