MrCreatoR Posted March 17, 2007 Share Posted March 17, 2007 Hi all, In next example, i had to use some code that i has found somewhere here on the forum (please except my apologies the author of this script, i really can not find it). This example is show how you can change the icons during the checking certain checkbox. I mean, if you check one checkbox, and even if you not select the item itself, the icon of that item is changed, if you uncheck it, then the icon is changing back... So my problem is, when i starting to sort the items (if some of them have different icons and check states), then i see one big confusion of the items, and they icons when i trying to check/uncheck them again. If someone could tell me, how to fix this problem, or even it's be better, if there is a way to get the text of the checked/uncheck item (and even if this item is not selected), it will be great - i am will be very grateful. Here the example: expandcollapse popup#include <GUIConstants.au3> #include <GUIListView.au3> Opt("GuiOnEventMode", 1) Global Const $LVM_GETITEM = $LVM_FIRST + 5 Dim $nCurCol = -1 Dim $nSortDir = 1 Dim $bSet = 0 Dim $nCol = -1 $gui = GUICreate("TEST APP!") $listview = GUICtrlCreateListView("Column 1", 0, 50, 500, 400, $WS_VSCROLL, $LVS_EX_CHECKBOXES + $LVS_EX_GRIDLINES) GUICtrlRegisterListViewSort(-1, "LVSort") ; Register the function "SortLV" for the sorting callback GUICtrlSetOnEvent(-1, "Sort") GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "CheckBoxesEvent") GUISetOnEvent($GUI_EVENT_CLOSE, "Quit") Dim $Item[11] For $i = 1 To 10 $Item[$i] = GUICtrlCreateListViewItem($i, $listview) GUICtrlSetImage(-1, "shell32.dll", 10) Next GUISetState(@SW_SHOW, $gui) While 1 Sleep(100) WEnd Func Sort() $bSet = 0 $nCurCol = $nCol GUICtrlSendMsg($listview, $LVM_SETSELECTEDCOLUMN, GUICtrlGetState($listview), 0) DllCall("user32.dll", "int", "InvalidateRect", "hwnd", GUICtrlGetHandle($listview), "int", 0, "int", 1) EndFunc Func CheckBoxesEvent() $ItemsCount = _GUICtrlListViewGetItemCount($listview) For $i = 1 To $ItemsCount If _GUICtrlListViewGetCheckedState($listview, $i-1) = 1 Then GUICtrlSetImage($Item[$i], "shell32.dll", 8) Else GUICtrlSetImage($Item[$i], "shell32.dll", 10) EndIf Next EndFunc Func Quit() Exit EndFunc ; Our sorting callback funtion Func LVSort($hWnd, $nItem1, $nItem2, $nColumn) Local $nSort ; Switch the sorting direction If $nColumn = $nCurCol Then If Not $bSet Then $nSortDir = $nSortDir * - 1 $bSet = 1 EndIf Else $nSortDir = 1 EndIf $nCol = $nColumn $val1 = GetSubItemText($listview, $nItem1, $nColumn) $val2 = GetSubItemText($listview, $nItem2, $nColumn) $nResult = 0 ; No change of item1 and item2 positions If $val1 < $val2 Then $nResult = -1 ; Put item2 before item1 ElseIf $val1 > $val2 Then $nResult = 1 ; Put item2 behind item1 EndIf $nResult = $nResult * $nSortDir Return $nResult EndFunc ;==>LVSort ; Retrieve the text of a listview item in a specified column Func GetSubItemText($nCtrlID, $nItemID, $nColumn) Local $stLvfi = DllStructCreate("uint;ptr;int;int[2];int") DllStructSetData($stLvfi, 1, $LVFI_PARAM) DllStructSetData($stLvfi, 3, $nItemID) Local $stBuffer = DllStructCreate("char[260]") $nIndex = GUICtrlSendMsg($nCtrlID, $LVM_FINDITEM, -1, DllStructGetPtr($stLvfi)); Local $stLvi = DllStructCreate("uint;int;int;uint;uint;ptr;int;int;int;int") DllStructSetData($stLvi, 1, $LVIF_TEXT) DllStructSetData($stLvi, 2, $nIndex) DllStructSetData($stLvi, 3, $nColumn) DllStructSetData($stLvi, 6, DllStructGetPtr($stBuffer)) DllStructSetData($stLvi, 7, 260) GUICtrlSendMsg($nCtrlID, $LVM_GETITEM, 0, DllStructGetPtr($stLvi)); $sItemText = DllStructGetData($stBuffer, 1) $stLvi = 0 $stLvfi = 0 $stBuffer = 0 Return $sItemText EndFunc ;==>GetSubItemText Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
randallc Posted March 17, 2007 Share Posted March 17, 2007 hi, Here's a nearly working workaround (* needs many of the files in mu GUIListView zip from signature to work) At present, click on column 1st time only 3 times! oh well, gives the idea; Randall expandcollapse popup;SortCheck34.au3 #include "_ArrayView2D1D.au3" Opt("GuiOnEventMode", 1) Global Const $LVM_GETITEM = $LVM_FIRST + 5 Local $ar_SetCheckboxes[1], $ar_isChecked [1] $searchdir = "c:\" $gui = GUICreate("TEST APP!") ;=================================================================== _GUISetCheckBoxesPresent (2);****************************** $listview = _GUICtrlCreateListViewIndexed ("Column 1", 0, 50, 500, 400, $WS_VSCROLL, $LVS_EX_CHECKBOXES + $LVS_EX_GRIDLINES) ;=================================================================== If $i_GUISetCheckBoxes=2 Then _GUICtrlListViewSetCheckState($listview, -1, 1) ;~ _GUICtrlListViewHideColumn ($listview, _GUICtrlListViewGetSubItemsCount($listview)-1) GUICtrlSetOnEvent($listview, "Sort") GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "CheckBoxesEvent") GUISetOnEvent($GUI_EVENT_CLOSE, "Quit") Dim $Item[11] For $i = 1 To 10 $Item[$i] = _GUICtrlCreateListViewItem ($i, $listview, $searchdir, 1, 1) _GUICtrlSetImage (-1, "shell32.dll", 10) Next GUISetState(@SW_SHOW, $gui) While 1 Sleep(100) WEnd Func Sort() __GUICtrlListViewSort ($listview, -1, GUICtrlGetState($listview)) CheckBoxesEvent() EndFunc ;==>Sort Func CheckBoxesEvent() $ItemsCount = __GUICtrlListViewGetItemCount ($listview) For $i = 0 To $ItemsCount - 1 If _GUICtrlListViewGetCheckedState($listview, $i) Then _GUICtrlSetImage ($ar_LISTVIEW [$i + 1], "shell32.dll", 8) Else _GUICtrlSetImage ($ar_LISTVIEW [$i + 1], "shell32.dll", 10) EndIf Next EndFunc ;==>CheckBoxesEvent Func Quit() Exit EndFunc ;==>Quit ; Retrieve the text of a listview item in a specified column Func GetSubItemText($nCtrlID, $nItemID, $nColumn) $sItemText=__GUICtrlListViewGetItemText($nCtrlID, $nItemID, $nColumn) Return $sItemText EndFunc ;==>GetSubItemText ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
MrCreatoR Posted March 18, 2007 Author Share Posted March 18, 2007 Wow! thanks, it works. Maybe you also know, how to get "check state" event? i mean, if i check/uncheck the checkbox of listvivew item, and the item is not selected, then i would like to see a MsgBox with a text of that item... but without actualy over the all items to see if they checked or not (as i did in my example), just for one item. It is possible? Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now