Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello, I am having a problem pulling data from a row Double-clicked in a vb data grid. What I want to do is double-click the row, put the first column's contents in one text box, the second column's contents in a second text box. Unfortunately the row index I am getting back is always -1.

 

I have tried:

 

Dim pt = New Point(e.X, e.Y)

Dim hit As DataGrid.HitTestInfo = Me.dgExtract.HitTest(pt)

rowIndex = hit.Row

 

But in debug mode, when I hover the mouse over rowIndex, it is alway -1.

 

I have tried this:

 

Dim rowIndex As Integer

rowIndex = Me.dgExtract.CurrentRowIndex

 

Me.txt_BatchNumber.Text = Me.dgExtract.Item(rowIndex, 0).ToString

Me.txt_StoreID.Text = Me.dgExtract.Item(rowIndex, 1).ToString

 

Again, the rowIndex is -1, if I let it go, it errors out on me when it tries to assign the value.

 

I found the above code in this forum. It seems logical, am I missing something simple ?

 

lauriemc :confused:

Posted

This stuff may or may not help you. I havent tested it out myself. Sorry if it doesnt. Also, do you mean datagrid control or datagridview control? This stuff is for datagridview controls (sorry never used datagrid control)..

 

1. I thought when extracting values from a cell you'd want to use the .Value property. So that Me.txt_BatchNumber.Text = Me.dgExtract.Item(rowIndex, 0).VALUE.ToString

 

2. You might want to use a Cell-Double Click event. Then when that event triggers the 'e' will provide you with the rowindex and the columnindex.

 

nevermind, i think you're using a Datagrid control. I'll post this anyway in case you change to a datagridview control

Currently Using: Visual Basic.Net 2005, .Net Framework 2.0
Posted
I found the problem, and it was a pretty silly one. I had two grids on my form and I was referencing the wrong grid - of course it was always -1. Am posting this embaressment just in case it can help someone else spot such an error....

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...