ReFran Posted October 26, 2005 Posted October 26, 2005 Hello, I've a listview GUI, where I gather with the FileOpenDialog some Files. I can sort it ascending or descending. But the files have to be in a special order for later batch processing (merge PDFs). Is there something like $LVS_EX_RowDragDrop (comparable to $LVS_EX_HEADERDRAGDROP) or a _GUICtrlListViewMoveItem, whichs moves a complett row. Thanks in advance (and also for the other UDFs, which saves much work), Reinhard
GaryFrost Posted October 26, 2005 Posted October 26, 2005 (edited) Hello,I've a listview GUI, where I gather with the FileOpenDialog some Files. I can sort it ascending or descending. But the files have to be in a special order for later batch processing (merge PDFs).Is there something like $LVS_EX_RowDragDrop (comparable to $LVS_EX_HEADERDRAGDROP)or a _GUICtrlListViewMoveItem, whichs moves a complett row.Thanks in advance (and also for the other UDFs, which saves much work),Reinhard Here's the code to do what you want, in working on this I found a bug in the delete item, the correction for the include has been submitted, i'll include that function also here for you to correct in your include fileexpandcollapse popup#include <GuiConstants.au3> #include <GuiListView.au3> opt('MustDeclareVars', 1) Dim $listview, $Btn_Move, $Btn_Exit, $msg, $ret, $ipt_from, $ipt_to GUICreate("ListView Move Item Text", 392, 322) $listview = GUICtrlCreateListView("col1|col2|col3", 40, 30, 310, 149) GUICtrlCreateListViewItem("line1|data1|more1", $listview) GUICtrlCreateListViewItem("line2|data2|more2", $listview) GUICtrlCreateListViewItem("line3|data3|more3", $listview) GUICtrlCreateListViewItem("line4|data4|more4", $listview) GUICtrlCreateListViewItem("line5|data5|more5", $listview) $Btn_Move = GUICtrlCreateButton("Move data", 75, 200, 90, 40) GUICtrlCreateLabel("From", 170, 215) $ipt_from = GUICtrlCreateInput("0", 200, 215, 30, 20, $ES_NUMBER) GUICtrlCreateLabel("To", 240, 215) $ipt_to = GUICtrlCreateInput("0", 260, 215, 30, 20, $ES_NUMBER) $Btn_Exit = GUICtrlCreateButton("Exit", 300, 260, 70, 30) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $Btn_Exit ExitLoop Case $msg = $Btn_Move _GUICtrlListViewMoveItem($listview, GUICtrlRead($ipt_from), GUICtrlRead($ipt_to)) EndSelect WEnd Exit Func _GUICtrlListViewMoveItem(ByRef $h_listview, $i_from = 0, $i_to = 0) Local $Max = _GUICtrlListViewGetItemCount ($h_listview) - 1 Local $ret, $m_item $i_from = Int($i_from) $i_to = Int($i_to) If $i_from >= 0 And $i_from <= $Max And $i_to >= 0 And $i_to <= $Max And $i_from <> $i_to Then $m_item = _GUICtrlListViewGetItemText ($h_listview, $i_from) If $m_item <> $LV_ERR Then $ret = _GUICtrlListViewInsertItem ($h_listview, $i_to, $m_item) If $i_to < $i_from And $ret <> $LV_ERR Then $ret = _GUICtrlListViewDeleteItem ($h_listview, $i_from + 1) Else $ret = _GUICtrlListViewDeleteItem ($h_listview, $i_from) EndIf EndIf EndIf Return $ret EndFunc ;==>_GUICtrlListViewMoveItemFunc _GUICtrlListViewDeleteItem($h_listview, $i_index) Dim $control_ID, $ID_Check _GUICtrlListViewSetItemSelState($h_listview, $i_index) $control_ID = GUICtrlRead($h_listview) GUICtrlDelete($control_ID) _GUICtrlListViewSetItemSelState($h_listview, $i_index) $ID_Check = GUICtrlRead($h_listview) _GUICtrlListViewSetItemSelState($h_listview, $i_index, 0) If $control_ID <> $ID_Check Then Return 1 Else Return GUICtrlSendMsg($h_listview, $LVM_DELETEITEM, $i_index, 0) EndIf EndFunc ;==>_GUICtrlListViewDeleteItemGary Edited October 26, 2005 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
ReFran Posted October 26, 2005 Author Posted October 26, 2005 Thank you very much Gary, exactly what I need. It would have been at least one day for me to get it somehow working. At the moment I'm try also to understand your wonderful Listview UDFs, so that I'm also be able to write some cool code already at breakfast time. Have a nice day, Reinhard
wiredbits Posted October 27, 2005 Posted October 27, 2005 Func _GUICtrlListViewDeleteItem($h_listview, $i_index) Dim $control_ID, $ID_Check _GUICtrlListViewSetItemSelState($h_listview, $i_index) $control_ID = GUICtrlRead($h_listview) GUICtrlDelete($control_ID) _GUICtrlListViewSetItemSelState($h_listview, $i_index) $ID_Check = GUICtrlRead($h_listview) _GUICtrlListViewSetItemSelState($h_listview, $i_index, 0) If $control_ID <> $ID_Check Then Return 1 Else Return GUICtrlSendMsg($h_listview, $LVM_DELETEITEM, $i_index, 0) EndIf EndFunc ;==>_GUICtrlListViewDeleteItemGary HI Does Autoit release any resources if you use GUICtrlSendMsg($h_listview, $LVM_DELETEITEM instead of GUiCtrlDelete? I have no idea how Autito tracks resources, any docs on internals around? While i am asking, does Autoit delete child controls in treeview if you delete parent? Thanks Jim
ReFran Posted October 27, 2005 Author Posted October 27, 2005 (edited) HI Does Autoit release any resources if you use GUICtrlSendMsg($h_listview, $LVM_DELETEITEM instead of GUiCtrlDelete? I have no idea how Autito tracks resources, any docs on internals around? While i am asking, does Autoit delete child controls in treeview if you delete parent? Thanks JimI don't know how that fits to the topic, but however:1.The resources you find in the AutoIT help files. Look into your \beta folder and especially look into the UDF3 help file.2. Normaly you don't see a child without a natural mother, or? I know only of one historical special case, reported in a bigger book, called ..... HTH, Reinhard Edited October 27, 2005 by ReFran
eVAPor8 Posted November 30, 2005 Posted November 30, 2005 2. Normaly you don't see a child without a natural mother, or? I know only of one historical special case, reported in a bigger book, called .....I laughed out loud when I read that! So what book are you referring to... 'cos it ain't The Bible...
wiredbits Posted November 30, 2005 Posted November 30, 2005 I don't know how that fits to the topic, but however:1.The resources you find in the AutoIT help files. Look into your \beta folder and especially look into the UDF3 help file.2. Normaly you don't see a child without a natural mother, or? I know only of one historical special case, reported in a bigger book, called ..... HTH, Reinhard 1. it fit since gary was using $LVM_DELETEITEM instead of GUICtrlDelete 2. look around, nature will delete parents and childern will continue. cheers Jim
GaryFrost Posted November 30, 2005 Posted November 30, 2005 1. it fit since gary was using $LVM_DELETEITEM instead of GUICtrlDelete2. look around, nature will delete parents and childern will continue.cheersJim The answer would be no, but I have to have that in there in case someone inserts an item using external method SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
ReFran Posted November 30, 2005 Author Posted November 30, 2005 (edited) @Jim ... with point 2) you are right in the basic meaning of the questioner. Therefore I edited it to "natural" mother, see "Lukas, Kapitel I, Vers 25". Reinhard PS: With this answer I got (became) Advanced Member. Isn't it creazy? Edited November 30, 2005 by ReFran
ReFran Posted December 1, 2005 Author Posted December 1, 2005 I laughed out loud when I read that! So what book are you referring to... 'cos it ain't The Bible... Hi,I wanted to write "Neues Testament" (the helpfile for the christian people), but didn't find my translator.The Bibel is also OK!Have a nice evening, Reinhard
ReFran Posted December 1, 2005 Author Posted December 1, 2005 (edited) OK, after playing with words, here some code to play with. Mostly from Gary (I think). I put the move up/down and the basic context menu in. Have fun, Reinhard expandcollapse popup;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; LV_FolderFiles_SortSelMoveDel ;; Get Files from Folder and Sort ;; Sort LV-Items by clicking on header and move up/down intems by button ;; LV-Files/Folder/Sorting and .. and ... and examples from Gary ;; Wingdings Buttons from BigDod ;; Puzzled together from ReFran ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #include <GuiConstants.au3> #include <GuiListView.au3> ;opt('MustDeclareVars', 1) Dim $listview, $font, $Btn_MoveUp, $Btn_Movedn, $Btn_Exit, $msg, $Status, $Btn_Insert, $ret, $Input_Index, $pos GUICreate("ListView Sort", 392, 322) $listview = GUICtrlCreateListView("File|Size|Type|Date Created|Date Modified", 40, 30, 310, 149, -1, BitOR($LVS_EX_REGIONAL, $LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES)) _GUICtrlListViewSetColumnWidth ($listview, 0, 75) _GUICtrlListViewSetColumnWidth ($listview, 1, 75) _GUICtrlListViewSetColumnWidth ($listview, 2, 75) _GUICtrlListViewSetColumnWidth ($listview, 3, 75) _GUICtrlListViewSetColumnWidth ($listview, 4, 75) $Menlv_context = GUICtrlCreateContextMenu($listview) $Menlv_DelFile = GUICtrlCreateMenuitem("Delete from List",$MenLV_context) $font="Wingdings" $Btn_MoveUp = GUICtrlCreateButton("é", 150, 190, 30, 30) GUICtrlSetFont (-1,18, 400, 1, $font) $Btn_MoveDn = GUICtrlCreateButton("ê", 200, 190, 30, 30) GUICtrlSetFont (-1,18, 400, 1, $font) $Btn_Exit = GUICtrlCreateButton("Exit", 300, 260, 70, 30) $Status = GUICtrlCreateLabel("", 0, 302, 392, 20, BitOR($SS_SUNKEN, $SS_CENTER)) GUISetState() _PopulateListView($listview) Dim $B_DESCENDING[_GUICtrlListViewGetSubItemsCount ($listview) ] While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $Btn_Exit ExitLoop Case $msg = $listview ; sort the list by the column header clicked on _GUICtrlListViewSort ($listview, $B_DESCENDING, GUICtrlGetState($listview)) Case $msg = $GUI_EVENT_PRIMARYDOWN $pos = GUIGetCursorInfo() If ($pos[4] == $listview) Then GUICtrlSetData($Status, "Current Index Selected: " & _GUICtrlListViewGetCurSel ($listview)) EndIf Case $msg = $Btn_MoveUP if _GUICtrlListViewGetSelectedCount ($listview) = 0 then msgBox(0,"","Nothing selected") Else _GUICtrlListViewMoveItem($listview, _GUICtrlListViewGetCurSel($listview), _GUICtrlListViewGetCurSel($listview)-1) EndIf Case $msg = $Btn_MoveDN if _GUICtrlListViewGetSelectedCount ($listview) = 0 then msgBox(0,"","Nothing selected") Else _GUICtrlListViewMoveItem($listview, _GUICtrlListViewGetCurSel($listview), _GUICtrlListViewGetCurSel($listview)+2) EndIf Case $msg = $MenLv_DelFile if _GUICtrlListViewGetSelectedCount ($listview) = 0 then msgBox(0,"","Nothing selected") Else _GUICtrlListViewDeleteItemsSelected ($listview) EndIf EndSelect WEnd Exit Func _PopulateListView(ByRef $listview) Local $startdir, $var, $search, $file, $item, $attrib, $time $startdir = @MyDocumentsDir $var = FileSelectFolder("Choose a folder.", $startdir) If $var <> "" Then FileChangeDir($var) ; Shows the filenames of all files in the current directory. $search = FileFindFirstFile("*.*") ; Check if the search was successful If $search = -1 Then Return EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop $item = $file & "|" $attrib = FileGetAttrib($file) If Not @error Then If StringInStr($attrib, "D") Then $item = $file & "||Directory|" Else $item = $file & "|" & FileGetSize($file) & " bytes" & "|File|" EndIf EndIf $time = FileGetTime($file, 1) If Not @error Then $item = $item & $time[0] & "/" & $time[1] & "/" & $time[2] & " " If Int($time[3]) > 12 Then $item = $item & $time[3] - 12 & ":" & $time[4] & " PM|" Else $item = $item & $time[3] & ":" & $time[4] & " AM|" EndIf EndIf $time = FileGetTime($file) If Not @error Then $item = $item & $time[0] & "/" & $time[1] & "/" & $time[2] & " " If Int($time[3]) > 12 Then $item = $item & $time[3] - 12 & ":" & $time[4] & " PM" Else $item = $item & $time[3] & ":" & $time[4] & " AM" EndIf EndIf GUICtrlCreateListViewItem($item, $listview) WEnd ; Close the search handle FileClose($search) EndIf EndFunc;==>_PopulateListView ;;;;;;;;;;;;;LV-Move items For MoveUp and DN buttons;;;;;;;;;;;;;;;;;;;;;;;; Func _GUICtrlListViewMoveItem(ByRef $h_listview, $i_from = 0, $i_to = 0) Local $Max = _GUICtrlListViewGetItemCount ($h_listview) Local $ret, $m_item $i_from = Int($i_from) $i_to = Int($i_to) ;msgBox(0,"",$max &" " &$i_from &"->" &$i_to) If $i_from >= 0 And $i_from <= $Max And $i_to >= 0 And $i_to <= $Max And $i_from <> $i_to Then $m_item = _GUICtrlListViewGetItemText ($h_listview, $i_from) ;msgBox(0,"","Mitem " &$m_item) If $m_item <> $LV_ERR Then $ret = _GUICtrlListViewInsertItem ($h_listview, $i_to, $m_item) If $i_from > $i_to And $ret <> $LV_ERR Then $xup = _GUICtrlListViewDeleteItem ($h_listview, $i_from +1) _GUICtrlListViewSetItemSelState($h_listview, $i_to, 1) Else $xdown = _GUICtrlListViewDeleteItem ($h_listview, $i_from) _GUICtrlListViewSetItemSelState($h_listview, $i_to-1, 1) EndIf EndIf EndIf Return $ret EndFunc;==>_GUICtrlListViewMoveItem Edited December 1, 2005 by ReFran
objectivescott Posted December 31, 2005 Posted December 31, 2005 Can anyone give me a simple way to sort a GuiCtrlCreateListView "listbox" alpabetically? I'm reading in a number of rows and columns into the "listbox" from a file (not necessarily in alphabetical order). I have looked at the example provided in the help and it refers to $LVS_SORTDECENDING...which only gives me errors. I noticed there is nothing to autosorting a GuiCtrlCreateList...works great all the time no matter what you do! Does anyone have a simple way to do this?
ReFran Posted January 2, 2006 Author Posted January 2, 2006 Can anyone give me a simple way to sort a GuiCtrlCreateListView "listbox" alpabetically? ....Mmmh,I don't understand this question. The above example show you all what you need for sorting listview items (click on the col headers for alpha up/down sort). The function "Func _PopulateListView(ByRef $listview)" you may replace with your own and slightly change some other statements.HTH, Reinhard
objectivescott Posted January 5, 2006 Posted January 5, 2006 Thank you for the response. I took a second good look at the example above, however it refers to #include <guilistview.au3>. I don't have that in my include folder. Is that a standard "include" that somebody makes and everyone uses in general? If so, where do I get it?Thanks,ScottMmmh,I don't understand this question. The above example show you all what you need for sorting listview items (click on the col headers for alpha up/down sort). The function "Func _PopulateListView(ByRef $listview)" you may replace with your own and slightly change some other statements.HTH, Reinhard
GaryFrost Posted January 5, 2006 Posted January 5, 2006 It's standard with the beta SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
objectivescott Posted January 5, 2006 Posted January 5, 2006 Okay, so I guess I should be using the beta eh? Is that what the rest of the folks here use? Also, what do you think is the most efficient way to clear all listviewitem entries in a listbox?It's standard with the beta
ReFran Posted January 6, 2006 Author Posted January 6, 2006 (edited) >>"Is that what the rest of the folks here use?" Yes. >>"Also, what do you think is the most efficient way to clear all listviewitem entries in a listbox?" If you have installed the beta you will find a help file for the UDFs in the ...\beta dir. There you will find "GUI Treeview Management". Under this you will see "_GUICtrlTreeViewDeleteAllItems". That .. "is the most efficient way", (at least) because you have to write only one statement. HTH, Reinhard Edit: Oh, replace Treeview with Listview, then it is correct. Edited January 6, 2006 by ReFran
objectivescott Posted January 6, 2006 Posted January 6, 2006 Hey. I really appreciate your guidance. I guess I'll break down and start using the Beta.>>"Is that what the rest of the folks here use?"Yes.>>"Also, what do you think is the most efficient way to clear all listviewitem entries in a listbox?"If you have installed the beta you will find a help file for the UDFs in the ...\beta dir.There you will find "GUI Treeview Management".Under this you will see "_GUICtrlTreeViewDeleteAllItems".That .. "is the most efficient way", (at least) because you have to write only one statement.HTH, Reinhard
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