Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 843
  • Last Modified:

VB.net ComboBox - DropDownList

Hi

I have a ComboBox on my windows form where I use the following code to change the text
          Me.CategoryType1_ComboBox.SelectedText = oResult

I have just changed the DropDownStyle to "DropDownList " and that code doesn't work
0
Murray Brown
Asked:
Murray Brown
  • 4
  • 3
  • 2
2 Solutions
 
Meir RivkinFull stack Software EngineerCommented:
DropDownList changes the combobox to be readonly so user cannot change/edit the text of the combobox items.
0
 
adriankohwsCommented:
if you wish to edit the combox text, the property to use is ".text", not selectedtext, selectedtext is readonly.
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks Sedgwick. Does that mean that I cannot assign a selected item. How would I get around this? Maybe my code should change the DropDownStyle to DropDown, then assign a value then change it back to DropDownList.
Or is this not going to work? Can a selection only be done manually
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
adriankohwsCommented:
You can't. Once it is dropdownlist, you can't change the text. Usually this property is used when the programmer needs to limit the possible values in this dropdown, there shouldn't be any value out of the selection list.
0
 
Meir RivkinFull stack Software EngineerCommented:
@adriankohws.
thats not entirely correct.

To assign selected item u can either use .SelectedIndex property or use .Text.
when u use ,Text only tsring that is one of the items in the comboxbo is allowed.
any other string u set would not be displayed.
0
 
adriankohwsCommented:
Since you are going to programmatically changing the text, you might want to consider adding an invisible textbox at the same location of the combobox. So when you need to change you change the text in the textbox and make the combobox invisible.

Hope I don't need to guide you which value to use in both situations.
0
 
Meir RivkinFull stack Software EngineerCommented:
@murbro

To sum up, to set the text in DropDownList mode, you can use .Text property only.
make sure the text u assign is one of the combobox items, otherwise, blank item will be displayed.
an alternative is to use .SelectedIndex property, which requires u to know the text index in the comboxbox.
0
 
adriankohwsCommented:
Yes, sedgwick is right. Maybe can also try before you change the text, you add that text value into the combobox list of selection, then changing to it shouldn't be a problem.
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thank you both for the help
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now