Пользователь
Сообщения: 88
Благодарности: 19
|
Профиль
|
Отправить PM
| Цитировать
Вот попробовал накалякать LVSort позволяющюю и сортировать на ListView,созданном с помощью UDF
При этом сохраняется возможность редактирования на месте
Код: 
#include <GuiListView.au3>
#include <GuiImageList.au3>
$Gui = GUICreate("Test", 400, 250)
$hListView = _GUICtrlListView_Create($GUI, "Items|SubItems", 2, 2, 220, 196, BitOR($LVS_EDITLABELS, $LVS_REPORT))
$hImage = _GUIImageList_Create (16,16,5);
_GUIImageList_AddIcon ($hImage, "shell32.dll", 3);
_GUIImageList_AddIcon ($hImage, "shell32.dll", 11);
_GUIImageList_AddIcon ($hImage, "shell32.dll", 22);
_GUIImageList_AddIcon ($hImage, "shell32.dll", 33);
_GUICtrlListView_SetImageList ($hListView, $hImage, 1)
$ListItem1 = _GUICtrlListView_AddItem($hListView, "Boris",0)
$ListItem2 = _GUICtrlListView_AddItem($hListView, "Anna",2)
$ListItem3 = _GUICtrlListView_AddItem($hListView, "Sveta",1)
$ListItem4 = _GUICtrlListView_AddItem($hListView, "Misha",3)
$ListSubItem1 = _GUICtrlListView_AddSubItem ($hListView, 0,'44', 1)
$ListSubItem2 = _GUICtrlListView_AddSubItem ($hListView, 1,'22', 1)
$ListSubItem3 = _GUICtrlListView_AddSubItem ($hListView, 2,'11', 1)
$ListSubItem4 = _GUICtrlListView_AddSubItem ($hListView, 3,'33', 1)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
Global $B_DESCENDING[_GUICtrlListView_GetColumnCount ($hListView) ]
While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
;------------------------------------------------------------------------------
Func LVSort($in)
$itN=_GUICtrlListView_GetItemCount($hListView)
$colN=_GUICtrlListView_GetColumnCount($hListView)
Dim $iArr[$itN][$colN+2]
For $ii=0 To $itN-1
$aItem=_GUICtrlListView_GetItem($hListView, $ii)
For $jj=0 To $colN-1
$iArr[$ii][$jj]=_GUICtrlListView_GetItemText($hListView, $ii,$jj)
$iArr[$ii][$jj+1]=$aItem[4]
Next
Next
_ArraySort( $iArr,'','','',$colN+1)
For $ii=0 To $itN-1
_ArraySwap( $iArr[$ii][0], $iArr[$ii][$in] )
Next
_ArraySort( $iArr,0,0,0,$colN+1)
For $ii=0 To $itN-1
_ArraySwap( $iArr[$ii][0], $iArr[$ii][$in] )
Next
_GUICtrlListView_DeleteAllItems($hListView)
For $ii=0 To $itN-1
_GUICtrlListView_AddItem($hListView,$iArr[$ii][0],$iArr[$ii][2])
For $jj=1 To $colN-1
_GUICtrlListView_AddSubItem ($hListView, $ii,$iArr[$ii][$jj], $jj)
Next
Next
EndFunc
;-----------------------------------------------------------------------------------
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
$hWndListView = $hListView
If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $LVN_COLUMNCLICK ; Клик по колонке
$aHit = _GuiCtrlListView_SubItemHitTest ($hWndListView)
LVSort($aHit[1])
Case $LVN_BEGINLABELEDIT
Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)
Return False
Case $LVN_ENDLABELEDIT
Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)
Local $tBuffer = DllStructCreate("char Text[" & DllStructGetData($tInfo, "TextMax") & "]", DllStructGetData($tInfo, "Text"))
If StringLen(DllStructGetData($tBuffer, "Text")) Then Return True
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
Наверняка ее можно еще упростить.
Цитата Creat0R:
gregaz,
Цитата:Как правильно это организовать?
Двойной клик улавливается сообщениями ($NM_DBLCLK), в справке есть пример (в _GUICtrlListView_Create()).
Когда мы кликаем два раза подряд (промежуточность установлена системой), то в ListView посылается сообщение $NM_DBLCLK, вот его и нужно улавливать (испол. WM_NOTIFY_EVENTS()). »
|
Да двойной то улавливает и эта функция (если добавить соответственно $iCode : $NM_CLICK и $NM_DBLCLK,но сначала улавливается одинарный клик(его не знаю как пропустить) чтобы среагировать на второй (от двойного) ?
|