?
Solved

VB 2008  - Select a row of a DataGridView control

Posted on 2009-07-08
3
Medium Priority
?
487 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 8

Expert Comment

by:Bob Hoffman
ID: 24808648
0
 
LVL 21

Accepted Solution

by:
Craig Wagner earned 2000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month11 days, 22 hours left to enroll

752 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