/// <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); }