|
-
Jan 25th, 2000, 04:31 AM
#1
Thread Starter
Hyperactive Member
Using MSflexgrid, I need to capture when the user presses the arrows. I put some code in to capture them in the KeyDown event but it only seems to be equal to an arrow if I'm holidng CTRL down at the same time.
-
Jan 25th, 2000, 04:58 AM
#2
You could figure out which Direction the User Pressed, by storing relative values and comparing them in the RowColChange Event, ie.
Code:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub MSFlexGrid1_RowColChange()
Static lRow As Long
Static lCol As Long
With MSFlexGrid1
If GetAsyncKeyState(vbLeftButton) = 0 Then
If lCol <> .Col Then
Caption = IIf(lCol > .Col, "Left", "Right")
lCol = .Col
Else
If lRow <> .Row Then
Caption = IIf(lRow > .Row, "Up", "Down")
lRow = .Row
End If
End If
Else
Caption = ""
lRow = .Row
lCol = .Col
End If
End With
End Sub
I use the GetAsyncKeyState API to determine when the User is Navigating with the Mouse, not the Keys.
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
-
Jan 25th, 2000, 09:22 PM
#3
Thread Starter
Hyperactive Member
ok, I have a couple questions about the code you posted. I dokn't think I've ever seen the Static statement used like that. I think I know what it does but could you explain?
I didn't know that you could just add a Sub to a control like that. Is this a special case or can you do that with other controls?
Also:
Caption = IIf(....)
what does the IIf do? I've never seen it before.
-
Jan 25th, 2000, 10:36 PM
#4
Declaring a Variable as Static Means that the Value is Stored when the Sub/Function Exits and Restored when Next Run, so any Changes you make to the Variable will be there next time.
I didn't add the Sub to the Control, RowColChange() is a Native Sub of the MSFlexGrid Control.
The Immeadiate If, (IIF), Returns 1 of 2 Values Depending on Whether the Expression is True or False, you should note that regardless of the Value returned, Both are Evaluated.
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
-
Jan 25th, 2000, 11:46 PM
#5
Thread Starter
Hyperactive Member
Thanks Aaron, that made things alot clearer. The reason I asked about adding the sub is because it wasn't listed there until I pasted the code. Once I pasted it, I didn't actually need any of the other code.
-
Jan 25th, 2000, 11:53 PM
#6
Hyperactive Member
Hi, Aaron.
Is your code should change the caption? But MSFlexgrid doesn't have a caption property.
I cannot get it work. I have tried to pass values to text box and it doesn't show anything. What I am doing wrong?
Larisa
-
Jan 26th, 2000, 01:15 AM
#7
Hyperactive Member
Thank you, Aaron. My fault, I was using mouse instead of arrow keys. Probably still sleepy.
Larisa
-
Jan 26th, 2000, 12:10 PM
#8
Larisa,
I'm not Referencing the MSFlexGrid when I use the Caption Property, so it's actually Changing the Forms Caption.
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|