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
-
VB6 Runtime error 381 subsript out of range Error
by Uncle (2 replies)
-
passing and reading parameters from using Shell
by jigartoliya (0 replies)
-
Convert C++ code to VB6
by mawcot (4 replies)
-
listbox scrollbar
by Dennijr (10 replies)
-
Can you describe Above simple VB6 code?
by pramodmca09 (0 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
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.