110,502
社区成员
发帖
与我相关
我的任务
分享
DataGridViewRow row = null;
private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.ColumnIndex == -1 && e.RowIndex != -1)
{
row = ((DataGridView)sender).Rows[e.RowIndex];
}
}
private void dataGridView1_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.ColumnIndex == -1 && e.RowIndex != -1 && row != null && row.Index != e.RowIndex)
{
bool down = (e.RowIndex > row.Index + 1);
((DataGridView)sender).Rows.Remove(row);
((DataGridView)sender).Rows.Insert(((down) ? e.RowIndex - 1 : e.RowIndex), row);
((DataGridView)sender).CurrentCell = ((DataGridView)sender)[0, (down) ? e.RowIndex - 1 : e.RowIndex];
row = null;
}
}