首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WPF DataGrid:禁用对多列的选择

WPF DataGrid:禁用对多列的选择
EN

Stack Overflow用户
提问于 2013-03-08 18:54:06
回答 1查看 141关注 0票数 0

我试图通过连接到数据网格的SelectedCellsChanged事件来阻止用户在多个列上进行单元格选择。

但是,由于某些原因,我的代码行为有点奇怪。

下面是我的代码:

代码语言:javascript
复制
private void chartDataGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
{
    foreach (DataGridCellInfo cell in e.AddedCells)
    {
        // If a selected cell is within a different column than the first selected cell, undo the selection (to prevent selections from crossing multiple columns)
        if (cell.Column != e.AddedCells[0].Column)
                    this.chartDataGrid.SelectedCells.Remove(cell);
    }
}

有人能告诉我我错过了什么吗?

EN

回答 1

Stack Overflow用户

发布于 2013-03-08 19:08:23

好吧,我摆脱了这个行为,但偶然发现了新代码的另一个问题,看起来是这样的:

代码语言:javascript
复制
private void chartDataGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
{
    foreach (DataGridCellInfo cell in e.AddedCells)
    {
        // If a selected cell is within a different column than the first selected cell, undo the selection (to prevent selections from crossing multiple columns)
        if (cell.Column != this.chartDataGrid.SelectedCell[0].Column)
            this.chartDataGrid.SelectedCells.Remove(cell);
    }
}

现在我不能将我的选择扩展到右侧的列(这很好),但我仍然可以扩展到左侧。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15292315

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档