[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

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
0
abidsml
Asked:
abidsml
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
Try to locked the columns.
0
 
kojotCommented:
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.MoveFirst
        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.
0
 
mmshahCommented:
Hi,
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.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
mmshahCommented:
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.
0
 
Éric MoreauSenior .Net ConsultantCommented:
Use the RowColChange event.
0
 
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. !!!
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now