Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 19,252 times

Related Categories

Detecting Column Header clicks for MSFlexGrid

webjose

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.

This code is for everyone's use and, although I have tested it the best I can, I cannot be held responsible for its use or misuse, or for any other type of damage WHATSOEVER. Use this code at your own risk. If you find an error or can improve it, feel

Comments

  • Good example

    Posted by Jon_Williamson on 10 Jul 2003

    While this is an ingenious solution, you can always use the .MouseRow property to detect header clicks.