ComboBox and Command not being fired when expected

Ribbon for WPF Forum

Posted 15 years ago by wpf.acp
Version: 9.1.0500
Avatar
Hi,

I have a problem with a ComboBox in a Ribbon. Its ItemsSource is bound to a collection and I believe a Command is supposed to be triggered on each selection change. I have looked at the samples and I have basically implemented everything in a similar fashion. Still I am observing a problem with Commands not being fired when expected.

When the application is initially started the first selection change fires a Command as expected. All subsequent selection changes never fire additional Commands unless Return is pressed immediately after a selection change. This is Actipro ComboBox, not WPF one and it is not editable. Why does this happen? Am I missing something obvious?

One other thing I have observed. I have added a button that allows me to clear ComboBox selection (set SelectedItem to null). Setting SelectedItem to null too does not fire a Command but the very next attempt to change ComboBox selection results in a Command being fired.

So to wrap up my experience, a Command is only fired upon the first selection change as well as on any other selection change that follows programmatic clearing of SelectedItem. In all other cases, a Command can be provoked solely by hitting Return after a selection change.

Please advise. Thanks!

Comments (8)

Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I believe the command is set up to fire in these scenarios:
1) You close the dropdown after having changed the selection.
2) You press Return.
3) Keyboard focus is lost after changing the selection.

The "selection change" is considered when the Text property is changed since the Text property's original value is stored when the control gets focus. So your data object has to be capable of having different ToString values based on its content for this all to work.

Hope that helps. If you think there is a still a problem after reading this info, then please email over a simple sample project that shows the issue. Thanks.


Actipro Software Support

Posted 15 years ago by wpf.acp
Avatar
[rant]Okay, this took me 3 days to figure this one out which is a bit too much considering I am still in evaluation mode. I really like the library but I have wasted 3 perfectly good days for something that should have worked out of the box.[/rant]

I created a full sample app that reproduces the issue and then your reply shed a light on the issue. I could get combo to work with all possible types but not with my own simple class. Now it turns out I wasn't overriding ToString() in my class and since the default implementation returns the very same class name for each instance, I was screwed as Combo never figured an actual selection change to be an actual change.

Is there any particular reason why this was implemented this way? IMHO this is plain wrong. First and foremost the combo itself has a selection change event and why not just fire a command upon this event?! This is what I now am doing as a workaround for this major problem and it works like a charm!

I believe I am not violating any rules by having two distinct instances of the same class have identical ToString() representation. Thus, ToString() should never be considered unique. Perhaps this Text property change road was taken because of editable combos, but I believe the non-editable combos only suffer because of this decision.

Thanks for your help though.
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I'm sorry this scenario caused you some confusion and time. In the future, please do write us sooner so that we can assist you faster.

It looks like the ComboBox was mostly tested for use as an editable combo. When editable, I don't believe you'd want to the command to fire on selection changed. In that scenario, you'd want to wait until the user is done typing (via Enter or LostFocus), or an item is chosen from the dropdown.

That being said, you are correct that when it is not editable, it should be based on the selection changed event instead. We'll get this updated for the next maintenance release so that you shouldn't require different item ToStrings.


Actipro Software Support

Posted 15 years ago by wpf.acp
Avatar
Perfect! Thanks!

I rarely use editable combos so I wonder how this wasn't detected earlier.

I hate to bother support as soon as I encounter a problem because 90% of the time the problem is down in my own code. So I blame myself for this one. Your support has been superb so far.

I am currently investigating another peculiar issue but I won't raise a question until I am quite sure it's not a problem in my code.

Thanks!
Posted 14 years ago by Marc Petralito
Avatar
I have a question regarding more or less the same problem:

I use a ribon:combobox whith its property IsEditable set to true.

But then the KeyDown Event for the ComboBox is not raised. And I would like to check if a user hits the return key.

Is there a solution for this?

Marc
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Marc,

ribbon:ComboBox will fire its assigned Command when Return is pressed. We override OnKeyDown to implement that logic however we don't mark e.Handled = true. So we wouldn't be doing anything to block the KeyDown event from being raised.


Actipro Software Support

Posted 14 years ago by Marc Petralito
Avatar
Hmm... well the problem is when the combobox IsEditable=True and the DropDown is open, I navigate with the arrows to a certain element in the dropdown and hit return --> there is no event fired up. The dropdown just closes. Then when I hit return the 2nd time (with dropdown closed) the event is fired.

Marc
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Marc,

Our OnKeyDown override isn't being called by WPF either in that scenario, so it's likely just how ComboBox was built by Microsoft.

However in that scenario we are tracking the selection change and execute the command associated with the ribbon:ComboBox. If you use a command on the ComboBox, you will be properly notified via that when Return is pressed.


Actipro Software Support

The latest build of this product (v24.1.3) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.