Combobox selectedvalue and selectedindex change unexpectedly
Posted on 2009-12-19
In my application users can select a client in a combobox showing the names of our clients.
Selecting a client fires the combobox.SelectedIndexChanged event. There I set the client number (which is a string) this way
strCodeClient = Me.cboClients.SelectedValue.ToString()
This far everythings goes well in all cases. When I click on another control the SelectedIndexChanged event and the SelectedValueChanged event are NOT fired again so strCodeClient remains unchanged.
In our client list there are a clients with the same name. Here my application behaves different. Let's presume there are five clients with the name 'KBC'. When the users selects another KBC than the first one, SelectedIndexChanged and SelectedValueChanged are fired and strCodeClient is set perfectly.
BUT, when the users then clicks on another control, SelectedIndexChanged and SelectedValueChanged are fired again and the SelectedValue and SelectedIndex are set to the FIRST instance of KBC. So is also strCodeClient. In another words the wrong KBC wil be selected.
What am I doing wrong??