Beispiel #1
0
        /// <summary>
        /// Selects or clears the selection for the specified item in a System.Windows.Forms.ListBox.
        /// </summary>
        /// <param name="lstBox">The listbox parent.</param>
        /// <param name="index">The index of the item.</param>
        /// <param name="value">The value to set to selected property.</param>
        public static void SetSelected(System.Windows.Forms.ListBox lstBox, int index, bool value)
        {
            if ((index < -1) || (index >= lstBox.Items.Count))
                throw new Exception("Invalid property value");

            if (lstBox.GetSelected(index) != value)
            {
                if ((value) && ((lstBox.SelectionMode == SelectionMode.MultiSimple) || (lstBox.SelectionMode == SelectionMode.MultiExtended)))
                {
                    if (selectedIndexList.ContainsKey(lstBox))
                        selectedIndexList[lstBox] = index;
                    else
                        throw new Exception("SelectedIndex property not stored for a MultiSelect ListBox, "
                            + "please add a ListBoxHelper to the form and set the property SelectionMode again");
                }

                lstBox.SetSelected(index, value);
            }
        }
Beispiel #2
0
 /// <summary>
 ///  Returns a value indicating whether the specified item is selected.
 /// </summary>
 /// <param name="lstBox">The listbox to test.</param>
 /// <param name="index">The index of the item to query if it is selected.</param>
 /// <returns>True if the item is selected.</returns>
 public static bool GetSelected(System.Windows.Forms.ListBox lstBox, int index)
 {
     return lstBox.GetSelected(index);
 }