Solved

VB 2008  - Select a row of a DataGridView control

Posted on 2009-07-08
3
476 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
ID: 24808648
0
 
LVL 21

Accepted Solution

by:
Craig Wagner earned 500 total points
ID: 24808665
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
ID: 31601281
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

790 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