Solved

combobox displayed text not changing when index changed...

Posted on 2009-05-20
4
559 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
[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
  • 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

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!

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

691 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