CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2000
    Posts
    36

    Flexgrid sort indicator

    Is there a way to put an indicator on a row header (up or down) that shows which column grid is sorted (ascending/descending - similar to Windows Explorer)?

    Thanks,
    Glenn



  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Flexgrid sort indicator

    Here is an example which will put ^ or v on a sorted column


    ' Useful for sorting da es and other occassions where you have
    ' to click on one column but sort by another
    '
    ' Inputs:'TheForm is the form where you want the
    'sorter works, usually its Me.
    'ClickCol is the column # that is being clicked
    'on and SortCol is the column # that will be
    'sorted.
    'ParamArray is an array of Booleans that represents how you want each column sorted. True
    means sort as a string, False means sort as
    numeric, and if you omit the paramter then it is
    sorted as generic. Example True,True,,False
    means the first two columns are sorted as a
    string the third column is sorted as generic,
    and the fourth is sorted as numeric. In this
    case if there is more than 4 columns then the rest would get sorted as generic since
    their parameter is missing.

    The IsString array represents
    how you want each column sorted. True
    means sort as a string, False means
    sort as numeric, and if you omit the
    paramter then it is sorted as generic.
    '' Example True,True,,False means the first two columns are sorted as a string
    the third column is sorted as generic
    and the fourth is sorted as numeric.



    Public Sub SortFlex(TheForm As Form, FlexGrid As MSFlexGrid, ClickCol As Integer, SortCol As Integer, ParamArray IsString() As Variant)
    Dim i As Integer
    Dim Headline As String
    Dim Ascend As Boolean
    Dim Decend As Boolean
    Const p As String = "^"
    Const m As String = "v"

    On Error Goto SortErr

    TheForm.MousePointer = vbHourglass
    FlexGrid.Col = SortCol

    'cycle thru all the columns



    'example
    Call SortFlex(Me, MSFlexGrid1, MSFlexGrid1.Col, MSFlexGrid1.Col)


    For i = 0 To FlexGrid.Cols - 1
    Headline = FlexGrid.TextMatrix(0, i)
    Ascend = Right(Headline, 1) = p
    Decend = Right(Headline, 1) = m
    If Ascend Or Decend Then Headline = Left(Headline, Len(Headline) - 1)


    If i = ClickCol Then


    If Ascend Then
    FlexGrid.TextMatrix(0, ClickCol) = Headline & m


    If UBound(IsString) < LBound(IsString) Then
    FlexGrid.Sort = flexSortGenericDescending
    Else


    If IsString(i) Then
    FlexGrid.Sort = flexSortStringDescending
    Else
    FlexGrid.Sort = flexSortNumericDescending
    End If
    End If
    Else
    FlexGrid.TextMatrix(0, ClickCol) = Headline & p


    If UBound(IsString) < LBound(IsString) Then
    FlexGrid.Sort = flexSortGenericAscending
    Else


    If IsString(i) Then
    FlexGrid.Sort = flexSortStringAscending
    Else
    FlexGrid.Sort = flexSortNumericAscending
    End If
    End If
    End If
    Else
    FlexGrid.TextMatrix(0, i) = Headline
    End If
    Next i
    SortErr:
    TheForm.MousePointer = vbNormal


    If Err.Number <> 0 Then
    MsgBox Err.Number & vbCrLf & Err.Description, vbCritical, "Sort Error"
    End If
    End Sub

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured