Solved

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

Posted on 2014-10-13
6
283 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

777 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