DataGridsを使用してWPFプロジェクトに取り組んでいます。ユーザーが必要な数の行を選択できるようにするか、単一のセルのみを選択できるようにします。つまり、セル範囲の選択を無効にします。しかし、私はそれをすることができませんでした。
これは可能ですか?
私は次のコードを試しました:
public MyDataGrid : DataGrid
{
public ExtendedDataGrid()
{
SelectionMode = DataGridSelectionMode.Extended;
SelectionUnit = DataGridSelectionUnit.CellOrRowHeader;
this.SelectedCellsChanged += new SelectedCellsChangedEventHandler(MyDataGrid_SelectedCellsChanged);
}
void MyDataGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
{
if (this.SelectedCells.Count > 1)
{
DataGridCellInfo currentCell = this.CurrentCell;
this.SelectedCells.Clear();
this.CurrentCell = currentCell;
}
}
しかし、このコードでは、行全体を選択することはできません。
それで、必要な数の行を選択するが、ユーザーがセル範囲を選択できないようにする方法はありますか?
前もって感謝します。