Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot prevent Duplication

Status
Not open for further replies.

GRIME

Programmer
Oct 23, 2012
2
AU
thread796-987057

VB.NET Win forms issue with combo. I have a combo-box filled with sql from a database which has duplicate DisplayMember values and after selecting the second value of duplicate values then returning to the combo and hitting the drop down arrow it always highlights the first row of the duplicate rows and not the one I selected. E.g. my sql could be SELECT ID, Name, Code. My ValueMember is ID (and I hide this column in code) and DisplayMember is Name. My data could be for e.g.:
1, 'Bob Brown', 'Bob'
2, 'David Smith', 'Dav'
3, 'David Smith', 'Dav2'

When I select item 3 ('Dav2') and click somewhere else on my form then click back on the combo and hit the drop down arrow I see that item 2 ('Dav') has been highlighted. If I do nothing (i.e. do not select anything) and click somewhere else on the form it indeed selects item 2. In my click event of the combo I set other fields based on the selection of my combo so it is obvious the value has changed. So am I doing the impossible, i.e. if the DisplayMember has duplicates the combo automatically shows the item selected by DisplayMember and Not ValueMember on dropping down. Is there any other information you need from me.
 

Try setting the combobox's DropDownStyle property to DropDownList.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
I believe it was DropDown and I changed it to the DropDownList and it made no difference!

I have to confess I am using an inhouse built custom combo (i.e. component that inherits the System.Windows.Forms.ComboBox) however, the original developer left the company so I cannot really give you any code snippet to show you other than giving you the whole thing which I am not allowed for obvious reasons. I was hoping I did not have to dive into some legacy code and change it incase some order of events have caused the selection to change during a validation or dropdown event. I have put break points whereever I can think for e.g. at the end of the OnDropDownEvent the SelectedIndex is the correct value. The combo is an owner drawn so I have put a further break point in the DrawItem when e.State And DrawItemState.Selected is true and at this point the SelectedIndex = 0 where it should have been 1 say. So where what has caused it to change.

Any suggestions are welcome.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top