2014-12-27 171 views
0

在數據網格視圖(已填充)對象上嘗試此代碼,當我做出選擇時,我總是得到0個選定的行。Datagridview.selectedrows.count總是返回0?

Private Function IsThereASelection(ByVal e As DataGridView) As Boolean 
      If e.SelectedRows.Count <> 0 Then 
       MsgBox("You have selected " & e.SelectedRows.Count & " Rows.") 
       IsThereASelection = True 
    End If 
       MsgBox("You have selected " & e.SelectedRows.Count & " Rows.") 
       IsThereASelection = False 
End Function 

一些按鈕的代碼:

IsThereAselection(Window.DataGridView1) 

enter image description here

EDIT1:我已經改變了datagridrow對象選擇模式FullRowSelect但它不會仍然工作。編輯2:我在按鈕代碼中使用了錯誤的引用(如上所示)。正確的參考將是DataGridView1,這將回答我的問題。

+0

你確定你有'推選',而不僅僅是一個lagatagridcell'嗎? – User999999

+0

是的,朋友。每當我構建窗口時,我將鼠標指向選擇該行的小三角形並點擊它。 –

+0

然後,你需要提供更多的代碼,我很害怕。 – User999999

回答

0

將SelectionMode屬性設置爲「FullRowSelect」解決了我的問題。