stewarts Posted April 8, 2003 Posted April 8, 2003 I have a TabControl with 2 TabPages on my form. TabPage1 contains a ComboBox (dropdownstyle = dropdownlist) that is bound to a database table. I want the ComboBox to be blank upon form initialization, so I set the ComboBox.SelectedIndex equal to -1. The ComboBox is blank when the form is initialized, but when I click over to TabPage2 and back to TabPage1, the SelectedIndex on the ComboBox is reset to 0. If I actually choose a value in the ComboBox via the dropdown list and then switch to TabPage2 and back, the selected value remains unchanged. How can I get the ComboBox.SelectedIndex to remain at -1 until a selection is made? Thanks in advance for your assistance!!!! Quote
*Experts* Nerseus Posted April 8, 2003 *Experts* Posted April 8, 2003 I'd check your code - sounds like you're doing something that's changing the index. If it's bound, it may be the data that it's bound to. Normally, when you use bound controls you *never* change the control properties - you change the dataset. To deselect something in your combobox, you'd set the corresponding value in your dataset to System.DBNull.Value (or 0, or whatever indicates a bad/unknown value for you). -ners Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
stuart Posted November 5, 2003 Posted November 5, 2003 Did you ever get a resolution to this. I'm having a similar problem. I have a combobox (dropdownlist) bound to a datatable. In the form load event I set the selectedindex = -1. But when the form appears on the screen the selectedindex = 0 and the first item is selected. I have a button that set the selectedindex = -1. However this only works if an item has NOT been selected from the dropdown. If an item has been selected from the dropdown then clicking the button causes selectedindex = 0 and the first item in the list is selected again. Any ideas on how to: a) have the form load with no item selected in the combobox (ie. selectedindex = -1 and b) clear the combobox (ie set selectedindex back to -1) no matter the current selection of the combobox. Thanks in advance. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.