We help IT Professionals succeed at work.
Get Started

Datagridview - RowEnter

TSFLLC
TSFLLC asked
on
2,035 Views
Last Modified: 2012-05-12
I seem to keep fighting this irritating problem while navigating a datagridview.

One thing VB.NET does with datagridviews that to me is such a crock is that it always highlights the first row.
Why?  When you've got 4-5 datagridviews on a form, you load the form and you're sitting there looking at all of these selected rows...and for what?

So you have to unselect rows.
grdview.CurrentCell = grdview.Item(1, 0)
grdview.CurrentCell.Selected = False

I am trying to get a currentrow index on my datagridview whenever one of two things happens:
1)  User clicks a row.
2) User arrows up and down changing the rowindex.

The RowEnter property apparently fires prior to the row index changing.  I keep getting the first row based on unselecting the default row OnLoad.
I need the NEW row index.

What property do I have to use to capture the new row index whenever there is movement between rows?

Thanks.  Phil
Private Sub grdviewWebQueue_RowChg(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grdviewWebQueue.RowEnter
        If Activating Then Exit Sub
        If dvWebQueue.Count > 0 Then
            Dim msg As String = ""
            Dim index As Integer = grdviewWebQueue.CurrentRow.Index
            If (index = -1) Then
                OutofHere = True
                Exit Sub
            Else
                glQueueID = dvWebQueue(index)("pkid").ToString
            End If
        End If
    End Sub

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE