Maybe I'm not understanding ComboBox events properly but it seems like these events aren't working as they should be.
I have a System.Windows.Forms.ComboBox placed on a form and its Items list is populated with items. When I open the dropdown box and click on an item, the SelectedIndexChanged and SelectedValueChanged events fire as expected.
However, after typing in a text value that is found in the dropdown box, when you hit enter the dropdown box closes and it seems to me like these events should fire, but they don't. When you reopen the dropdown box the item is indeed now selected, but the SelectedValueChanged and the SelectedIndexChanged never fired.
I trapped the SelectedIndexChanged, SelectedValueChanged, and SelectionChangeCommitted events of the ComboBox and did some testing. I also added a button to print the status of the ComboBox's SelectedIndex, SelectedValue, and SelectedItem properties when I click it. (I have step by step descriptions of what I did).
This appears when the form is loading:
{
SelectedValueChanged
SelectedIndexChanged
SelectedValueChanged
SelectedIndexChanged
}
After the form loaded, I clicked the test button to check the ComboBox's current property values:
{
SelectedIndex: -1
SelectedValue: null
SelectedItem: null
}
Next, I typed in the first number that displays in my dropdown box (in my case 1111) and hit enter. The text stays in the textbox portion and the dropdown box disappears. I then clicked the test button to check the current values. As you can see none of the values have changed.
{
SelectedIndex: -1
SelectedValue: null
SelectedItem: null
}
So you'd expect no item to be selected when you reopen the dropdown box, right? Wrong. I click on the little arrow of the ComboBox to open the dropdown box and there is the first item (1111) selected!!! I immediately click the button to display the ComboBox property values and sure enough, the SelectedIndex and SelectedItem have changed, but the SelectedValue is still null. However, the SelectedIndexChanged event NEVER fired. None of my trapped events fired, yet the index has obviously been changed.
{
SelectedIndex: 0
SelectedValue: null
SelectedItem: 1111
}
I then click on the dropdown box and type in the next number (1860) and hit enter. Again the dropdown box disappears. I click the button to test the values. Nothing has changed yet:
{
SelectedIndex: 0
SelectedValue: null
SelectedItem: 1111
}
I click the dropdown box though, and there's 1860 selected. Again I immediately click my button to test the values:
{
SelectedIndex: 1
SelectedValue: null
SelectedItem: 1860
}
Mind you none of my trapped events have fired during any of these SelectedIndex and SelectedItem changes. Just for the heck of it I open my dropdown box and actually click the next item (1862). Sure enough the events fire:
{
SelectionChangeCommitted
SelectedValueChanged
SelectedIndexChanged
}
This is what I would expect and shows that my events are hooked correctly, but it seems as though this should happen when you hit enter as well, but it doesn't. I clicked my button to test the ComboBox's property values:
{
SelectedIndex: 2
SelectedValue: null
SelectedItem: 1862
}
Can anyone explain this?
All I'm after is I when you hit enter I want it to pick up the fact there is a SelectedIndex change. The problem is the change doesn't actually occur unless you click on the dropdown box again, and even then the event never actually fires although the SelectedIndex does change. I'm so confused.
I have a System.Windows.Forms.ComboBox placed on a form and its Items list is populated with items. When I open the dropdown box and click on an item, the SelectedIndexChanged and SelectedValueChanged events fire as expected.
However, after typing in a text value that is found in the dropdown box, when you hit enter the dropdown box closes and it seems to me like these events should fire, but they don't. When you reopen the dropdown box the item is indeed now selected, but the SelectedValueChanged and the SelectedIndexChanged never fired.
I trapped the SelectedIndexChanged, SelectedValueChanged, and SelectionChangeCommitted events of the ComboBox and did some testing. I also added a button to print the status of the ComboBox's SelectedIndex, SelectedValue, and SelectedItem properties when I click it. (I have step by step descriptions of what I did).
This appears when the form is loading:
{
SelectedValueChanged
SelectedIndexChanged
SelectedValueChanged
SelectedIndexChanged
}
After the form loaded, I clicked the test button to check the ComboBox's current property values:
{
SelectedIndex: -1
SelectedValue: null
SelectedItem: null
}
Next, I typed in the first number that displays in my dropdown box (in my case 1111) and hit enter. The text stays in the textbox portion and the dropdown box disappears. I then clicked the test button to check the current values. As you can see none of the values have changed.
{
SelectedIndex: -1
SelectedValue: null
SelectedItem: null
}
So you'd expect no item to be selected when you reopen the dropdown box, right? Wrong. I click on the little arrow of the ComboBox to open the dropdown box and there is the first item (1111) selected!!! I immediately click the button to display the ComboBox property values and sure enough, the SelectedIndex and SelectedItem have changed, but the SelectedValue is still null. However, the SelectedIndexChanged event NEVER fired. None of my trapped events fired, yet the index has obviously been changed.
{
SelectedIndex: 0
SelectedValue: null
SelectedItem: 1111
}
I then click on the dropdown box and type in the next number (1860) and hit enter. Again the dropdown box disappears. I click the button to test the values. Nothing has changed yet:
{
SelectedIndex: 0
SelectedValue: null
SelectedItem: 1111
}
I click the dropdown box though, and there's 1860 selected. Again I immediately click my button to test the values:
{
SelectedIndex: 1
SelectedValue: null
SelectedItem: 1860
}
Mind you none of my trapped events have fired during any of these SelectedIndex and SelectedItem changes. Just for the heck of it I open my dropdown box and actually click the next item (1862). Sure enough the events fire:
{
SelectionChangeCommitted
SelectedValueChanged
SelectedIndexChanged
}
This is what I would expect and shows that my events are hooked correctly, but it seems as though this should happen when you hit enter as well, but it doesn't. I clicked my button to test the ComboBox's property values:
{
SelectedIndex: 2
SelectedValue: null
SelectedItem: 1862
}
Can anyone explain this?
All I'm after is I when you hit enter I want it to pick up the fact there is a SelectedIndex change. The problem is the change doesn't actually occur unless you click on the dropdown box again, and even then the event never actually fires although the SelectedIndex does change. I'm so confused.