问题描述
根据MSDN,MultiSelect选项允许用户使用Ctrl或Shift修饰符选择多行,但是我只能用鼠标左键选择多行,而无需按下任何控件修饰符。是否可以在不按Shift或Ctrl修饰符的情况下停止多项选择?
我正在使用Windows 10和Visual Studio 2019。
解决方法
也许您可以通过Mouse Event
禁用选择。
这是您可以参考的解决方法。
private void dataGridView1_MouseMove(object sender,MouseEventArgs e)
{
dataGridView1.ClearSelection();
dataGridView1.CurrentCell.Selected = true;
}
private void dataGridView1_MouseDown(object sender,MouseEventArgs e)
{
dataGridView1.MouseMove += dataGridView1_MouseMove;
}
private void dataGridView1_KeyDown(object sender,KeyEventArgs e)
{
if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
{
dataGridView1.MouseMove -= dataGridView1_MouseMove;
}
}
测试结果