Solved

VB.net ComboBox - DropDownList

Posted on 2013-06-05
9
766 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 39222306
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
ID: 39222309
if you wish to edit the combox text, the property to use is ".text", not selectedtext, selectedtext is readonly.
0
 

Author Comment

by:murbro
ID: 39222345
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
Technology Partners: 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!

 
LVL 10

Expert Comment

by:adriankohws
ID: 39222398
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
 
LVL 42

Expert Comment

by:sedgwick
ID: 39222409
@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
ID: 39222412
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
ID: 39222426
@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
ID: 39222565
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
ID: 39224635
Thank you both for the help
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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