Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where to place my code...???

Status
Not open for further replies.

todd666

IS-IT--Management
Dec 3, 2001
61
CA
Hi,

When nothing is execute and the program is waiting for action of user, can we place some code?

If yes, where?

I give an example:
I click on the datagrid. There is some code to execute on the module "click_datagrid". After that, the program is waiting for some action of the user. Is there a "After_click_datagrid" where I can put my code.

Thanks in advance.
 
No other event happends after the click event..
I wonder if you can create and event using the WithEvents??

Alley
 
Can you explain a little what is WithEvents?
 
The problem is that the code I want to put when nothing is happened, I want to put it just before the mousewheel is use. I'm not sure How to use your "WithEvent"....
 
Are you wanting to wait a period of time after the user clicks the grid?

Have you considered using a timer. Enable the time in the click_datagrid (not sure what this is??) procedure and then place your code in the timer to fire after whatever interval. You can disable the timer if the user takes an action in which you would not want this code to fire...

I am still unclear as to exactly what you're wanting to do so I don't really know if this will help you or not.
 
No, I don't want to wait a period of time and by the way, Thanks to all for helping me.

Here is what exactly what I want to do:

I use the mousewheel to scroll data of my DataGrid.
If I click on the datagrid, the DatGrid becomes in "Edit Mode". I have to press "ESCAPE" before to re-use the mousewheel. And I don't want the user to do this.

My problem is that the property "Form1.DataGrid1.EditActive"
return always "FALSE". I try many, many, many place to put this code but I think this property will return "TRUE" only after the code in "DataGrid_Click" will be finish to execute.

I hope I am more clear with this explanation of my problem.
Any help or suggestion will be appreciate.
 
So, if the user uses the mouse wheel while in Edit mode, you want the grid to exit out of edit mode?
 
What code do you have to make the mousewheel work with the datagrid? I imagine that you have some sort of subclass procedure to do this. Can we see that here (maybe you even got it here).
 
I try to put the code in the "WndProc" function and also in the "MouseWheel" function but "Datagrid.EditActive" is always to FALSE even if not. I don't understand...

Here is my code for the mousewheel:

Code:
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Const WM_VSCROLL = &H115

Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Const GWL_WNDPROC = (-4)
Public lpPrevWndProc As Long

Const WM_MOUSEWHEEL = &H20A
Const WHEEL_DELTA = 120

Dim Count As Integer

Function WndProc(ByVal hWnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  If msg = WM_MOUSEWHEEL Then
    Dim Delta As Long
    Static Travel As Long
    Delta = HiWord(wParam)
    Travel = Travel + Delta
    MouseWheel Travel \ WHEEL_DELTA, LoWord(lParam), HiWord(lParam)
    Travel = Travel Mod WHEEL_DELTA
  End If
  WndProc = CallWindowProc(lpPrevWndProc, hWnd, msg, wParam, lParam)
  End Function

Sub MouseWheel(Travel As Integer, x As Long, y As Long)
  Dim hWndGrid As Long, hWndScroll As Long
  hWndGrid = Form1.DataGrid1.hWnd
  If WindowFromPoint(x, y) = hWndGrid Then
    If Travel < 0 Then Travel = 1 Else Travel = 0 'The scroll code (up/down)
    hWndScroll = FindWindowEx(hWndGrid, 0, "ScrollBar", "DataGridSplitVScroll")
    SendMessage hWndGrid, WM_VSCROLL, Travel, ByVal hWndScroll
  End If
End Sub

Function HiWord(DWord As Long) As Integer
  CopyMemory HiWord, ByVal VarPtr(DWord) + 2, 2
End Function

Function LoWord(DWord As Long) As Integer
  CopyMemory LoWord, DWord, 2
End Function
 
The reason that EditActive is false is because when the cell that you are editing loses focus the datagrid automatically exits edit mode. The DG enters Edit Mode only when changing the contents of a cell.

You can see this for yourself if you add a time to your datagrid and set it's interval to 1000 and then add

Debug.Print DataGrid1.EditActive

Then watch the Immediate window and it should be false. Then go into your data grid, change a value - it will print out true. Then use your scroll wheel and it should print false again.

Also where are you actually subclassing this from? Could you paste the code that you use for the call to SetWindowLong.
 
Here is the code:

Code:
lpPrevWndProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WndProc)

If I understand well what you explain, I can conclude that if I just click on a cell of DataGrid and I don't change her value and I want to re-use the scrolling immediately, It's not possible to code it (To prevent the user pressing "ESC")?
 
It appears that when the datagrid has an activated cell, that the window is not processing any mouse wheel messages. Right now I don't know what to do for this. I am not going to be around for a while so maybe someone else can pick this up for you...
 
OK, thank you for the time you have taken for me. I appreciate. I better understand my problem So I hope I will find a solution ... Or someone else will pick this up for me...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top