Solved

VB 2008  - Select a row of a DataGridView control

Posted on 2009-07-08
3
473 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

770 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