Quote Originally Posted by lizano diaz View Post
Dear Krool thank you very much for the update, the Extend LastCol seems to work fine. There is a small detail you can see in the attached picture. Apart from this, I wanted to take advantage of asking, how would it be done to sort (ascending, descending) when clicking on the header of the grid, regardless of whether the data in the columns are of type date, string, etc. Thank you very much for your answers.Attachment 182148
I can't replicate your picture issue and with rows set to 300.

Concerning your sorting. Below is a code example showing how it can be done. Please note to fill in .ColData() on all columns on your data population with the VarType values. (e.g. vbString, vbDate)
Code:
Private LastColSort As Long

Private Sub Form_Load()
LastColSort = -1
End Sub

Private Sub VBFlexGrid1_BeforeMouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single, Cancel As Boolean)
With VBFlexGrid1
.HitTest X, Y
If .HitResult = FlexHitResultCell And .HitRow < .FixedRows And .HitCol > .FixedCols - 1 Then
    If (Button And vbLeftButton) = vbLeftButton Then
        .Sort = FlexSortNone
        If LastColSort > -1 And LastColSort <> .HitCol Then .ColSort(LastColSort) = FlexSortNone
        LastColSort = .HitCol
        Call FlexSetColSort(VBFlexGrid1, LastColSort, True)
        .Cell(FlexCellSort, .FixedRows, LastColSort, .Rows - 1, LastColSort) = FlexSortUseColSort
        Cancel = True
    End If
End If
End With
End Sub

Public Sub FlexSetColSort(ByRef This As VBFlexGrid, ByVal iCol As Long, ByVal Toggle As Boolean)
With This
Select Case .ColData(iCol)
    Case vbString
        If Toggle = True Then
            If .ColSort(iCol) = FlexSortStringAscending Then
                .ColSort(iCol) = FlexSortStringDescending
            Else
                .ColSort(iCol) = FlexSortStringAscending
            End If
        Else
            If .ColSort(iCol) <> FlexSortStringDescending Then .ColSort(iCol) = FlexSortStringAscending
        End If
    Case vbDate
        If Toggle = True Then
            If .ColSort(iCol) = FlexSortDateAscending Then
                .ColSort(iCol) = FlexSortDateDescending
            Else
                .ColSort(iCol) = FlexSortDateAscending
            End If
        Else
            If .ColSort(iCol) <> FlexSortDateDescending Then .ColSort(iCol) = FlexSortDateAscending
        End If
    Case vbCurrency
        If Toggle = True Then
            If .ColSort(iCol) = FlexSortCurrencyAscending Then
                .ColSort(iCol) = FlexSortCurrencyDescending
            Else
                .ColSort(iCol) = FlexSortCurrencyAscending
            End If
        Else
            If .ColSort(iCol) <> FlexSortCurrencyDescending Then .ColSort(iCol) = FlexSortCurrencyAscending
        End If
    Case vbDecimal, vbDouble, vbSingle, vbLong, vbInteger, vbByte
        If Toggle = True Then
            If .ColSort(iCol) = FlexSortNumericAscending Then
                .ColSort(iCol) = FlexSortNumericDescending
            Else
                .ColSort(iCol) = FlexSortNumericAscending
            End If
        Else
            If .ColSort(iCol) <> FlexSortNumericDescending Then .ColSort(iCol) = FlexSortNumericAscending
        End If
    Case Else
        If Toggle = True Then
            If .ColSort(iCol) = FlexSortGenericAscending Then
                .ColSort(iCol) = FlexSortGenericDescending
            Else
                .ColSort(iCol) = FlexSortGenericAscending
            End If
        Else
            If .ColSort(iCol) <> FlexSortGenericDescending Then .ColSort(iCol) = FlexSortGenericAscending
        End If
End Select
End With
End Sub