473,387 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

MSHFlexGrid column resizing

Hello,

Anybody know how to detect when a user drags between columns in a
MSHFlexGrid when resizing column width? (Short of setting up a timer event
that continuously monitors column width.) MouseDown, MouseUp, MouseMove,
MouseIcon etc. all seem to be 'blind' when my mouse cursor changes to the
horizontal double headed arrow for column resizing. No events seem to be
triggered when the mouse pointer is in this state?

Thanks,

Gord
Jul 17 '05 #1
1 10925
Gord
Hello,

Anybody know how to detect when a user drags between columns in a
MSHFlexGrid when resizing column width? (Short of setting up a timer event
that continuously monitors column width.) MouseDown, MouseUp, MouseMove,
MouseIcon etc. all seem to be 'blind' when my mouse cursor changes to the
horizontal double headed arrow for column resizing. No events seem to be
triggered when the mouse pointer is in this state?


Put the following into a bas module.

' from ExtremeVBTalk - get a notification when the grid columns have been resized
' B Chernyachuk 1999 - Bo****@hotmail.com
'
Public g_lngDefaultHandler As Long ' Original handler of the grid events
Private m_bLMousePressed As Boolean 'true if the left button is pressed
Private m_bLMouseClicked As Boolean 'true just after the click (i.e. just after the left button is released)

'API declarations ================================================== ==========
' Function to retrieve the address of the current Message-Handling routine
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
' Function to define the address of the Message-Handling routine
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As
Long) As Long
' Function to execute a function residing at a specific memory address
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

'Windows messages constants
Private Const WM_LBUTTONUP = &H202
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_ERASEBKGND = &H14
'this is our event handler
Public Function GridMessage(ByVal hwnd As Long, ByVal Msg As Long, ByVal wp As Long, ByVal lp As Long) As Long

If m_bLMousePressed And Msg = WM_LBUTTONUP Then
'button have been just released
m_bLMousePressed = False
m_bLMouseClicked = True
End If

If Not (m_bLMousePressed) And Msg = WM_LBUTTONDOWN Then
'button have been just pressed
m_bLMousePressed = True
m_bLMouseClicked = False
End If

If m_bLMouseClicked And (Msg = WM_ERASEBKGND) Then
'Only when resize happens this event may occur after releasing the button !
'When user is making a simple click on grid,
'the WM_ERASEBKGND event occurs before WM_LBUTTONUP,
'and therefore will not be handled there

Debug.Print "Grid message: ", "Resized !" 'TO DO: Replace this futile code
'with something usefull

m_bLMouseClicked = False

End If

'call the default message handler
GridMessage = CallWindowProc(g_lngDefaultHandler, hwnd, Msg, wp, lp)

End Function
Put the following into a form:

' This constant is used to refer to the Message Handling function in a given window
Private Const GWL_WNDPROC = (-4)

In your form_load:

' setup the handler for knowing when the user has resized the grid columns
'Save the address of the existing Message Handler
g_lngDefaultHandler = GetWindowLong(MSFlexgrid.hwnd, GWL_WNDPROC)

'Define new message handler routine
Call SetWindowLong(MSFlexgrid.hwnd, GWL_WNDPROC, AddressOf GridMessage)

Then, when the user resizes the grod columns, the code in the GridMessage function will run.
Replace the

Debug.Print "Grid message: ", "Resized !" 'TO DO: Replace this futile code
'with something usefull

code with whatever you need to do when the user resizes the column.

* IMPORTANT *
In your form_unload:

'Return the old grid message handler back
Call SetWindowLong(MSFlexgrid.hwnd, GWL_WNDPROC, g_lngDefaultHandler)
Always remember to restore the original handler (as above) before the form gets destroyed.

Regards

Brad
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: dave | last post by:
I've designed a nice little App that works something like a spreadsheet using the MSHFlexgrid control. Many users are inclined to press the tab key, expecting the program to respond like excel...
4
by: doller | last post by:
Hi Dear , I have a mshflexgrid control on the VB form having 200 rows .I need to add a row before or after the selected row in the grid. As wee do in excel we can add rows before or after...
4
by: giddy | last post by:
hie, does anyone know. how to use the MSHFlexGrid.. .in C#... and does'nt VS 2005 shipp with a NEW MSHflexGrid??? i hav VB6 installed to so does that create some conflict?? theres only ver. 6.0...
2
by: nairda | last post by:
Hi, I'm Adrian from Indonesia. I have a problem using MSHFlexgrid in VB. I want to show a data from a single cell in MSHFlexgrid that I choose by mouse click in a textbox. The problem is, how to...
0
by: nairda | last post by:
Hello all! I have a problem combining 2 tables from excel to my MSHFlexgrid. I've succeeded to show an excel table in my MSHFlexgrid using clipboard, but then I have to add a view columns from...
4
by: nairda | last post by:
Hi, I have a minor trouble in my program. I've one MSHFlexgrid to show all datas from an input form that I made. The problem occurs when I deleted one or more rows in the MSHFlexgrid and would like...
4
by: nairda | last post by:
Hi all, I have a MSHFlexgrid to show my database and some textboxes to show datas I choosed from MSHFlexgrid. I would like to know if there's a way to show a specific data I choosed from MSHF in...
2
by: WhiteShore | last post by:
hi there just wonder is it possible to save all the data item from mshflexgrid that has been retrieved from another table? let say i got 1 table called A and has been retrieved by mshflexgrid,...
2
Fary4u
by: Fary4u | last post by:
Hi it's my 1st post in VB, i'm trying to get data from ComboBox & result with MSHFlexGrid it's working fine there is no problem they only thing i need is Another ComboBox & ( result...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.