Click here to Skip to main content
15,743,541 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to clear a selected value in combo box without deleting any value in the list.
Posted

Not sure what you want to so.
According to my understanding you want to reset dropdown values.
You can use
C#
DropDownList1.SelectedIndex=-1;
 
Share this answer
 
v2
Comments
suganyass 3-Aug-12 0:57am    
Thank u for your reply. But I am using MVVM pattern. I need to clear the selected value in the combo box in View Model. while clear that value, list item get deleted.
Sharma Richa 3-Aug-12 1:02am    
You have to set the selected value property to null or something else you want in your viewmodel
suganyass 3-Aug-12 1:08am    
If i set null means then the selected value clear from list. Then the List loaded without the selected value.
Santhosh Kumar Jayaraman 3-Aug-12 1:10am    
please check solution2
Sharma Richa 3-Aug-12 1:14am    
you have to set it to null when you finished working with combobox selected value.
try this

if in view:
C#
ComboBox1.SelectedIndex = -1 


or dou you want it in viewmodel,

then Have a property for selected item. and set it to null:

For eg:
C#
public List<gender> GenderList
{get;set;}

//include notify property changed for that property..the above one is just outline

Then have a property
C#
Public Gender SelectedGender
{get;set;}

Bind Itemsource to GenderList property and Selectedvalue property to SelectedGender.

Whenever You want to clear the selection Set SelectedGender =null. SInce Notifyproperty changed element is there, it will clear the selection
 
Share this answer
 
v3
Comments
suganyass 3-Aug-12 1:15am    
Thank u..... I got the answer.....
Santhosh Kumar Jayaraman 3-Aug-12 1:16am    
ya welcome

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