Hello,
I need to let the user move items in a listbox, either through the mouse (drag 'n drop) or through the keyboard (eg. CTRL + up/down arrows).
EditableListBox seems to support that feature but 1) I don’t need to edit the contents and 2) it displays a toolbar.
As for RearrangeCtrl, I found no example.
Would someone have code this newbie could just copy/paste?
Thank you.
import sys,os, wx
class ListBoxFrame(wx.Frame):
def __init__(self, *args, **kwargs):
#wx.Frame.__init__(self, None, -1, 'List Box Example')
super().__init__(None, -1,title='List Box Example')
self.Centre()
self.statusbar = self.CreateStatusBar()
panel = wx.Panel(self, -1)
sizer = wx.BoxSizer(wx.VERTICAL)
#create dict, and loop to add to listbox
lb1 = wx.ListBox(panel, -1, choices=[], style=(wx.LB_SINGLE | wx.LB_ALWAYS_SB))
sampleList_dict = {'key1': 'value1', 'key2': 'value2', 'item3': 'value3'}
for k, v in sampleList_dict.items():
lb1.Append(k, v);
sizer.Add(lb1,0,wx.ALL,5)
panel.SetSizer(sizer)
self.Bind(wx.EVT_LISTBOX, self.EvtListBox, lb1)
def EvtListBox(self, event):
name = event.GetString()
data = str(event.GetClientData())
self.statusbar.SetStatusText(f"{name}: {data}")
app = wx.App()
ListBoxFrame().Show()
app.MainLoop()
–
Edit: Never mind. The listctrl supports drag 'n drop: