Solved

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

Posted on 2014-10-13
6
276 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 40

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
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
Comment Utility
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
Comment Utility
I selected my solution only because of trial and error.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

11 Experts available now in Live!

Get 1:1 Help Now