Solved

combobox displayed text not changing when index changed...

Posted on 2009-05-20
4
556 Views
Last Modified: 2012-05-07
In a winforms program, I have a combobox bound to a list of datasource.   When I change its selectedindex to 0, everything works as expected, except the text displayed in the entry field remains blank.   I can't find anything in the code to account for this:

frm.ComboBoxForms.SelectedIndex = 0

The debugger shows me the datasource is populated,  selectedindex IS 0,  and the list does drop down when the combobox is clicked.
frm.comboboxforms.text shows the correct value in the debugger, but selectedtext remains empty.    if I try programmatically setting the selectedtext equal to the text, selectedtext remains empty, but text displays doubled!

 Is there some property I may be overlooking?  This WAS working fine at one time, I can't figure out what's going on.  Any help greatly appreciated, this is really slowing down my project big time.  Thanks in advance.


0
Comment
Question by:codefinger
  • 2
  • 2
4 Comments
 
LVL 15

Accepted Solution

by:
oobayly earned 500 total points
ID: 24431770
SelectedText only returns the actual text highlighted in the ComboBox. ie. If no text is hightlighted, SelectedText will be empty. Try using the Text property instead.

This one a caught me more than once as it's easy to assume that SelectedText works like SelectedIndex, SelectedItem & SelectedValue
0
 

Author Comment

by:codefinger
ID: 24434299
I think we are ALMOST there, but let's say I want to programmatically make the 3rd item in the drop down list be the one that displays to the user beside the drop down arrow.   Right now, just changing the selected index (as in my first example to zero)  does not display ANYTHING next to the arrow.

Thanks again for your (continuing) assistance.

--Al
0
 
LVL 15

Expert Comment

by:oobayly
ID: 24435592
Is the ComboBox showing any of the items when the Drop-down list is shown? My initial thought would have been that the DisplayMember isn't correct, but if the Text value is correct in the debugger and nothing is displayed in the entry field, I can't quite explain.
Any chance you can post the portion of the code doing the databinding?
0
 

Author Closing Comment

by:codefinger
ID: 31583492
You could NEVER have figured this out with what little I gave you to work with, so you earn the points just for trying....would you believe the solution was frm.comboboxforms.selectedvalue = Convert.ToInt32(labeldo.HPFNO) ????     Without the conversion, selectedvalue remains nothing.   Not sure WHY I have to do this conversion, but it works.  Weird.
0

Featured Post

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to use odbc in vb to connect to ms sql 14 53
VB.Net How to Exit Sub - Exit Form??? 5 57
Expression Evaluater 3 26
Get distinct values from excel or comm seperated file 4 25
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…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

810 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