Solved

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

Posted on 2014-10-13
6
280 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create XML 5 46
C# Single Form 8 26
Extracting last characters in a substring 5 20
Web Form VB.Net  import CSV 4 17
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…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

930 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now