简体   繁体   中英

Selecting rows in Datagridview

我如何制作它,以便我的代码选择他们点击的数据网格视图中的行而不是硬编码到代码本身,我想选择用户在窗体上用鼠标选择的每一行。

You have to set multiselect to true for your DataGridView and your dataGridView.SelectionMode should be FullRowSelect

Example:

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

Then you can get the selected rows with

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM