|
发表于 2020-9-3 19:15:01
|
显示全部楼层
DataGridView 中可以这样做:
private int _selecting_index = 0;
private void dataGridView1_MouseMove(object sender, MouseEventArgs e)
{
DataGridView.HitTestInfo hti = this.dataGridView1.HitTest(e.X, e.Y);
//如果坐标在单元格内
if (hti.Type == DataGridViewHitTestType.Cell)
{
if (_selecting_index != hti.RowIndex)
{
// this.dataGridView1.Rows[_selecting_index].DefaultCellStyle.BackColor = Color.White;
this.dataGridView1.Rows[hti.RowIndex].Selected = true;
_selecting_index = hti.RowIndex;
}
}
}
其中
this.dataGridView1.MultiSelect = false;
this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; |
|