Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I have the following codes which is trying get the selected item in combobox and convert it into string. But after I run my project it does not display the value as I expected. Below are my codes:

C#
dummyMeasurementDto.ProcessType = cmbProcessType.SelectedItem.ToString();
Posted
Comments
Vivek Krishnamurthy 30-Jan-15 2:07am    
can you explain in detail what is the issue, what is it displaying ?

what have you tried ?
Atish K. Singh 30-Jan-15 2:16am    
Question is not clear? What you are expecting and what is it displaying?
deepankarbhatnagar 30-Jan-15 2:36am    
Not getting what you trying to ask?
Jamie888 30-Jan-15 2:50am    
I am trying to convert the selected item from combobox into a string so that I can display it. The "dummyMeasurementDto.ProcessType" is a DTO. I can get the item, just I cannot convert the selected item properly.
Vivek Krishnamurthy 30-Jan-15 5:28am    
"it does not display the value as I expected" - what are you expecting ? and what is it dispalying ?

1 solution

Try..
C#
dummyMeasurementDto.ProcessType = cmbProcessType.SelectedItem.Text.ToString();
//OR
dummyMeasurementDto.ProcessType = cmbProcessType.Text;


C#
Object selectedItem = comboBox1.SelectedItem;
String str=selectedItem.ToString();
 
Share this answer
 
v3
Comments
Jamie888 2-Feb-15 0:29am    
Yes. I have tried both methods. The second answer on the first tab "dummyMeasurementDto.ProcessType = cmbProcessType.Text;" seems to solve the problem. Thank you sir.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900