2011-12-19 35 views
7

所以我有幾個datagridviews,我們已經設置爲FullRowSelect。用戶現在要求能夠在單個單元上選擇複製功能。DataGridView CellSelect和FullRowSelect

我將DataGridView設置爲CellSelect,但是當我運行該應用程序時,當我單擊行標題時,它不會突出顯示整行,只顯示第一列。

我嘗試使用​​用CellMouseClick獲得選擇模式轉移,但爲了​​選擇它完全我有點擊行標題上多次。

private void DataGridView_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) 
{ 
    dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; 
} 

我怎麼能輕易或不那麼容易來回切換CellSelectFullRowSelect之間取決於他們對電網選擇?

回答

13

如果我理解你,你希望能夠選擇單個細胞也容易選擇一整行?

如果是這種情況,請將SelectionMode設置爲RowHeaderSelect

2
DataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; 

1-您實際上使用DataGridView結構,而不是您的對象DataGridView。

2-每當用戶點擊一行時,SelectionMode不應該被修改,而是在你的程序的Constructor中。

public MyForm() 
{ 
    dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; 
} 
+1

我正在使用該對象,它只是在示例中被稱爲DataGridView。爲了清晰起見,我將更改名稱。就選擇模式而言,它將根據用戶的需求而改變。他們可能會點擊一個單元格,因此它應該是CellSelect。如果他們點擊RowHeader,它將是FullRowSelect。 – Taryn 2011-12-19 20:41:08

-1

this.dataGridViewEmpList.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

0

添加這一行代碼。

this.dataGridView1.SelectionMode = isTrue == true ? DataGridViewSelectionMode.FullRowSelect : DataGridViewSelectionMode.RowHeaderSelect;