c# - how to exchange selected item in a list box winform -


i'm trying change 'selecteditem' in list box, 'selecteditem' staying though create new item different data. appreciate help

this.listbox1.selecteditem = new listboxitem(m_currentitem);  //next line operate event list item changed this.listbox1.items[index] = this.listbox1.selecteditem;   

i think you're doing operations in reverse order ^^

you should first add new item in list box with

this.listbox1.items.add(yournewitem); 

then can select newly inserted item with

this.listbox1.selecteditem = yournewitem; 

or, since .add method adds element in last position of items array, can use

this.listbox1.selectedindex = this.listbox1.items.count - 1 

see article reference on listbox.selecteditem property: http://msdn.microsoft.com/it-it/library/system.windows.forms.listbox.selecteditem(v=vs.110).aspx :)


Comments

Popular posts from this blog

javascript - Unusual behaviour when drawing lots of images onto a large canvas -

how can i manage url using .htaccess in php? -

javascript - Chart.js - setting tooltip z-index -