Winforms 在DataGridView中使用CurrentRow

Winforms 在DataGridView中使用CurrentRow,winforms,datagridview,Winforms,Datagridview,第一次加载表单时,是否有方法将DataGridView中的CurrentRow设置为null?我想这样做,以便我的BindingSource上的CurrentChanged事件不会触发 为了澄清这一点,在最初加载表单时,我不希望在DataGridView中选择任何行。我希望BindingSource.CurrentChanged仅在用户选择行时激发。CurrentRow为只读 我认为您应该将CurrentCell设置为null。为什么不设置e.Cancel=true如果要取消它?您可以使用thi

第一次加载
表单时,是否有方法将
DataGridView
中的
CurrentRow
设置为
null
?我想这样做,以便我的
BindingSource
上的
CurrentChanged
事件不会触发


为了澄清这一点,在最初加载
表单时,我不希望在
DataGridView
中选择任何行。我希望
BindingSource.CurrentChanged
仅在用户选择行时激发。

CurrentRow为只读

我认为您应该将CurrentCell设置为null。

为什么不设置
e.Cancel=true
如果要取消它?

您可以使用
this.dataGridView1.ClearSelection()清除行选择方法。我不知道这是不是和你一起工作的场景

试试看

               foreach(DataGridViewCell Cell datagridview1.SelectedCells)
              {
                      Cell.Seleted=false;
              }
我希望这能解决你的问题