我已經有了一個來自數據庫的一些單元格的gridview。用戶應該一次只能選擇1列的行。例如:創建一個gridview事件來選擇同一列中的某些元素
0 1 2
0 a b c
1 d e f
2 g h i
如果用戶拖動鼠標(同時按下左按鈕)從0/0 = a至1/1 = E 僅小區A和d應選擇。 (多列選擇不應該被允許)
如果有人能幫忙,
謝謝
這就是我得到了開頭:
private void myDataGridView1_MouseDown(object sender, MouseEventArgs e) {
var hti = dataGridView1.HitTest(e.X, e.Y);
coord[0] = hti.RowIndex;
coord[1] = hti.ColumnIndex;
}
private void dataGridView1_MouseUp(object sender, MouseEventArgs e)
{
var hti = dataGridView1.HitTest(e.X, e.Y);
coord[2] = hti.RowIndex;
coord[3] = hti.ColumnIndex;
// Some actions
}
這個例子還是選擇多列。
好的,你想選擇在同一行中的單元格。但是,您如何確定應選擇哪一列的哪一列。你使用什麼事件? – 2013-03-18 12:24:54
好吧,你的英語對我來說有點神祕,所以你想要什麼。即使用戶選擇了多列,也只選擇一列的元素。 – 2013-03-19 14:40:59
對不起,我的壞話,我有很多問題要說,但可以理解你。 但是,是的。如果用戶開始在列「A」中選擇,他不能選擇多列,只能選擇列「A」中的行。 – Weautus 2013-03-19 16:13:44