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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MSHFlexGrid - User click on Header 1

Status
Not open for further replies.

RobHVB6Sql

Programmer
May 20, 2002
77
0
0
AU
What property /code can I use to see what header column the user clicked on. This will then allow me to sort the grid on this column.

I'm not sure I want to use
Code:
 .Row = 0
as I normally bypass processes when this is true.
I've also looked at:
Code:
.Col
.MouseRow
.MouseCol

I presume I'll be using the MouseDown event?

Anyone done this before? Any help appreciated :)

Rob Hasard
(VB6 /SQL 7.0)
 
Use the click event. The .col value will be the column. To test whether this is the header row or not, use this:

If .MouseRow < 1 Then
' do the sort here
...
Else
...


"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
Yup, that'll do it :)
Here is some solution code that will sort any column.
Thanks Artie.

Code:
'declaration section
dim blnAscend as boolean

Code:
Private Sub theGrid_Click()
With theGrid
   
    'if user clicked the grid header, then sort by that column!
     If (.MouseRow < 1 And blnAscend = True) Then
        Call SortGrid(theGrid, .MouseCol, 2) 'DESescending
        blnAscend = False
     ElseIf (.MouseRow < 1 And blnAscend = False) Then
       Call SortGrid(theGrid, .MouseCol, 1) 'ascending
       blnAscend = True
     End If
...

Code:
Public Sub SortGrid(TheGrid As MSFlexGrid, TheCol As Long, TheOrder As Long)
'TheCol = 0 is the first column in any grid
'TheOrder = 1 is Ascending;     2 is Descending

  Dim i As Long
  TheGrid.Col = TheCol
  If TheOrder = 1 Then
     TheGrid.Sort = flexSortStringNoCaseAscending
  Else
      TheGrid.Sort = flexSortStringNoCaseDescending
  End If
  TheGrid.Refresh
End Sub

Rob Hasard
(VB6 /SQL 7.0)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top