public void MoveSoftware(string direction) { int oldIndex = XMLSoftware.IndexOf(SelectedXMLSoftware); int newIndex; switch (direction) { case "top": newIndex = 0; break; case "up": newIndex = (oldIndex == 0) ? 0 : oldIndex - 1; break; case "down": newIndex = (oldIndex == (XMLSoftware.Count - 1)) ? XMLSoftware.Count - 1 : newIndex = oldIndex + 1; break; case "bottom": newIndex = XMLSoftware.Count - 1; break; default: newIndex = oldIndex; break; } XMLSoftware.Move(oldIndex, newIndex); }