/// <summary> /// Displays a list of trimmed items inside the control MyListBox. /// Returns the number of the answer at the provided list or the value 0 in the case in which /// the user cancels the answer. /// An exception is thrown if the passed list is empty or larger than LargestListSize. /// </summary> public static int ChooseStaticItem(List <string> myItems) { try { GeneralClass.CheckInRange(myItems.Count(), 1, myItems.Count()); } catch (Exception myException) { throw new ArgumentException(String.Format("The wrong number of arguments has been passed to the function ChooseItem, its size is {0} ", myItems.Count()) + myException.Message); } ChooseListItem MyForm = new ChooseListItem(); int ToReturnInt = MyForm.ChooseItem(myItems); return(ToReturnInt); }
/// <summary> /// It is assumed that the type "myType" is an enumeration type. The function displays a form in which all enumeration members are displayed. /// The function returns the string value of the chosen item, in the case in which the user aborts the selection an empty string is returned. /// </summary> /// <param name="myType"></param> /// <returns></returns> public static string ChooseItem(Type myType) { Array MyArray; MyArray = Enum.GetValues(myType); List <string> ToDisplay = new List <string>(); foreach (object ArrayItem in MyArray) { string StringToAdd = ArrayItem.ToString(); ToDisplay.Add(StringToAdd); } ChooseListItem MyForm = new ChooseListItem(); int MyNumber = MyForm.ChooseItem(ToDisplay); string ToReturn = (MyNumber == 0) ? "" : ToDisplay[MyNumber - 1]; return(ToReturn); }
/// <summary> /// Displays a list of values to be selected by the user and places the selected value inside the control. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void EventEnter(object sender, EventArgs e) { string MyKey = MyControls.Where(Element => (Element.Value.Equals(sender))).Single().Key; // .Select(Element=>Element.) //0GetEnumerator (Element => Element.Equals(sender)); // string MyTag= (sender as TextBox).Tag.ObjectToString(); //MessageBox.Show(MyTag); if (AllowedValues.Keys.Contains(MyKey) == false) { return; } List <string> MyList = AllowedValues[MyKey]; int SelectedItem = ChooseListItem.ChooseStaticItem(MyList); if (SelectedItem > 0) { (sender as TextBox).Text = MyList[SelectedItem - 1]; } }