?
Solved

DataGrid

Posted on 2003-02-25
5
Medium Priority
?
214 Views
Last Modified: 2010-05-01
I am sick of looking on MSDN ...

Can someone tell me how I can return the Value in the first Column of the Selected Row of a Datagrid.

The value always seems to be one click behind.

Thanks
Wayne
0
Comment
Question by:wlawson
  • 3
5 Comments
 
LVL 2

Expert Comment

by:IeuanJ
ID: 8023621
Instead of using the onClick event use the onRowChange event.  Click is an object level event not a data level one.

Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
    MsgBox DataGrid1.Text

End Sub
0
 
LVL 1

Expert Comment

by:xThorx
ID: 8023636
To retreive the value of a colum X of a slected row:

grid.col=x-1
value_of_the_element=grid.text

Hope that's what your looking for
0
 
LVL 2

Accepted Solution

by:
IeuanJ earned 150 total points
ID: 8023651
Apologies I forgot about the first column bit.

Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
    Dim oldCol As Integer

    oldCol = DataGrid1.Col
    DataGrid1.Col = 0
    MsgBox DataGrid1.Text
    DataGrid1.Col = oldCol
End Sub
0
 

Author Comment

by:wlawson
ID: 8029610
Thanks,

I actually found that if I ignored the first click, it moved the pointer to the right Row and then the second click found the correct value of Column(0) in the selected Row.

But you can have the points anyway.

Probably could have used the DBLCLICK event for the same affect.
0
 
LVL 2

Expert Comment

by:IeuanJ
ID: 8031895
both the click and double click event work on the object, they will process the routine BEFORE moving the focus to the new cell, the whole point of RowColChange is that it get processed only when the focus has changed toa  new cell.  The work around you have is neither efficient or good practise, I strongly suggest you change.

Also why a B grade here, my answer did exactly as you asked !!!!
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month9 days, 3 hours left to enroll

621 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