lauriemc Posted March 29, 2007 Posted March 29, 2007 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: Quote
NeuralJack Posted March 29, 2007 Posted March 29, 2007 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 Quote Currently Using: Visual Basic.Net 2005, .Net Framework 2.0
lauriemc Posted April 4, 2007 Author Posted April 4, 2007 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.... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.