Hi All,

Can someone tell me how to set the selected text of a combobox on windows form with C#. If the combobox is unbound ie. has a static item list then combobox1.selected.text = "mtetxt"; works fine. However when the box is databound to a list from a database this does not work. I could use selectedindex but my database list may change, therefore changing the required index. I have found some other forums suggesting this is a glitch with the combobox object but offer no workaround.

Any help with this would be greatly appreciated.

Try to first search your items for the required text to find out its index, then select that index from the box

Hi Emilo35,

I have tried searching the items and then selecting the one i want but it still wont work. Have you got some sample code?

Is your problem that in the time between loading your form (which will populate your comboBox automatically because it's databound) and selecting a comboBox item the data in the database may have changed and you would like your comboBox to update if the data in the database is changed ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.