Jump to content

ListView: Drag and drop to change items order


Azevedo
 Share

Go to solution Solved by MikahS,

Recommended Posts

Hi.

Is it possible to change the order of items in a listBox by drag'n'drop them?

By dragging an item, the mouse cursor changes (dragging). But it does nothing.

Thanks!

;http://brugbart.com/create-list-view-autoit

 #include <GUIConstantsEx.au3>
 #include <GuiListView.au3>

 Opt("GUIOnEventMode", 1)

MainGUI()

 ; ----- GUIs
Func MainGUI()
  Global $listview
  $listGUI = GUICreate("AutoIt list item GUI", 400, 200, 100, 200, -1)
  GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close_Main")
  $listview = GUICtrlCreateListView("Users", 10, 10, 200, 150)
  _GUICtrlListView_SetColumnWidth($listview, 0, 150)

  GUICtrlCreateListViewItem("First Item", $listview)
  GUICtrlCreateListViewItem("Second Item", $listview)
  GUICtrlCreateListViewItem("Third Item", $listview)

  $BtnAdd = GUICtrlCreateButton("Add Item", 10, 165, 80, 30)
  GUICtrlSetOnEvent(-1, "Addi")
  $BtnSelect = GUICtrlCreateButton("Select", 100, 165, 80, 30)
  GUICtrlSetOnEvent(-1, "SelectItem")

  GUISetState()
  
  While 1
    Sleep(10)
  WEnd
EndFunc
 ; ///// Functions
Func Addi()
   $sToAdd = InputBox("Add", "Enter Item Name", "")
   GUICtrlCreateListViewItem($sToAdd, $listview)
EndFunc

Func SelectItem()
  $sItem = GUICtrlRead(GUICtrlRead($listview))
  $sItem = StringTrimRight($sItem, 1) ; Will remove the pipe "|" from the end of the string
  MsgBox(0, "Selected Item", $sItem)
EndFunc
  
Func On_Close_Main()
   Exit
EndFunc
Link to comment
Share on other sites

  • Solution

Have a look at Melba23's UDF >GUIListViewEx :D

Taken from the description:

Permits insertion, deletion, moving, dragging, sorting and editing of items within activated ListViews

It is a great library, and I use it almost anytime I use ListViews :)

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

  • Moderators

Azevedo,

Look at my GUIListViewEx UDF (the link is in my sig) which allows you to drag items within and between ListViews - as well as lot of other interesting things! ;)

M23

Edit: Or in MikahS' post above! :D

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Azevedo,

User Defined Function. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Azevedo,

Glad you like it. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 1 year later...

Here is an example that doesn't use somebody else's UDF.

#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <misc.au3>
Opt("GUIOnEventMode", 1);

GUICreate("", 200, 400)
GUISetState(@SW_SHOW)

$Listview = GUICtrlCreateListView("filename", 0, 0, 200, 400);
_GUICtrlListView_SetExtendedListViewStyle($Listview, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))

GUISetOnEvent($GUI_EVENT_CLOSE, "_Close")
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN,"_Arrange_List")

_Create_List()

While True
    Sleep(200)
WEnd

Func _Create_List()
    Local $Item
    While $Item <> "XXXXXXXX"
        $Item = $Item & "X"
        GUICtrlCreateListViewItem($Item, $Listview)
    Wend
Endfunc

Func _Arrange_List()
    $Selected = _GUICtrlListView_GetHotItem($Listview)
    If $Selected = -1 then Return
    While _IsPressed(1)
    WEnd
    $Dropped = _GUICtrlListView_GetHotItem($Listview)
    If $Dropped > -1 then
        _GUICtrlListView_BeginUpdate($Listview)
        If $Selected < $Dropped Then
            _GUICtrlListView_InsertItem($Listview, _GUICtrlListView_GetItemTextString($Listview, $Selected), $Dropped + 1)
            _GUICtrlListView_SetItemChecked($Listview, $Dropped + 1, _GUICtrlListView_GetItemChecked($Listview, $Selected))
            _GUICtrlListView_DeleteItem($Listview, $Selected)
        ElseIf $Selected > $Dropped Then
            _GUICtrlListView_InsertItem($Listview, _GUICtrlListView_GetItemTextString($Listview, $Selected), $Dropped)
            _GUICtrlListView_SetItemChecked($Listview, $Dropped, _GUICtrlListView_GetItemChecked($Listview, $Selected + 1))
            _GUICtrlListView_DeleteItem($Listview, $Selected + 1)
        EndIf
        _GUICtrlListView_EndUpdate($Listview)
    EndIf
EndFunc

Func _Close()
    Exit(0)
EndFunc

 

 

 

Link to comment
Share on other sites

  • 1 year later...

I have for the first time seen this library and tested the example code listed. It seems GuiListView.au3 is part of the mainstream production version.

Can this be used with a list that is in a file or ini file or a registry record?

Once I re-org the list, I am guessing it can be used to write that new list order to the source record, but I am looking to find some example code that does that.

My goal is to create an Application that provides a list interface that allows adding an item to the list, OR down arrow to select from the list..

Possibly using this instead of a down select dialog(combobox) would be a better method. I do need to allow users to re-order items so it can be easier to find an item according to how each user thinks and operates. A possible alternative is to calculate usage weight for each time an item is selected, and move it up the list the more it is selected..

Using the check mark to select one is very useful as users will be selecting just one item at the time of use..
BUT, this method does not provide a way to manage the list, add items and delete items.

I may be asking to much, but that is my goal.

Link to comment
Share on other sites

  • Moderators

unixman427,

My GUIListViewEx UDF will certainly allow you to drag items within the ListView and also to read the new order, which can then be rewritten to the file used to load the ListView when next reloaded.

if you can give me an idea of what you want to have as an initial load from file I will see what I can come up with as an example for you.

M23

Edit: Welcome to the AutoIt forum, by the way.

 

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...