Hi

I am trying to count the rows that has been selected by the user - either with CTRL or SHIFT. The only property that i see is 'CurrentRowIndex' or 'Currentcell' but it only gives me the last selected row even though there are several rows selected. Other than that i am out of ideas and I have not been able to find anything on the web.

Thanks in advance.

Private Function ReturnNbrOfSelectedDataGridRows(ByVal dgSearchResults As DataGrid) As Integer
    Dim cm As CurrencyManager = DirectCast(Me.BindingContext(Me.dgSearchResults.DataSource, Me.dgSearchResults.DataMember), CurrencyManager)
    
    Dim dv As DataView = DirectCast(cm.List, DataView)
    
    Dim iRowCount As Integer = 0
    For i As Integer = 0 To dv.Count - 1
        
        If Me.dgSearchResults.IsSelected() Then
            iRowCount += 1
        End If
    Next
End Function

Hi,

I guess, you can use this :

MsgBox("Selected Rows : " & DataGridView1.SelectedRows.Count.ToString())

Regards
Veena

Thanks a lot; it is all I needed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.