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 - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -