Solved

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

Posted on 2014-10-13
6
290 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

737 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