Question on combobox control

jwebb

Member
Joined
Sep 4, 2006
Messages
11
Programming Experience
Beginner
Is it possible to change a combobox's .text property dynamically if you are in the same combobox's 'selectedValueChanged' event handler?

Does vb.net avoid this to eliminate some sort of circular referencing?

Thanks
 
You can set the Text property of a ComboBox wherever you like, although you should generally not be using it at all for a bound control. You should be using the SelectedIndex, SelectedItem and SelectedValue properties in the vast majority of situations.

Having said that, if you do set the Text property, or one of the others, in an event handler of the ComboBox itself then you may end up in an infinite loop of setting the property and raising the same event. The best way to accomplish your aim depends on that aim and, since you haven't specified what that is, it's not possible to speculate.

Also, please post in the most appropriate forum for the topic. The VS.NET Genereal forum is for general questions about VS.NET. This thread is not about that subject so it doesn't belong there. The Windows Forms forum is for questions realting to Windows Forms and since the ComboBox is a Windows Forms control that is where it belongs. Please make the effort in future to help keep the forums as orderly as possible so they are easy to use for everyone.

Moved.
 
Please keep in mind that I am new to this.

My goal is this:

1. To use a For each ... get string in loop to populate a combobox with possible project #s. Along with these I include another item called 'Add new project'.

2. If the 'add new project' is selected in the combo box drop down, a separate form pops up for the user to input some initializing data including a project name.

3. Once data is entered and a button is pressed, the second form is closed and the desire is that the 'Add New Project' text in the combobox is replaced with the project name the user entered on the separate form. The reality is that all the other items appropriately update (textboxes) but the combo box does not.

Any help is appreciated.
 
As I said, you shouldn't really be using the Text property of the ComboBox very much at all. If you have just added a new item to the ComboBox then you should set the SelectedItem property to that item.
 
Back
Top