|
|
|
Forum Guru
      
участник
Last Login: 31.03.2008 18:35
Сообщ.: 54,
Visits: 771
|
|
| Сортировка MSFlexGrid.Sort по колонке, в которой содержатся данные типа Date или Date+Time происходит неверно. Как решить эту проблему, если данные берутся не из базы, а из массива ?
|
|
|
|
|
Forum Member
      
участник
Last Login: 28.08.2006 0:43
Сообщ.: 48,
Visits: 452
|
|
| пиши собственную процедуру сортировки, основанную на каком-нибудь быстром алгоритме, я делал по способу Шелла:)
|
|
|
|
|
Supreme Being
      
непров.участник
Last Login: 08.07.2008 15:52
Сообщ.: 1 131,
Visits: 8 867
|
|
| Insolent, U menya vse rabotaet: Private Sub Command1_Click() MSHFlexGrid1.Sort = 9 'flexSortCustom End Sub Private Sub Form_Load() With MSHFlexGrid1 .Cols = 2 .AddItem 1 & vbTab & Date .AddItem 2 & vbTab & Date - 1 .AddItem 3 & vbTab & Date + 1 .AddItem 4 & vbTab & Date - 5 End With End Sub Private Sub MSHFlexGrid1_Compare(ByVal Row1 As Long, ByVal Row2 As Long, Cmp As Integer) CustomSort MSHFlexGrid1, 1, Row1, Row2, Cmp, True End Sub Private Sub CustomSort(ByRef pGrid As MSHFlexGrid, _ ByVal pCol As Long, _ ByVal pRow1 As Long, _ ByVal pRow2 As Long, _ ByRef pCmp As Integer, _ ByRef pSortAscending As Boolean) Dim varRow1 As Variant Dim varRow2 As Variant On Error GoTo MethodError With pGrid If IsNumeric(.TextMatrix(pRow1, pCol)) And IsNumeric(.TextMatrix(pRow2, pCol)) Then varRow1 = CDbl(.TextMatrix(pRow1, pCol)) varRow2 = CDbl(.TextMatrix(pRow2, pCol)) ElseIf IsDate(.TextMatrix(pRow1, pCol)) And IsDate(.TextMatrix(pRow2, pCol)) Then varRow1 = CDate(.TextMatrix(pRow1, pCol)) varRow2 = CDate(.TextMatrix(pRow2, pCol)) Else varRow1 = CStr(Trim$(.TextMatrix(pRow1, pCol))) varRow2 = CStr(Trim$(.TextMatrix(pRow2, pCol))) End If If varRow1 < varRow2 Then pCmp = -1 ElseIf varRow1 > varRow2 Then pCmp = 1 Else pCmp = 0 End If If Not pSortAscending Then pCmp = pCmp * -1 End If End With MethodError: If Err.Number <> 0 Then MsgBox "Error " & Err.Description & " in CustomSort" End If End Sub
|
|
|
|
|
новичок
      
участник
Last Login: 30.04.2007 7:19
Сообщ.: 3,
Visits: 29
|
|
| Спасибо за функцию :) У меня тоже все замечательно работает!
---
|
|
|
|