Click Inside Datagrid

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Click Inside Datagrid

Post by D Willett »

Clicking a record selector in a DataGrid will return a correct value I can use ie:

Private Sub DataGrid1_Click()
Dim tmp As Integer
tmp = DataGrid1.Row
Me.txtUser.Text = DataGrid1.Columns(1).Text
End Sub

But Clicking inside the grid will return the previous value unless double clicked.
Is there a fix for this so my user can select his own name from inside the datagrid?
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 79365
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Click Inside Datagrid

Post by HansV »

You could use the On Mouse Up event instead of the On Click event.
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Click Inside Datagrid

Post by D Willett »

Same effect Hans.
A single click returns the previous value selected.
A dbl click returns the value required.

??
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 79365
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Click Inside Datagrid

Post by HansV »

In that case, I'm afraid I can't help you. The problem is mentioned in several other forums, and the suggestion to use On Mouse Up was the only one that looked plausible.
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Click Inside Datagrid

Post by D Willett »

Could I populate a listbox from the datagrid instead? that way I can return the correct record?
Or
Populate the list from the DSN ?

( Edited, This works )

Private Sub Command2_Click()
Dim Conn As adodb.Connection
Dim Rst As adodb.Recordset

Set Conn = New adodb.Connection
Set Rst = New adodb.Recordset

Conn.Open "dsn=AFDemo"
Rst.Open "SELECT SiteCD, UserID, JobID FROM DBA_SEARCH_PARAMS", Conn

While Not Rst.EOF
List1.AddItem Rst.Fields(1).Value
Rst.MoveNext
Wend
Rst.Close
Conn.Close
Set Rst = Nothing
Set Conn = Nothing
End Sub
Cheers ...

Dave.