c# - How to move item in listBox up and down? -


i have listbox1 object , contains items. have button move selected item , move selected item down. should code 2 buttons?

private void upclick() {     // if first item isn't current 1     if(listbox1.listindex > 0)     {         // add duplicate item in listbox         listbox1.additem(listbox1.text, listbox1.listindex - 1);         // make current item         listbox1.listindex = (listbox1.listindex - 2);         // delete old occurrence of item         listbox1.removeitem(listbox1.listindex + 2);     } }  private void downclick() {    // if last item isn't current 1    if((listbox1.listindex != -1) && (listbox1.listindex < listbox1.listcount - 1))    {       // add duplicate item down in listbox       listbox1.additem(listbox1.text, listbox1.listindex + 2);       // make current item       listbox1.listindex = listbox1.listindex + 2;       // delete old occurrence of item       listbox1.removeitem(listbox1.listindex - 2);    } } 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -