Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get a field value from selected datagrid row

Status
Not open for further replies.

cmn2

Programmer
Mar 6, 2003
73
US
Hi

I've not coded in VB6 for quite some time am having trouble and could use some help. I'll keep this short.

I have a datagrid populated with a recordset. If a user clicked somewhere on row 5 how could I get the value of say field 3 from row 5?

I would appreciate any help that anyone could lend.

Thanks
 
Use the recordset itself to retrieve the value of the third field in the fifth record. The only problem is that the user will see the row changing as you access the fifth record.
 
This code will allow you to get the value with whatever column and row you specify

Code:
Dim intCol as Integer
Dim intRow as Integer

intCol = 3
intRow = 5
DataGrid.Columns(intCol).CellValue(datagrid.RowBookmark(intRow))
 
Thanks for responding.
Sorry, I wasn't overly clear on what I'm looking for in my post.

With the datagrid click event, how can I capture a field value of the row the user just clicked on?
 
There might be a better solution but this is the one that I use:

Code:
Option Explicit
Private GridWasClicked As Boolean

Private Sub DataGrid_Click()
    GridWasClicked = True
End Sub

Private Sub DataGrid_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii
        Case vbKeyUp, vbKeyDown, vbKeyRight, vbKeyLeft
            GridWasClicked = False
    End Select
        
End Sub

Private Sub DataGrid_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
    If GridWasClicked Then
        Debug.Print DataGrid.Text
        GridWasClicked = False
    End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top