Link to home
Start Free TrialLog in
Avatar of lyners
lyners

asked on

Event Actions and Flexgrid

I am using Access97. In it I have a form with a flexgrid control on it. To mimick tab movements within the flexgrid and to allow users to add data to the flexgrid I have a textbox that I move over the top of the flexgrid. The user thinks that they are entering data into the flexgrid, but in actuallity they are entering the data into the textbox, and the program is filling in the flexgrid.

My problem.
I am trying to capture mousedown events. In order to use the tab (which does not work in a flexgrid) I have a lostfocus routine that when the the textbox loses the focus, it "tabs" to the next field. I am trying to have the program catch mousedown events, so that if a user uses the mouse to move to a different grid rather than the next grid in the control, it goes there. my coding is as follows:
'***************

Private Sub flxRevObjDetail_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Long, ByVal y As Long)
    usingMouse = True
    flxRevObjDetail.Text = txtFlxGridInput2.Text
    ChangeCelltext
End Sub

'***************
Private Sub txtFlxGridInput2_LostFocus()
    If usingMouse = True Then 'if using mouse, then ignor rest
        usingMouse = False
        Exit Sub
    End If
   
    flxRevObjDetail.Text = txtFlxGridInput2.Text
   
    If flxRevObjDetail.Col < flxRevObjDetail.Cols - 1 Then
        If flxRevObjDetail.Col = 0 And txtFlxGridInput2.Text = "" Then
            txtNotes.SetFocus
        Else
            flxRevObjDetail.Col = flxRevObjDetail.Col + 1
            flxRevObjDetail.SetFocus
            ChangeCelltext
        End If
    Else
        If flxRevObjDetail.Row = flxRevObjDetail.Rows - 1 Then
            flxRevObjDetail.AddItem ""
        End If
        flxRevObjDetail.Row = flxRevObjDetail.Row + 1
        flxRevObjDetail.Col = 0
        flxRevObjDetail.SetFocus
        ChangeCelltext
    End If
           
End Sub

The problem is the this LostFocus Event fires BEFORE the Mousedown event. Is there a different way I can check to see if the mouse was they previous thing used?

Avatar of Nosterdamus
Nosterdamus
Flag of Israel image

Hi lyners,

Try using the OnClick Event instead.

HTH,

Nosterdamus
Avatar of lyners
lyners

ASKER

Thanks for the advise. I have researched this further and have found out the following....

Order of events when the mouse is clicked..

First Control..
Exit -> Lost Focus

Second Control..
Enter -> Got Focus -> MouseDown -> MouseUp -> Click

The Click event is the last thing, The lost Focus event is where the moving of the text box occurs. At this moment I still do not see how I am going to detect the mouse click prior to the lostfocus procedure.
ASKER CERTIFIED SOLUTION
Avatar of Nosterdamus
Nosterdamus
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Correction:

If that is so, lets monitor the keystrokes in the textbox, and set UsingMouse, when ever Non Tab and Non Reurn keys are pressed. If they are pressed, then you want it to akt as if a Tab is pressed.

Should read:
If that is so, lets monitor the keystrokes in the textbox, and set UsingMouse, when ever Non Tab and Non Return keys are pressed. If they are pressed, then you want it to act as if a Tab is pressed.

In addition:
The rest of Sub txtFlxGridInput2_LostFocus() should stay as is...


;-)

Nosterdamus
Avatar of lyners

ASKER

Excellent Idea. A couple things with this to make it work effectively.

-I had to leve the mouse down. This assitted me if I entered the flexgrid control through a mouse click.

-Also I had to add a routine in every controls onEnter function so that the textbox was shrunk back down to a size nobody could see.

Thanks, This worked great!

:-)
Lyners
Hi lyners,

Glad I could help & good luck with your app.

;-)

Nosterdamus