Solved

VB.net ComboBox - DropDownList

Posted on 2013-06-05
9
740 Views
Last Modified: 2013-06-05
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
Comment
Question by:murbro
  • 4
  • 3
  • 2
9 Comments
 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
DropDownList changes the combobox to be readonly so user cannot change/edit the text of the combobox items.
0
 
LVL 10

Expert Comment

by:adriankohws
Comment Utility
if you wish to edit the combox text, the property to use is ".text", not selectedtext, selectedtext is readonly.
0
 

Author Comment

by:murbro
Comment Utility
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
 
LVL 10

Expert Comment

by:adriankohws
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
@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
 
LVL 10

Expert Comment

by:adriankohws
Comment Utility
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
 
LVL 42

Accepted Solution

by:
sedgwick earned 250 total points
Comment Utility
@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
 
LVL 10

Assisted Solution

by:adriankohws
adriankohws earned 250 total points
Comment Utility
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
 

Author Closing Comment

by:murbro
Comment Utility
Thank you both for the help
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now