Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
2.00/5 (4 votes)
See more:
I have a combo box in which i am populating a text value which is associated internally with unique ID. But the text value could be repeated. Say my combo has "AA" followed by "AA". The first "AA" is internally bound to ID - 1 and second "AA" to ID-2.My problem is when I select second "AA" and again click on drop down arrow of combo, by default it selects the first "AA". But I want second "AA" to be selected.
Posted
Comments
Hiren solanki 6-Jan-11 1:56am    
That's a very good question, I don't know why people is downvoting it.
If you will see my answer you will find same question discussed in Forum before, and it was formatted correctly, but you've just missed to present it and it's a very good information question for whom not aware of it still. :)

Oh thats problem in combobox with duplicate text, it's discussed quite few time, see HERE[^].

The ASP.NET ComboBox is using the item value as an identity property for selected item. This is by design. for good practice Avoid using items with duplicate values.
 
Share this answer
 
Comments
Sunasara Imdadhusen 5-Jan-11 7:22am    
Good call!
Ian Write 7-Jan-11 5:36am    
Good call Hiren.
The combobox have a Property Called DisplayMember in that you specify what value of datasource shows.

Did you inform it?
 
Share this answer
 
You can use
C#
ComboBox1.SelectedValue = 1; //instead of SelectedText


Thanks,
Imdadhusen
 
Share this answer
 
Comments
Hiren solanki 5-Jan-11 7:16am    
you haven't got question properly. but I haven't downvoted you.
set SelectedIndex of the ComboBox using ValueMember and not using DisplayMember.
 
Share this answer
 
Leave alone the technical implications, it does not make sense to have combo box with two identical options. Does it?
 
Share this answer
 
I agree that its not good practice to have repeating items in combo, but these are not completely duplicate items, these items Text is duplicating but internally they are linked with separate identity.
 
Share this answer
 

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