能够 select 一行但不应该 select DataGridView 中该行的最后一列

Able to select a row but shouldn't select the last column in that row in a DataGridView

我有大约 5 列的 DataGridView,最后一列是 DataGridViewLinkColumn 类型。所以这里的要求是我应该能够 select 我想要的任何行,当我这样做时,除了该 selected 行的最后一列外,所有列都应该 selected .由于最后一列包含超链接文本,并且编写了一些旨在 运行.

的函数

目前我已经将 selection 模式设置为 FullRowSelect

为了达到要求,我尝试将模式设置为 CellSelect,在 CellContentClick 中我设置了 'Selected' 属性 用于 selected 行的特定列。但是 selection 并没有正常发生。我一点击它就会消失。我也尝试将相同的逻辑放入 CellMouseUp,但它也没有用。

请建议我实现要求的方法或解决方法。

非常感谢!

首先将SelectionMode设置为CellSelect。然后编码 SelectionChanged 事件:

private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
    foreach (DataGridViewCell c in dataGridView1.CurrentRow.Cells)
            c.Selected = c.ColumnIndex != 4;
}

请注意,这没有取消选择行的规定!