I'm a complete rookie. I learned so much from here but this one I can't find the answer to. I'm using Visual Studio Pro 2015.
I found this question, but the answer does not work for my application:
VB.Net - Is there any way to count the number of selected rows in a datagridview?
I have a windows form application that has a single column datagridview that is populated by reading a textfile, line by line at runtime.
I need to display (in a label) the number of rows that the user selects in the datagridview control.
I have this:
Private Sub DataGridView1_SelectionChanged(sender As Object, e As EventArgs) Handles DataGridView1.SelectionChanged
Dim selectedRowCount As Integer
selectedRowCount = DataGridView1.Rows.GetRowCount(DataGridViewElementStates.Selected)
lblNumSelected.Text = selectedRowCount.ToString()
End Sub
Or this:
Private Sub DataGridView1_SelectionChanged(sender As Object, e As EventArgs) Handles DataGridView1.SelectionChanged
lblNumSelected.Text = DataGridView1.SelectedRows.Count().ToString()
End Sub
Both of these methods return 0 (zero) no matter how many rows are selected. Thank you for helping me.
On your DataGridView
, set the .SelectionMode
property to FullRowSelect
, then use the .SelectedRows.Count
property.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments