Solved

VB.net ComboBox - DropDownList

Posted on 2013-06-05
9
755 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
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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

821 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