2016-07-26 82 views
0

我想以編程方式選擇/突出顯示按鈕單擊的整列,以便讓用戶知道他們搜索的內容。DataGridView:以編程方式選擇/突出顯示按鈕單擊的整個列

This is what currently happens on button click ("GO" button)this是我需要發生的事情。

到目前爲止,我還嘗試了這些無濟於事: DataGridView2.SelectionMode = DataGridViewSelectionMode.FullColumnSelect DataGridView2.Columns(2).Selected = True

這樣做給了我這個錯誤:DataGridView control's SelectionMode cannot be set to FullColumnSelect while it has a column with SortMode set to DataGridViewColumnSortMode.Automatic.

我也試圖簡單地選擇整列。沒有錯誤,但沒有奏效。 DataGridView2.Columns(2).Selected = True

回答

0

找到了這個thread。我修改的代碼如下所示:

Dim row As DataGridViewRow 
For Each row In DataGridView2.Rows 
    row.Cells(1).Selected = True 
Next 

並把它放在裏面Private Sub Button1_Click

我注意到,第一小區被自動選擇。 This解決了這個問題。

0

只需設置列中每個單元格的Selected屬性即可。

+0

請你詳細說明我該怎麼做?謝謝.. – austin

+0

@austin遍歷每一行,將所需單元格的「Selected」屬性設置爲「True」。 – OhBeWise

+0

啊,好的。我改變了我用來搜索我的問題的答案的關鍵字..我終於找到了一些類似的線程。謝謝 – austin

相關問題