2013-06-24 113 views
0

如何使它成爲我的代碼選擇數據網格視圖中他們單擊的行而不是將其硬編碼到代碼本身中,我想選擇用戶使用鼠標選擇的每一行表格。在Datagridview中選擇行

回答

2

你必須多選設置爲true你的DataGridView和你dataGridView.SelectionMode應該FullRowSelect

例子:

dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; 
dataGridView.MultiSelect = true; 

然後你就可以得到

Dim selectedItems As DataGridViewSelectedRowCollection = dataGridView.SelectedRows 
     For Each selectedItem As DataGridViewRow In selectedItems 
      'Add code to handle whatever you want for each row 
     Next 
End Sub 
選定行