如果你想選擇的行/向下多次拉昇,只要你想,你可以使用此代碼中移動:
最多:
if (dataGridView1.SelectedRows[0].Index != 0) {
for (int j = 0; j < this.dataGridView1.Columns.Count; j++) {
object tmp = this.dataGridView1[j, dataGridView1.SelectedRows[0].Index].Value;
this.dataGridView1[j, dataGridView1.SelectedRows[0].Index ].Value = this.dataGridView1[j, dataGridView1.SelectedRows[0].Index - 1].Value;
this.dataGridView1[j, dataGridView1.SelectedRows[0].Index - 1].Value = tmp;
}
int a = dataGridView1.SelectedRows[0].Index;
dataGridView1.ClearSelection();
this.dataGridView1.Rows[a - 1].Selected = true;
}
下:
if (dataGridView1.SelectedRows[0].Index != dataGridView1.Rows.Count - 2) {
for (int j = 0; j < this.dataGridView1.Columns.Count; j++) {
object tmp = this.dataGridView1[j, dataGridView1.SelectedRows[0].Index].Value;
this.dataGridView1[j, dataGridView1.SelectedRows[0].Index].Value = this.dataGridView1[j, dataGridView1.SelectedRows[0].Index + 1].Value;
this.dataGridView1[j, dataGridView1.SelectedRows[0].Index + 1].Value = tmp;
}
int i = dataGridView1.SelectedRows[0].Index;
dataGridView1.ClearSelection();
this.dataGridView1.Rows[i + 1].Selected = true;
}
jegan它不適用於我的情況。 – sanjeev 2013-04-26 12:25:03
什麼是不工作?你能更精確嗎? – Jegan 2013-04-26 13:34:33
實際上按照我的要求.... 如上圖所示..假設如果我選擇突出顯示的行,並且按向上鍵的那一行應該向上移動,並且它的上面一行應該會下移... 請問你能否幫我解決這個問題......它非常緊急...... – sanjeev 2013-04-26 14:19:06