[wxPython-users] Moving items in a list

Rickey, Kyle W Kyle.Rickey at bakerhughes.com
Mon Mar 10 11:28:07 PDT 2008


If what you mean is moving an item up or down in a list, this code might
help out a bit. I get the text of the item I'm going to move, then
delete that item, then insert into the appropriate position.

def OnMoveUp(self, event):
	index = self.list_ctrl.GetFirstSelected()
	
	prev_item = self.list_ctrl.GetItem(index-1, 0)
	file_name = prev_item.GetText()
	
	self.list_ctrl.DeleteItem(index-1)
	self.list_ctrl.InsertStringItem(index, file_name)
	self.OnListItemSelected(event)

def OnMoveDown(self, event):
	index = self.list_ctrl.GetFirstSelected()
	
	next_item = self.list_ctrl.GetItem(index+1, 0)
	file_name = next_item.GetText()
	
	self.list_ctrl.DeleteItem(index+1)
	self.list_ctrl.InsertStringItem(index, file_name)
	self.OnListItemSelected(event)


-Kyle Rickey

-----Original Message-----
From: L. Fanchi [mailto:lorenzo.fanchi at gmail.com] 
Sent: Monday, March 10, 2008 12:10 PM
To: wxPython-users at lists.wxwidgets.org
Subject: [wxPython-users] Moving items in a list

Hello,

I'm using an EditableListBox to display a list of images. I'd like to 
add the possibility of sorting an item in the list up or down.
Now I bound the Up and Down buttons of the EditableListBox to OnUpItem 
and OnDownItem, respectively, but I'm not sure that the best way is to 
code the sorting. Changing the index won't work, I guess, since adding 1

to the index of the currently selected item will overwrite the entry 
that is currently on 'selected item + 1'. I hope I described the problem

clearly ;)

Thanks for your help!
Lorenzo

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help at lists.wxwidgets.org





More information about the wxpython-users mailing list