Hi,
I am trying to take a string, seperate it into 3 parts and parse one of them into a combobox only if it has that value in it.
So...
The values are stored in an Enum and are displayed in the combobox. on selected index changed the first combobox's text is taken into 3 parts. FirstName,
LastName and Position
FirstName and LastName are put into textboxes and I want the position to be selected automatically from a Combo Box
This is the code I am using to split the string:
private void SelectEmployeeInfo() { if (!string.IsNullOrEmpty(cboSelectEmp.Text.Trim())) { string input = cboSelectEmp.Text.Trim(); string[] splittedText = input.Split(','); if (splittedText.Length > 1) { string[] firstAndLastName = splittedText[0].Split(' '); txtFirstName.Text = firstAndLastName[0]; txtLastName.Text = firstAndLastName[1]; string formPositionValue = splittedText[1].Substring(1, splittedText[1].Length - 2); int position; if (int.TryParse(formPositionValue, out position)) cboPosition.SelectedIndex = position; } } }
The values stored in the combobox are from an Enum and its code is:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace EmployeeTracker.DataTypes { public enum EmployeePosition { Owner, Manager, SalesClerk, Stocker } }
The input string will always be in the format of FirstName LastName, (Position)
EG -
John Doe, (Manager)
Jane Doe, (Owner)
How would I get the Combobox to automatically selectthe correct position value from the enum and show it in the combobox?
Any help would be greatly appreciated.
From, Nathaniel Peiffer