Amen Jlili
Amen Jlili

Reputation: 1944

Datagridview.selectedrows.count always returning 0?

Trying this code on a data grid view (Already populated) object, I always get 0 selected rows when ever I make a selection.

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

Some button code:

IsThereAselection(Window.DataGridView1)

enter image description here

Edit1: I've changed the datagridrow object selection mode to FullRowSelect but it doesn't work still. Edit2: I was using the wrong reference in the button code (shown above). The correct reference would be DataGridView1 and that would be answer my question.

Upvotes: 0

Views: 1652

Answers (1)

sgupta
sgupta

Reputation: 565

Setting SelectionMode property to "FullRowSelect" solved my problem.

Upvotes: 1

Related Questions