jerem488 Posted October 27, 2009 Posted October 27, 2009 (edited) Hello, I have a small problem with the option $LVS_SORTDESCENDING. Why my script don't work with this option ??? How to make the code works ?? And other question (for after in my ocde) ==> How make to delete a line in a listview and add this line deleted in an other listview... ? my code : expandcollapse popup#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <GuiConstantsEx.au3> #include <GuiListView.au3> ;~ Opt('MustDeclareVars', 1) _Main() Func _Main() Local $hListView, $Window, $Button_1, $msg, $Count $Window = GUICreate("ListView : ", 400, 300) $hListView = _GUICtrlListView_Create($Window, "", 2, 2, 350, 250, -1, $LVS_EX_GRIDLINES) ;~ $hListView = _GUICtrlListView_Create($Window, "", 2, 2, 350, 250, $LVS_SORTDESCENDING, $LVS_EX_GRIDLINES) GUISetState() $Button_1 = GUICtrlCreateButton("Add", 50, 260, 60) ; Add columns _GUICtrlListView_AddColumn($hListView, "Column 1", 100) _GUICtrlListView_AddColumn($hListView, "Column 2", 100) _GUICtrlListView_AddColumn($hListView, "Column 3", 100) _GUICtrlListView_AddItem($hListView, "Line", 0) _GUICtrlListView_AddSubItem($hListView, 0, "Line 1", 1) _GUICtrlListView_AddSubItem($hListView, 0, "Line 1", 2) ; _GUICtrlListView_AddItem($hListView, "Line", 1) _GUICtrlListView_AddSubItem($hListView, 1, "Line 2", 1) _GUICtrlListView_AddSubItem($hListView, 1, "Line 2", 2) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 $Count = _GUICtrlListView_GetItemCount($hListView) ConsoleWrite("dhfjs : " & $Count & @CRLF) _GUICtrlListView_AddItem($hListView, "Line", $Count) _GUICtrlListView_AddSubItem($hListView, $Count, "Line " & $Count + 1, 1) _GUICtrlListView_AddSubItem($hListView, $Count, "Line " & $Count + 1, 2) EndSelect WEnd GUIDelete() EndFunc ;==>_Main Thanks Edited October 27, 2009 by jerem488 Qui ose gagneWho Dares Win[left]CyberExploit[/left]
martin Posted October 27, 2009 Posted October 27, 2009 (edited) Hello, I have a small problem with the option $LVS_SORTDESCENDING. Why my script don't work with this option ??? How to make the code works ?? And other question (for after in my ocde) ==> How make to delete a line in a listview and add this line deleted in an other listview... ? my code : expandcollapse popup#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <GuiConstantsEx.au3> #include <GuiListView.au3> ;~ Opt('MustDeclareVars', 1) _Main() Func _Main() Local $hListView, $Window, $Button_1, $msg, $Count $Window = GUICreate("ListView : ", 400, 300) $hListView = _GUICtrlListView_Create($Window, "", 2, 2, 350, 250, -1, $LVS_EX_GRIDLINES) ;~ $hListView = _GUICtrlListView_Create($Window, "", 2, 2, 350, 250, $LVS_SORTDESCENDING, $LVS_EX_GRIDLINES) GUISetState() $Button_1 = GUICtrlCreateButton("Add", 50, 260, 60) ; Add columns _GUICtrlListView_AddColumn($hListView, "Column 1", 100) _GUICtrlListView_AddColumn($hListView, "Column 2", 100) _GUICtrlListView_AddColumn($hListView, "Column 3", 100) _GUICtrlListView_AddItem($hListView, "Line", 0) _GUICtrlListView_AddSubItem($hListView, 0, "Line 1", 1) _GUICtrlListView_AddSubItem($hListView, 0, "Line 1", 2) ; _GUICtrlListView_AddItem($hListView, "Line", 1) _GUICtrlListView_AddSubItem($hListView, 1, "Line 2", 1) _GUICtrlListView_AddSubItem($hListView, 1, "Line 2", 2) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 $Count = _GUICtrlListView_GetItemCount($hListView) ConsoleWrite("dhfjs : " & $Count & @CRLF) _GUICtrlListView_AddItem($hListView, "Line", $Count) _GUICtrlListView_AddSubItem($hListView, $Count, "Line " & $Count + 1, 1) _GUICtrlListView_AddSubItem($hListView, $Count, "Line " & $Count + 1, 2) EndSelect WEnd GUIDelete() EndFunc ;==>_Main Thanks First you need more than just the $LVS_SORTASCENDING style. More importantly, you have to think what is happening when you add an item to a listview which has a sorting style. Suppose you want to add a line 5. So you add an item, say fish. (I know it's 'line' in your code.) Straight away the listview is sorted so that fish is no longer line 5 but is some other line number. So when you add the subitems to line 5 you are just overwriting the subitems of a line which has now become line 5. This mod to your code gets round the problem but only to demonstrate. You should really add an item, then get the index of the item which has that item text, then add the sub items to that index. This implies that you need to have unique index texts for each item. expandcollapse popup#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <GuiConstantsEx.au3> #include <GuiListView.au3> ;~ Opt('MustDeclareVars', 1) _Main() Func _Main() Local $hListView, $Window, $Button_1, $msg, $Count $Window = GUICreate("ListView : ", 400, 300) ;$hListView = _GUICtrlListView_Create($Window, "", 2, 2, 350, 250, -1, $LVS_EX_GRIDLINES) ;$ListView1 = GUICtrlCreateListView("", 235, 115, 250, 150, BitOR($LVS_REPORT,$LVS_SINGLESEL,$LVS_SHOWSELALWAYS,$LVS_SORTASCENDING)) $hListView = _GUICtrlListView_Create($Window, "", 2, 2, 350, 250, BitOR($LVS_REPORT,$LVS_SINGLESEL,$LVS_SHOWSELALWAYS,$LVS_SORTASCENDING), $LVS_EX_GRIDLINES) GUISetState() $Button_1 = GUICtrlCreateButton("Add", 50, 260, 60) ; Add columns _GUICtrlListView_AddColumn($hListView, "Column 1", 100) _GUICtrlListView_AddColumn($hListView, "Column 2", 100) _GUICtrlListView_AddColumn($hListView, "Column 3", 100) _GUICtrlListView_AddItem($hListView, "Line0", 0) _GUICtrlListView_AddSubItem($hListView, 0, "Line 1", 1) _GUICtrlListView_AddSubItem($hListView, 0, "Line 1", 2) ; _GUICtrlListView_AddItem($hListView, "Line1", 1) _GUICtrlListView_AddSubItem($hListView, 1, "Line 2", 1) _GUICtrlListView_AddSubItem($hListView, 1, "Line 2", 2) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 $Count = _GUICtrlListView_GetItemCount($hListView) ConsoleWrite("dhfjs : " & $Count & @CRLF) _GUICtrlListView_AddItem($hListView, "Line"& $Count, $Count) _GUICtrlListView_AddSubItem($hListView, $Count, "Line " & $Count + 1, 1) _GUICtrlListView_AddSubItem($hListView, $Count, "Line " & $Count + 1, 2) EndSelect WEnd GUIDelete() EndFunc ;==>_Main Edited October 27, 2009 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
jerem488 Posted October 28, 2009 Author Posted October 28, 2009 First you need more than just the $LVS_SORTASCENDING style. More importantly, you have to think what is happening when you add an item to a listview which has a sorting style. Suppose you want to add a line 5. So you add an item, say fish. (I know it's 'line' in your code.) Straight away the listview is sorted so that fish is no longer line 5 but is some other line number. So when you add the subitems to line 5 you are just overwriting the subitems of a line which has now become line 5. This mod to your code gets round the problem but only to demonstrate. You should really add an item, then get the index of the item which has that item text, then add the sub items to that index. This implies that you need to have unique index texts for each item. expandcollapse popup#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <GuiConstantsEx.au3> #include <GuiListView.au3> ;~ Opt('MustDeclareVars', 1) _Main() Func _Main() Local $hListView, $Window, $Button_1, $msg, $Count $Window = GUICreate("ListView : ", 400, 300) ;$hListView = _GUICtrlListView_Create($Window, "", 2, 2, 350, 250, -1, $LVS_EX_GRIDLINES) ;$ListView1 = GUICtrlCreateListView("", 235, 115, 250, 150, BitOR($LVS_REPORT,$LVS_SINGLESEL,$LVS_SHOWSELALWAYS,$LVS_SORTASCENDING)) $hListView = _GUICtrlListView_Create($Window, "", 2, 2, 350, 250, BitOR($LVS_REPORT,$LVS_SINGLESEL,$LVS_SHOWSELALWAYS,$LVS_SORTASCENDING), $LVS_EX_GRIDLINES) GUISetState() $Button_1 = GUICtrlCreateButton("Add", 50, 260, 60) ; Add columns _GUICtrlListView_AddColumn($hListView, "Column 1", 100) _GUICtrlListView_AddColumn($hListView, "Column 2", 100) _GUICtrlListView_AddColumn($hListView, "Column 3", 100) _GUICtrlListView_AddItem($hListView, "Line0", 0) _GUICtrlListView_AddSubItem($hListView, 0, "Line 1", 1) _GUICtrlListView_AddSubItem($hListView, 0, "Line 1", 2) ; _GUICtrlListView_AddItem($hListView, "Line1", 1) _GUICtrlListView_AddSubItem($hListView, 1, "Line 2", 1) _GUICtrlListView_AddSubItem($hListView, 1, "Line 2", 2) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 $Count = _GUICtrlListView_GetItemCount($hListView) ConsoleWrite("dhfjs : " & $Count & @CRLF) _GUICtrlListView_AddItem($hListView, "Line"& $Count, $Count) _GUICtrlListView_AddSubItem($hListView, $Count, "Line " & $Count + 1, 1) _GUICtrlListView_AddSubItem($hListView, $Count, "Line " & $Count + 1, 2) EndSelect WEnd GUIDelete() EndFunc ;==>_Main First, thank you very much for the explanation. But the problem is that I can to have the same text index for several lines. Qui ose gagneWho Dares Win[left]CyberExploit[/left]
martin Posted October 28, 2009 Posted October 28, 2009 First, thank you very much for the explanation.But the problem is that I can to have the same text index for several lines.No problem.One way:First create the new item with text which is garanteed to make it the last of the sorted list. Say 'zzzzzzz999'. Then add the subitems, then change the text of that item to the the required text. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
jerem488 Posted October 30, 2009 Author Posted October 30, 2009 No problem.One way:First create the new item with text which is garanteed to make it the last of the sorted list. Say 'zzzzzzz999'. Then add the subitems, then change the text of that item to the the required text.Can you give me an example please...Thank you Qui ose gagneWho Dares Win[left]CyberExploit[/left]
Moderators Melba23 Posted October 30, 2009 Moderators Posted October 30, 2009 jerem488, martin's suggestion is a very clever piece of lateral thinking Here it is working with comments: expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <GuiConstantsEx.au3> #include <GuiListView.au3> ;~ Opt('MustDeclareVars', 1) _Main() Func _Main() Local $hListView, $Window, $Button_1, $msg, $Count Local $aLV_Col_Sort[3] = [False] ; Needed for the resort - look in the Help file for _GUICtrlListView_SimpleSort $Window = GUICreate("ListView : ", 400, 300) ;$hListView = _GUICtrlListView_Create($Window, "", 2, 2, 350, 250, -1, $LVS_EX_GRIDLINES) ;$ListView1 = GUICtrlCreateListView("", 235, 115, 250, 150, BitOR($LVS_REPORT,$LVS_SINGLESEL,$LVS_SHOWSELALWAYS,$LVS_SORTASCENDING)) $hListView = _GUICtrlListView_Create($Window, "", 2, 2, 350, 250, BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_SORTASCENDING), $LVS_EX_GRIDLINES) GUISetState() $Button_1 = GUICtrlCreateButton("Add", 50, 260, 60) ; Add columns _GUICtrlListView_AddColumn($hListView, "Column 1", 100) _GUICtrlListView_AddColumn($hListView, "Column 2", 100) _GUICtrlListView_AddColumn($hListView, "Column 3", 100) _GUICtrlListView_AddItem($hListView, "AAAA1", 0) _GUICtrlListView_AddSubItem($hListView, 0, "AAAA2", 1) _GUICtrlListView_AddSubItem($hListView, 0, "AAAA3", 2) ; _GUICtrlListView_AddItem($hListView, "CCCC1", 1) _GUICtrlListView_AddSubItem($hListView, 1, "CCCC2", 1) _GUICtrlListView_AddSubItem($hListView, 1, "CCCC3", 2) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 ; Add new line using a false item name to fool the auto-sort $Count = _GUICtrlListView_GetItemCount($hListView) ConsoleWrite("Index : " & $Count & @CRLF) _GUICtrlListView_AddItem($hListView, "ZZZZ1", $Count) ; Add the correct sub items _GUICtrlListView_AddSubItem($hListView, $Count, "BBBB2", 1) _GUICtrlListView_AddSubItem($hListView, $Count, "BBBB3", 2) Sleep(2000) ; Now correct the item name _GUICtrlListView_SetItemText($hListView, $Count, "BBBB1", 0) Sleep(2000) ; And re-sort the listview _GUICtrlListView_SimpleSort($hListView, $aLV_Col_Sort, 0) EndSelect WEnd GUIDelete() EndFunc ;==>_Main M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
jerem488 Posted October 30, 2009 Author Posted October 30, 2009 jerem488, martin's suggestion is a very clever piece of lateral thinking Here it is working with comments: expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <GuiConstantsEx.au3> #include <GuiListView.au3> ;~ Opt('MustDeclareVars', 1) _Main() Func _Main() Local $hListView, $Window, $Button_1, $msg, $Count Local $aLV_Col_Sort[3] = [False] ; Needed for the resort - look in the Help file for _GUICtrlListView_SimpleSort $Window = GUICreate("ListView : ", 400, 300) ;$hListView = _GUICtrlListView_Create($Window, "", 2, 2, 350, 250, -1, $LVS_EX_GRIDLINES) ;$ListView1 = GUICtrlCreateListView("", 235, 115, 250, 150, BitOR($LVS_REPORT,$LVS_SINGLESEL,$LVS_SHOWSELALWAYS,$LVS_SORTASCENDING)) $hListView = _GUICtrlListView_Create($Window, "", 2, 2, 350, 250, BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_SORTASCENDING), $LVS_EX_GRIDLINES) GUISetState() $Button_1 = GUICtrlCreateButton("Add", 50, 260, 60) ; Add columns _GUICtrlListView_AddColumn($hListView, "Column 1", 100) _GUICtrlListView_AddColumn($hListView, "Column 2", 100) _GUICtrlListView_AddColumn($hListView, "Column 3", 100) _GUICtrlListView_AddItem($hListView, "AAAA1", 0) _GUICtrlListView_AddSubItem($hListView, 0, "AAAA2", 1) _GUICtrlListView_AddSubItem($hListView, 0, "AAAA3", 2) ; _GUICtrlListView_AddItem($hListView, "CCCC1", 1) _GUICtrlListView_AddSubItem($hListView, 1, "CCCC2", 1) _GUICtrlListView_AddSubItem($hListView, 1, "CCCC3", 2) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 ; Add new line using a false item name to fool the auto-sort $Count = _GUICtrlListView_GetItemCount($hListView) ConsoleWrite("Index : " & $Count & @CRLF) _GUICtrlListView_AddItem($hListView, "ZZZZ1", $Count) ; Add the correct sub items _GUICtrlListView_AddSubItem($hListView, $Count, "BBBB2", 1) _GUICtrlListView_AddSubItem($hListView, $Count, "BBBB3", 2) Sleep(2000) ; Now correct the item name _GUICtrlListView_SetItemText($hListView, $Count, "BBBB1", 0) Sleep(2000) ; And re-sort the listview _GUICtrlListView_SimpleSort($hListView, $aLV_Col_Sort, 0) EndSelect WEnd GUIDelete() EndFunc ;==>_Main M23 The code is it good for the option $LVS_SORTDESCENDING ?? Because, at the start, I would use this option, and not $LVS_SORTASCENDING !! So, if I change the option (ASCENDING ==> to descending) the code don't work correctly. Qui ose gagneWho Dares Win[left]CyberExploit[/left]
Moderators Melba23 Posted October 30, 2009 Moderators Posted October 30, 2009 jerem488, Just reverse the logic and make sure the first item name is now BEFORE the last item so it still goes at the end of the list. expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <GuiConstantsEx.au3> #include <GuiListView.au3> ;~ Opt('MustDeclareVars', 1) _Main() Func _Main() Local $hListView, $Window, $Button_1, $msg, $Count Local $aLV_Col_Sort[3] = [False] ; Needed for the resort - look in the Help file for _GUICtrlListView_SimpleSort $Window = GUICreate("ListView : ", 400, 300) ;$hListView = _GUICtrlListView_Create($Window, "", 2, 2, 350, 250, -1, $LVS_EX_GRIDLINES) ;$ListView1 = GUICtrlCreateListView("", 235, 115, 250, 150, BitOR($LVS_REPORT,$LVS_SINGLESEL,$LVS_SHOWSELALWAYS,$LVS_SORTASCENDING)) $hListView = _GUICtrlListView_Create($Window, "", 2, 2, 350, 250, BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_SORTDESCENDING), $LVS_EX_GRIDLINES) GUISetState() $Button_1 = GUICtrlCreateButton("Add", 50, 260, 60) ; Add columns _GUICtrlListView_AddColumn($hListView, "Column 1", 100) _GUICtrlListView_AddColumn($hListView, "Column 2", 100) _GUICtrlListView_AddColumn($hListView, "Column 3", 100) _GUICtrlListView_AddItem($hListView, "CCCC1", 0) _GUICtrlListView_AddSubItem($hListView, 0, "CCCC2", 1) _GUICtrlListView_AddSubItem($hListView, 0, "CCCC3", 2) ; While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 ; Add new line using a false item name to fool the auto-sort $Count = _GUICtrlListView_GetItemCount($hListView) ConsoleWrite("Index : " & $Count & @CRLF) _GUICtrlListView_AddItem($hListView, "11111", $Count) ; Add the correct sub items _GUICtrlListView_AddSubItem($hListView, $Count, "BBBB2", 1) _GUICtrlListView_AddSubItem($hListView, $Count, "BBBB3", 2) Sleep(2000) ; Now correct the item name _GUICtrlListView_SetItemText($hListView, $Count, "BBBB1", 0) Sleep(2000) ; And re-sort the listview _GUICtrlListView_SimpleSort($hListView, $aLV_Col_Sort, 0) EndSelect WEnd GUIDelete() EndFunc ;==>_Main M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
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