Solved

VB 2008  - Select a row of a DataGridView control

Posted on 2009-07-08
3
469 Views
Last Modified: 2012-05-07
I'm having a problem making a selection "stick" in this bound DataGridView control.

I am able to bring up the code shown below by clicking on the RowHeader of a given row.  If I click on the (say) 3rd row the RowIndex is shown at 2 (correct, so far.)  However, at that point the thing gets lost.  

The second message box shows the value of Cells(8) for the first row (RowIndex 0).  Moreover the cursor also jumps to the first row and stays there.  I will also mention that it jumps to the 3rd cell.

If I click on any other RowHeader I also get the same value for Cells(8) from the first row.  Also the cursor jumps to the first row (RowIndex 0) but in a different cell.  Who knows why?  I don't.  Perhaps you have a better solution.
Private Sub EvalItemsDataGridView_RowHeaderMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles EvalItemsDataGridView.RowHeaderMouseClick

        MsgBox(e.RowIndex)

        Me.EvalItemsDataGridView.CurrentCell = Me.EvalItemsDataGridView(e.RowIndex, 0)

        Dim i As Long = (EvalItemsDataGridView.CurrentRow.Cells(8).Value())

        MsgBox(i)

    End Sub

Open in new window

0
Comment
Question by:ljcor
3 Comments
 
LVL 8

Expert Comment

by:Bob Hoffman
Comment Utility
0
 
LVL 21

Accepted Solution

by:
Craig Wagner earned 500 total points
Comment Utility
You've got the row and column indexes backwards here:

Me.EvalItemsDataGridView(e.RowIndex, 0)

The column index comes first. It should be:

Me.EvalItemsDataGridView(0, e.RowIndex)
0
 

Author Closing Comment

by:ljcor
Comment Utility
Sorry I didn't get back to you earlier.  Had to be out for awhile. I thank both of you for your assistance, particularly Craig, who hit the right nail precisely on the head.  
Jack
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now