我设置了DataGridViewSelectionMode.FullRowSelect
模式,设置了MultiSelect=true
,我想当我选择一个row1,也触发另一个选择的row2时,通过工具CellClick
事件可以很好地工作,但是当我按下鼠标时单击(按住)任意一行,即使未处理CellMouseDown
事件,第2行也不被选择,是否可以按鼠标单击(按住)某行而不影响先前选择的行?谢谢!
这是我的代码:
private void _dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
GridColumns currRow = (GridColumns)_dataGridView.Rows[e.RowIndex].DataBoundItem;
string currRowUID = currRow.GetRowUID();
if (e.RowIndex + 1 < _dataGridView.RowCount)
{
GridColumns nextRow = (GridColumns)_dataGridView.Rows[e.RowIndex + 1].DataBoundItem;
string nextRowUID = nextRow.GetRowUID();
if (currRowUID == nextRowUID)
if (!_dataGridView.Rows[e.RowIndex + 1].Selected)
{
_dataGridView.Rows[e.RowIndex + 1].Selected = true;
_dataGridView.Refresh();
}
}
if (e.RowIndex - 1 > -1)
{
GridColumns nextRow = (GridColumns)_dataGridView.Rows[e.RowIndex - 1].DataBoundItem;
string nextRowUID = nextRow.GetRowUID();
if (currRowUID == nextRowUID)
if (!_dataGridView.Rows[e.RowIndex - 1].Selected)
{
_dataGridView.Rows[e.RowIndex - 1].Selected = true;
_dataGridView.Refresh();
}
}
}