Для одного проекта мне понадобилась сортировка по столбцу. Нашел пример в интернетах и вряд ли бы допер до реализации.
Global sortm1.l=0; -1 desc,0 undef,1 asc
Global sortm2.l=0
Procedure Callback(Window.l, Message.l, wParam.l, lParam.l)
result = #PB_ProcessPureBasicEvents
Select Message
Case #WM_NOTIFY ; these events are send as notification messages
*pnmh.NMHDR = lParam ; lParam points to a structure with more info
If *pnmh\hwndFrom = GadgetID(0) ; see if it is the right gadget
Select *pnmh\code ; code contains actual message
Case #LVN_COLUMNCLICK ; user clicked on the Header of a column
*pnmv.NMLISTVIEW = lParam ; another info structure
Column.l = *pnmv\iSubItem ; clicked column
;MessageRequester("Column Header Click","Clicked on Column"+Str(Column),0)
hdi.HD_ITEM
hdi\mask=#HDI_FORMAT
ColumnHeader=SendMessage_(GadgetID(0), #LVM_GETHEADER, 0, 0)
Select Column
Case 0
SendMessage_(ColumnHeader,#HDM_GETITEM,0,@hdi)
If sortm1=0
sortm1=-1
;SendMessage_(ColumnHeader,#HDM_GETITEM,0,@hdi)
hdi\fmt=hdi\fmt|#HDF_SORTDOWN
hdi\mask=#HDI_FORMAT
SendMessage_(ColumnHeader,#HDM_SETITEM,0,@hdi)
Else
sortm1=-sortm1
If sortm1=1
hdi\fmt=hdi\fmt&~#HDF_SORTDOWN
hdi\fmt=hdi\fmt|#HDF_SORTUP
ElseIf sortm1=-1
hdi\fmt=hdi\fmt&~#HDF_SORTUP
hdi\fmt=hdi\fmt|#HDF_SORTDOWN
EndIf
;hdi\mask=#HDI_FORMAT
SendMessage_(ColumnHeader,#HDM_SETITEM,0,@hdi)
EndIf
;reset header 1
sortm2=0
SendMessage_(ColumnHeader,#HDM_GETITEM,1,@hdi)
hdi\fmt=hdi\fmt&~#HDF_SORTUP
hdi\fmt=hdi\fmt&~#HDF_SORTDOWN
SendMessage_(ColumnHeader,#HDM_SETITEM,1,@hdi)
Case 1
SendMessage_(ColumnHeader,#HDM_GETITEM,1,@hdi)
If sortm2=0
sortm2=-1
hdi\fmt=hdi\fmt|#HDF_SORTDOWN
hdi\mask=#HDI_FORMAT
SendMessage_(ColumnHeader,#HDM_SETITEM,1,@hdi)
Else
sortm2=-sortm2
If sortm2=1
hdi\fmt=hdi\fmt&~#HDF_SORTDOWN
hdi\fmt=hdi\fmt|#HDF_SORTUP
ElseIf sortm2=-1
hdi\fmt=hdi\fmt&~#HDF_SORTUP
hdi\fmt=hdi\fmt|#HDF_SORTDOWN
EndIf
;hdi\mask=#HDI_FORMAT
SendMessage_(ColumnHeader,#HDM_SETITEM,1,@hdi)
EndIf
;reset header 0
sortm1=0
SendMessage_(ColumnHeader,#HDM_GETITEM,0,@hdi)
hdi\fmt=hdi\fmt&~#HDF_SORTUP
hdi\fmt=hdi\fmt&~#HDF_SORTDOWN
SendMessage_(ColumnHeader,#HDM_SETITEM,0,@hdi)
EndSelect
EndSelect
EndIf
EndSelect
ProcedureReturn result
EndProcedure
If OpenWindow(0, 0, 0, 640, 480, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
; left column
ListIconGadget(0, 0, 0, 640, 480, "Column 1", 300)
AddGadgetColumn(0, 1, "Column 2" , 320)
SetWindowCallback(@Callback())
Repeat
ev=WaitWindowEvent()
Until ev = #PB_Event_CloseWindow
EndIf
Global sortm2.l=0
Procedure Callback(Window.l, Message.l, wParam.l, lParam.l)
result = #PB_ProcessPureBasicEvents
Select Message
Case #WM_NOTIFY ; these events are send as notification messages
*pnmh.NMHDR = lParam ; lParam points to a structure with more info
If *pnmh\hwndFrom = GadgetID(0) ; see if it is the right gadget
Select *pnmh\code ; code contains actual message
Case #LVN_COLUMNCLICK ; user clicked on the Header of a column
*pnmv.NMLISTVIEW = lParam ; another info structure
Column.l = *pnmv\iSubItem ; clicked column
;MessageRequester("Column Header Click","Clicked on Column"+Str(Column),0)
hdi.HD_ITEM
hdi\mask=#HDI_FORMAT
ColumnHeader=SendMessage_(GadgetID(0), #LVM_GETHEADER, 0, 0)
Select Column
Case 0
SendMessage_(ColumnHeader,#HDM_GETITEM,0,@hdi)
If sortm1=0
sortm1=-1
;SendMessage_(ColumnHeader,#HDM_GETITEM,0,@hdi)
hdi\fmt=hdi\fmt|#HDF_SORTDOWN
hdi\mask=#HDI_FORMAT
SendMessage_(ColumnHeader,#HDM_SETITEM,0,@hdi)
Else
sortm1=-sortm1
If sortm1=1
hdi\fmt=hdi\fmt&~#HDF_SORTDOWN
hdi\fmt=hdi\fmt|#HDF_SORTUP
ElseIf sortm1=-1
hdi\fmt=hdi\fmt&~#HDF_SORTUP
hdi\fmt=hdi\fmt|#HDF_SORTDOWN
EndIf
;hdi\mask=#HDI_FORMAT
SendMessage_(ColumnHeader,#HDM_SETITEM,0,@hdi)
EndIf
;reset header 1
sortm2=0
SendMessage_(ColumnHeader,#HDM_GETITEM,1,@hdi)
hdi\fmt=hdi\fmt&~#HDF_SORTUP
hdi\fmt=hdi\fmt&~#HDF_SORTDOWN
SendMessage_(ColumnHeader,#HDM_SETITEM,1,@hdi)
Case 1
SendMessage_(ColumnHeader,#HDM_GETITEM,1,@hdi)
If sortm2=0
sortm2=-1
hdi\fmt=hdi\fmt|#HDF_SORTDOWN
hdi\mask=#HDI_FORMAT
SendMessage_(ColumnHeader,#HDM_SETITEM,1,@hdi)
Else
sortm2=-sortm2
If sortm2=1
hdi\fmt=hdi\fmt&~#HDF_SORTDOWN
hdi\fmt=hdi\fmt|#HDF_SORTUP
ElseIf sortm2=-1
hdi\fmt=hdi\fmt&~#HDF_SORTUP
hdi\fmt=hdi\fmt|#HDF_SORTDOWN
EndIf
;hdi\mask=#HDI_FORMAT
SendMessage_(ColumnHeader,#HDM_SETITEM,1,@hdi)
EndIf
;reset header 0
sortm1=0
SendMessage_(ColumnHeader,#HDM_GETITEM,0,@hdi)
hdi\fmt=hdi\fmt&~#HDF_SORTUP
hdi\fmt=hdi\fmt&~#HDF_SORTDOWN
SendMessage_(ColumnHeader,#HDM_SETITEM,0,@hdi)
EndSelect
EndSelect
EndIf
EndSelect
ProcedureReturn result
EndProcedure
If OpenWindow(0, 0, 0, 640, 480, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
; left column
ListIconGadget(0, 0, 0, 640, 480, "Column 1", 300)
AddGadgetColumn(0, 1, "Column 2" , 320)
SetWindowCallback(@Callback())
Repeat
ev=WaitWindowEvent()
Until ev = #PB_Event_CloseWindow
EndIf
Комментарии
Отправить комментарий