db grid

i have a db grid and i need when i click on a row (record) display one field from the gid in a text box it works only on the press of a second click not the first Why and ho to solve this
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
Try to locked the columns.
First time you click on the grid you ONLY SET FOCUS to that grid. The csecond time you click you actually move to the desired record. I have a solution to this problem - I needed to capture a right click over a TDBGrid (it's pretty the same in a grid), and simultaniusly set the recordset to that record. Here is the code:

Private Sub TDBGrid_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim a
MouseX = X
MouseY = Y
If Button = 2 Then
For a = 0 To datPrimaryRS.Recordset.RecordCount - 1
    If (Y >= TDBGrid.RowTop(a)) And (Y <= TDBGrid.RowTop(a) + TDBGrid.RowHeight) Then
        datPrimaryRS.Recordset.Move (a)
        Exit For
    End If
Next a
PopupMenu Menu
End If
End Sub

This code POSITIONES you to the record clicked (THE FIRST CLICK NOW DOES THE TRICK)

Hope your problem is solved.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The easier way to slove this problem is to trap MouseDown event. And using this you should get your text box on first click. This assumes that your first control on the form is Grid control. I hope this will work.
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

The addition to my earlier comment please use RowContaining and ColContaining methods, which will make sure that you get the text box in your desired field.
Éric MoreauSenior .Net ConsultantCommented:
Use the RowColChange event.
abidsmlAuthor Commented:
well i have used the code above, it behaves silly, when i click first time works, but when i scroll down to get an entry at the bottom of the grid it returns to the top of the grid when i click. !!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.