What is the best way to use SfComboBox as a list of actions?

I'm using an SfComboBox as a list of actions (e.g., Open, Close, Save, etc.) and when the SelectedItem changes, I cast the SelectedItem to a Command and execute the command.

The problem I'm seeing is when the action is selected, the next time the dropdown is displayed, the SfComboBox item remains in the selected state and cannot be clicked again.

I've tried setting SelectedItem to null or calling SelectedItems.Clear() within the SelectedItemChanged event does not work so I ended up using Dispatch.DispatchAsync instead.

Is there a better way to do this?


Thanks.



3 Replies

BV Brundha Velusamy Syncfusion Team February 5, 2024 02:07 PM UTC

Hi Daniel,

 

We regret to inform you that we are unable to replicate the reported issue on our end. We have generated a simple sample based on the provided details and verified whether the reported problem persists in the SfComboBox. However, the issue did not manifest in our sample. To better assist you, could you please provide a sample that illustrates the problem? This will enable us to thoroughly investigate and propose a solution more accurately.

 

For your convenience, we have included the sample as an attachment. Kindly review the attached file and inform us if you have any concerns. If necessary, please make any required modifications and share the updated sample with us. This would greatly aid us in conducting a more comprehensive analysis of the reported issue on our end.

 

Feel free to contact us if you have any further questions or need additional assistance. We are here to help!

 

Regards,

Brundha V


Attachment: ComboBoxSample_de2c2982.zip


DT Daniel Travison February 7, 2024 03:01 PM UTC

I can repro the issue with your sample with the following steps:

1: Select an item in the combobox (Save)

2: set/enable a breakpoint on ViewModel.SelectedItem.Set

3: Select the same item (Save)

4: The break point is not hit.

This is exactly the case I'm addressing.

The distinction is whether the ComboBox item is a noun or a verb.

If the items are a list of colors, the individual item is a noun, the color to use.

If the items are a list of actions to perform, the individual item is a verb (Save, Close, New, etc.)

In the sample, Save should be selectable if some associated application state needs to be saved.  However, it can't be selected a second time if it is already the selected item.

Ideally, I should be able to set selection mode to none and/or subscribe to an Item clicked event.  Since this is not available, I'm attempting to clear SelectedItem to ensure Save is based on my application's state and am looking for a simpler method that doesn't require Dispatcher.Dispatch




BV Brundha Velusamy Syncfusion Team February 8, 2024 10:39 AM UTC

Hi Daniel,


Thank you for the details.


Query: Save should be selectable if some associated application state needs to be saved.  However, it can't be selected a second time if it is already the selected item.


We would like to notify you that if an already selected item is chosen again from the dropdown, the selected item function won't be triggered due to a built-in function in the SfComboBox.


To address your concern, we have devised a workaround sample that uses the DropDownClosed event to meet your needs. Please find the a sample for your reference and don't hesitate to reach out if you have any questions or need further assistance. We are here to help, and if your requirements differ from the suggested solution, kindly provide detailed specifications to facilitate a more effective investigation and solution.


Regards,

Brundha V


Attachment: ComboBoxSample_6758b19b.zip

Loader.
Up arrow icon