Cannot Insert or Add a String To a ComboBox

J

John Tyce

When a button is clicked, a date is inserted or added into a combo box like this : ComboBox.Items.Add(string) or ComboBox.Items.Insert(0,string);

Either way, the new string does not show up in the ComboBox. I get no errors or problems, it just will not work. At load time I am retrieving dates from an Oracle database and adding them to the ComboBox with out any problems. However, once the application is up and running I cannot add to the ComboBox. I have even tried saying ComboBox.Refresh() after adding or inserting the string, but it still does not show up. Has any one ever encountered this, and do you know how to fix it?
 
N

Nicholas Paldino [.NET/C# MVP]

John,

Can you supply a code example? Are you binding to a data source for the
list contents first? This might be the cause if you are getting the
contents of the list this way.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


When a button is clicked, a date is inserted or added into a combo box like
this : ComboBox.Items.Add(string) or ComboBox.Items.Insert(0,string);

Either way, the new string does not show up in the ComboBox. I get no errors
or problems, it just will not work. At load time I am retrieving dates from
an Oracle database and adding them to the ComboBox with out any problems.
However, once the application is up and running I cannot add to the
ComboBox. I have even tried saying ComboBox.Refresh() after adding or
inserting the string, but it still does not show up. Has any one ever
encountered this, and do you know how to fix it?
 
J

John Tyce

To better explain the problem, I cannot apply changes to a control when class instances are involved. For example: If I create a button on my main form and in that button's click event I write ComboBox.Items.Add(string), the string is added to the combo box without a problem. However, in my case, I am clicking a button on the main form which opens a dialog. Since it is a dialog, it is a separate form belonging to its own class. On that dialog a button is clicked. That buttons click event creates a new instance of the main forms class and calls a function in that class, passes it a string, and then calls ComboBox.Items.Add(string). In this case, the string does not show up in the combo box. Even if I insert new data into the database and then reload the combo box from the database the new data in the combo box will not show up unless I call form.Close() followed by form.Show(). I have already tried ComboBox.Refresh() and Update, neither helps. FYI the combo box is not bound to a datasource; I am simply looping through the rows and adding the column value of each row with the Items.Add function when populating the combo box (not when adding a single string). There has to be a way to insert a string into the combo box. I get the same results with a text box.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top