I need to catch an event when a user selects an item from a combo box. After reading some answers here on StackOverflow I used this method
(XAML):
SelectionChanged="LocationBox_SelectionChanged"
And the event handler in C#:
private void LocationBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
The problem is that this event handler is getting tripped numerous times as the ComboBox is being built dynamically and not when a user selects an item. By the way, this method does work correctly when a user selects an item. The problem is all of these extraneous events.
I want the event handler to be called only when a user selects an item from the combobox. I do not want the event handler to be called when the combobox is being built dynamically before it is displayed. It appears that every time an item is added to the combobox it is tripping the event handler. I want the event handler to be tripped IFF a human being makes a selection from the combobox.
Suggestions? Thanks.
Unsure about the selectionChanged signal.
You can always use QObject: blockSignals during QComboBox editing?
It's a problem because when it falsely reports a user event my code would like to do something with the user selected index. However, since the user didn't actually select anything the event, and subsequent index, is wrong causing a crash.
Just return from your event handler immediately in case SelectedItem == null or SelectedIndex == -1.
Related
The question is similar to What event handler to use for ComboBox Item Selected (Selected Item not necessarily changed) , albeit with WinForms.
When the user selects an item in a ComboBox, even if the item was selected before, I want to execute some additional code. If the user just opens and closes the dropdown, I don't want the code to run.
SelectionChanged, ValueChanged and DropDownClosed so far did not work. ValueChanged is best, but not 100%ly what I want. I would like a ValueSelected event.
WinForms' ComboBox raises the SelectedIndexChanged and SelectionChangeCommitted events anytime an item is selected, not matter if it is the same index.
These events are not raised if the DropDown is simply opened and closed.
I linked a combobox SelectedValue to a class. I noticed, the class value is changed only when I exit the control.
How do I change this behavior and set the class value when the combobox SelectedValue is changed and has focus yet?
Is it possible that your code is currently listening for the SelectionChangeCommitted event? If so, give SelectedIndexChanged a try.
The SelectionChangeCommitted event is raised only when the user changes the combo box selection, and you can create a handler for this event to provide special handling for the ComboBox when the user changes the selected item in the list. However, depending on how the ComboBox is configured, and how the user changes the selected item, the SelectionChangeCommitted event may not be raised. Alternatively, you can handle the SelectedIndexChanged, but note that this event occurs whether the index is changed programmatically or by the user.
If you have a CheckedListBox with CheckOnClick = False the ItemCheck event will not fire when the item is checked IF it is first selected...pause...then click again to check the item. But if it is a quick double click with no pause the event will fire.
Is this the correct behavior? The ItemCheck event should fire regardless of the click speed, right?
I believe this is strange behavior that is easy to replicate:
Make a new winform
add a CheckedListBox and add some items to it. (Leave the default check on click to false)
add a label
subscribe to ItemCheck event and SelectedIndexChanged make the label's text change when each event fires.
Has anyone else ran into this issue?
EDIT 5/1/2015
The problem is that the SelectedIndexChanged event gets fired directly after the ItemCheck event. That means it gets fired before every ItemCheck and then immediately after. The label will not show the change as it happens too fast, but switching to MessageBox.Show() verifies that it is getting fired directly after.
The problem is that the SelectedIndexChanged event gets fired directly after the ItemCheck event. That means it gets fired before every ItemCheck and then immediately after. The label will not show the change as it happens too fast, but switching to MessageBox.Show() verifies that it is getting fired directly after.
according to MSDN checkedlistbox.checkonclick (read the remarks section) check on click property controls whether the list box item is checked on the first click or on the second click. in your case where check on click is flase it requires two clicks to check the item thus firing the ItemCheck event.
I have a grid which contains multiple columns/rows with ASP TextBox controls. In addition to this, above the grid I have a radio button list which contains years.
The user can enter numbers into the TextBoxes and then click an item on the RadioButton list to save the information then switch years or click an update button to just save the information and remain viewing the data.
If I click the 'save' button the textchanged event handler fires and I know what rows on my grid had something changed, then I update my DB and then get the data again to display to the user.
If however I click the radiobuttonlist to switch years the SelectedIndexChanged event fires but the TextChanged event handler does not run because the save and get data runs first, rebinding the grid and eventhandler.
This appears to me to be something to do with the way events run in .net, does anyone know how can I get the textchanged event handler to run first when clicking a radio button list?
I'm using VS2005, .Net 2.5, ASP.Net, C#
Thanks in advance
Your question is not clear. Anyway i can understand that you have problem with the event handlers and how they are called.
I want to know what is the need of calling the textchanged event and SelectedIndexChanged. Even they are not called your data would be get saved perfectly.
I have a System.Windows.Forms.ComboBox on a form and I want to capture the event just before the ComboBox's menu is displayed (something like "DroppingDown"). I can't seem to find a suitable event.
Is capturing this type of event possible with a ComboBox?
The ComboBox should have a DropDown Event. If I am not mistaken, this event should fire immediately when the drop down list starts to show.
What exactly are you wanting to accomplish immediately before the drop down shows that necessitates your capturing of such an event?