I am associating a dictionary with a ComboBox that stores enum values. To get the selected value that I used
comboBox1.SelectedItem that returns size values โโsays [0, Permanent] . Just i, which extracts "Permanent" and converts it back to an enumeration.
something like ..Employee.JobType = Enum.Parse (JobType, comboBox1.SelectedItem)
how can i achieve this
Or:
Employee.JobType = (JobType)Enum.Parse(typeof(JobType), comboBox1.SelectedValue);
Employee.JobType = (JobType)Enum.Parse(typeof(JobType), comboBox1.SelectedText);
, SelectedItem : KeyValuePair < [ ], JobType >
, SelectedItem Value.
var selectedItem = (KeyValuePair<[type of key], JobType>) comboBox1.SelectedItem; var jobType = selectedItem.Value;
- http://www.fmsinc.com/free/NewTips/NET/NETtip4.asp
PeopleNames people = (PeopleNames)Enum.Parse(ComboBox1.SelectedValue, PeopleNames)
:
ComboBox1.DataSource = System.Enum.GetValues(typeof(PeopleNames))
, :
string[] parts = comboBox1.SelectedItem.Split( new char[] { ',', '[', ']' }, StringSplitOptions.RemoveEmptyEntries); Employee.JobType = (JobType)Enum.Parse(typeof(JobType), parts[1].Trim()));
. , . enum.
, Type Parse, , Parse object.
Type
Parse
object
Employee.JobType = (JobTypeEnum)Enum.Parse(typeof(JobTypeEnum), comboBox1.SelectedValue);
- (WPF), .
, ,
KeyValuePair<string,string> selectedPair = (KeyValuePair<string,string>)(cmbApplications.SelectedItem); ProTraceLicence.Products chosenProduct = (ProTraceLicence.Products)Enum.Parse(typeof(ProTraceLicence.Products), selectedPair.Key);
Hope this helps someone. I can't believe it is so hard
Source: https://habr.com/ru/post/1715409/More articles:MySQL: MIN () and MAX () versus string value - sqlBlackBerry - Simulate an event KeyPress - integrationCan I change the controller code generation pattern? - visual-studio-2008Renaming objects using Wing IDE - pythonC # - why is it impossible to access 'this' in a field initializer? - constructorWhat is the best size for a log file in LOG4J? - javaCreate javascript embed code for users - javascriptHow to recognize two different words in a regular expression without grouping - regexhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1715413/in-kentico-cms-how-do-you-programmatically-subscribe-users-to-newsletters&usg=ALkJrhgJ9_MHNHGxkRx2bc7OETEDaWyGtg3gp for Android wav file - javaAll Articles