Library code snippets
Detecting Column Header clicks for MSFlexGrid
By Jose Pablo Ramirez Vargas, published on 06 Mar 2002
To use this code, add a flexgrid control to a form, and add the following to the MouseDown or MouseUp event of the control.
Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim cont As Integer
Dim found As Boolean
'Only do it if the button is the left one, and there
'are no mask keys pressed.
'Of course, you can vary this to fit your needs.
If (Button = vbLeftButton) And (Shift = 0) Then
With MSFlexGrid1
'Do not proceed if the row clicked is
'not the header row.
If (.RowHeight(0) < y) Then
Exit Sub
End If
'Initialize variables
cont = 0
found = False
'Find the column clicked using mouse coords
Do While (cont < .Cols) And Not (found)
If (.ColPos(cont) + .ColWidth(cont) < x) Then
cont = cont + 1
Else
found = True
End If
Loop
'If column found, proceed to run the appropriate code
If found Then
MsgBox "You clicked the header for column " & .TextMatrix(0, cont)
End If
End With
End If
End Sub
The above will work for one fixed row only. However, you can easily adapt it to multiple fixed header rows.
Related articles
Related discussion
-
Working on Who Wants To Be A Millionaire Project in VB6 [NEED HELP]
by williamsg (1 replies)
-
Make me or point me to an installer with comctl32 vb6
by tgkprog2 (0 replies)
-
How to use VB6 to make cumulative frequency polygons
by heibaidoufu (0 replies)
-
Problem with Input File
by heibaidoufu (4 replies)
-
Make setup vb6 + sql 2000
by himanshu.tomar (1 replies)
While this is an ingenious solution, you can always use the .MouseRow property to detect header clicks.
This thread is for discussions of Detecting Column Header clicks for MSFlexGrid.