Solved

ComboBox doesn't change the Text property even though SelectedIndex changes?

Posted on 2014-10-13
6
295 Views
Last Modified: 2014-12-13
I'm really getting frustrated with programming. I have several ComboBox controls that are bound to a DataTable, each with DisplayMember/ValueMember. When in edit mode, the user selects a record and all the ComboBoxes get populate by changing the SelectedIndex property. For the very first time a user does this, it works fine, however, when selecting different records and doing the same process, the "Text" doesn't change in the CB even though the SelectedIndex does.

Prior to selecting a new record to edit, I execute a procedure that sets ComboBox.SelectedIndex = -1.

The below code is how I retrieve a value from the ComboBox List. The row.Cells(3).Value comes from a DataGridView.

idx = cmbManufacturer.FindString(row.Cells(3).Value)
cmbManufacturer.SelectedIndex = idx

Open in new window

0
Comment
Question by:BlakeMcKenna
[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
  • 2
6 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 40378481
It is possible for a ComboBox to keep the same text when the SelectedIndex change, if there are many entries with the same text. This one is trivial.

This being said, I cannot reproduce your problem, code such as yours works well here in Montréal.

But have you tried changing the Text property directly instead:

cmbManufacturer.Text = CStr(row.Cells(3).Value)
0
 

Author Comment

by:BlakeMcKenna
ID: 40378546
I tried changing the Text property directly and even the SelectedIndex directly with appropriate values and nada!!!!

I've tried everything I can think of James. Just really frustrated over seemingly simple stuff.
0
 

Author Comment

by:BlakeMcKenna
ID: 40378608
James,

In the scenario I've described, I failed to mention one thing. When the user selects a completely different record, the above scenario happens, however, if there happens to be more than one detail record in the DataGridView and the user selects a different one (assuming they have already selected a prior record to view), then the code works fine. I think it has to do with selecting an initial record from the DGV. I have no idea what the correlation could be though.
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 40
ID: 40379000
When do you run your code? In which specific event?

Maybe it runs the first time, but the event in which it is coded is not triggered for the following calls. Have you tried to put a breakpoint on the code to make sure that it is executed when you think it will be?
0
 

Assisted Solution

by:BlakeMcKenna
BlakeMcKenna earned 0 total points
ID: 40379749
James,

I figured it out! My initial record selection is from a DGV on the first TabPage of a TabControl. By selecting that record, I was prefilling all the different controls including the ComboBoxes in questions on another TabPage. The TabPage wasn't visible yet (even though it's there in design mode). I'm not sure really what is happening other than the ComboBoxes are preloaded when the form opens. But it had to do with when I was displaying the TabPage, which was after I had prepopulated the ComboBox "Text" property. Not sure what you would call that but I finally got it to work consistently as it should.

Thanks for your help!
0
 

Author Closing Comment

by:BlakeMcKenna
ID: 40497764
I selected my solution only because of trial and error.
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

695 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