/// <the Summary> /// forced removal of the specified item in a list control. /// If the entry list control, increased by the DataSource property. /// </ Summary> /// <param name = "LC"> list of controls to operate </ param> /// <param name = "indexToRemove"> several /// order to remove, from 0 Start. /// If no, SelectedIndex property will be used to populate /// </ param> public static void the RemoveItem (the ListControl LC, indexToRemove int = -1) { int iSelected = -1; String the mDisplay = null; Object DS = null; the IList items = null; items = (LC AS the ComboBox) .Items; { items = (lc as ListBox).Items; } if(indexToRemove == -1) { indexToRemove = lc.SelectedIndex; } if (indexToRemove != -1) { iSelected = lc.SelectedIndex; mDisplay = lc.DisplayMember; if (lc.DataSource == null) { items.RemoveAt(indexToRemove); MessageBox.Show(lc.SelectedIndex.ToString()); } else { lc.DataSource = DS; // this operation, erases items lc.DataSource = null; // the ListBox / Items in the ComboBox is IList type or array, the array also implements IList interface IList LST DS = AS IList; for (int 0 = I; I <lst.Count; I ++) { IF (I = indexToRemove)! the Items.Add (LST [I]); } } } ! IF (DS = null) { IF (LC IS the ComboBox) { the ComboBox CBB = lc as ComboBox; cbb.DataSource = items; CBB. SelectedIndex = iSelected; } if (lc is ListBox) { ListBox lb = lc as ListBox; lb.DataSource = items; lb.SelectedIndex = iSelected; } lc.DisplayMember = mDisplay; } }