Combobox first use

Hi

I have a problem with the first time that I click on a combobox.

I have
cmbDept.SelectedItem = NewItem
cmbDept.Text = NewItem

which is supposed to display the string in NewItem but it doesn't the first time it is clicked, it displays the first item in the list.
If it is clicked again it displays the string correctly.

All help appreciated.

Regards

alungwytherAsked:
Who is Participating?
 
DarthModConnect With a Mentor Commented:
PAQd, 125 points refunded.

DarthMod
CS Moderator
0
 
manchCommented:


Why don't u use directly

        cmbDept.SelectedItem = cmbDept.Items(indexOfItemUWantToSelect)

it will work surely

Try It
0
 
alungwytherAuthor Commented:
Hi

Thanks for the reply but it didn't work, still came up with the first item in the list.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Kinger247Commented:
Where are you running this code ?

So, as I can gather from your code you want to highlight the value of NewItem in the combo cmbDept ?
0
 
dctuckCommented:
Try:

 cmbDept.Text = NewItem
0
 
manchCommented:

Now u have to elaborate ur need

Where do u want to set the Item as First or Selected One
r u writing the code in the Event of the ComboBox itself or ur writing it in some other place
and what is ur basic need?

mention it
0
 
alungwytherAuthor Commented:
Hi

Solved the problem.
The combobox was not visible until after the text was set. Once I made it visible before then everything worked OK.
Thanks for the replies
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.