Binding SelectedValue

Hi,

Is it possible to bind SelectedValue of sfcombobox to property in view model?


12 Replies

AJ AhamedAliNishad JahirHussain Syncfusion Team July 25, 2023 02:28 PM UTC

Hi Amit,

 

We have reviewed your query and would like to inform you that you can only obtain the Value of SelectedValue in SfComboBox and not able to set the value to the SelectedValue property in SfComboBox. Instead, you can use SelectedItem or SelectedIndex in SfComboBox . We have created a sample based on this, which includes a label and sfcombobox loaded with data. We have bound the SelectedItem of SfComboBox to a property in the ViewModel. In the SelectionChanged event, we retrieve the value of SelectedValue and update it in the Text property of the Label. Please review the attached sample and let us know if you require any further details.

 

Regards,

Ahamed Ali Nishad.


Attachment: ComboMaui_(3)_ea2bdb1b.zip


AS Amit Saraf July 27, 2023 07:30 AM UTC

Thanks for your reply

I wanted to bind SelectedValue as in wpf combobox to directly get value from ViewModel

In future if possible please look at the possibality of binding SelectedValue 


Thanks for your reply



AJ AhamedAliNishad JahirHussain Syncfusion Team July 28, 2023 02:09 PM UTC

Hi Amit,

 

Currently, we don't have support for setter support for the SelectedValue property in SfComboBox in .NET MAUI. We have created a new feature request for the required behavior in SfComboBox "Provide setter support for SelectedValue in SfComboBox in .NET MAUI ". Please find the below link for tracking the status of the feature implementation.

 

Feedback linkProvide setter support for SelectedValue in SfComboBox in .NET MAUI in .NET MAUI | Feedback Portal (syncfusion.com)

 

Please cast your vote to make it count. We will prioritize the features every release based on the demands and we do not have an immediate plan to implement this feature since we have committed to already planned work. So, this feature will be available in any of our upcoming releases.

 

If you have any more specifications/suggestions for the feature request, you can add them as a comment in the portal. We will share the release details in the feedback itself.

 

Regards,

Ahamed Ali Nishad.



AS Amit Saraf July 28, 2023 02:20 PM UTC

Thanks for Considering


Amit Saraf



PR Preethi Rajakandham Syncfusion Team July 31, 2023 06:59 AM UTC

Hi Amit Saraf,

You're welcome. Please track the status of the feature using the below feedback link.

Feedback portal URL: https://www.syncfusion.com/feedback/45715/provide-setter-support-for-selectedvalue-in-sfcombobox-in-net-maui

Regards,

Preethi R



LC Les Caudle August 20, 2023 06:23 PM UTC

I've been pretty happy with SyncFusion's Maui controls so far.

But this is really just .. Basic .. functionality???

I absolutely .. Have .. to be able to bind my controls to a ViewModel and have the combo boxes (and any Other controls) display the selected value from the ID Index in the DataModel.

You show:

public class SocialMedia
{
    public string Name { get; set; }
    public int ID { get; set; }
} 

in your documentation on the SfComboBox here:

https://help.syncfusion.com/maui/combobox/getting-started

But have Not provided any way to actually use that ID that can I can see?

I can't use ComboBoxName.SelectedIndex to set that selection from a ViewModel's data (even if I Wanted to try to handle that by hand) as I can change it using code but .. it doesn't change the Text shown in the comboBox?

If this is not a feature that's coming in the next week or so I'm going to have to move to using anothe company's controls that .. Has .. this feature Now?

And I really hope I don't have to?  So .. Please .. Data Binding is rather Essential?

Thanks!



BV Brundha Velusamy Syncfusion Team August 21, 2023 12:41 PM UTC

Hi Les,


To display the selected value from the viewmodel collection in the combobox inputview field, we suggest you to use TextMemberPath property in ComboBox control as shown in the code snippet below. It will helps to display the selected value [Name or ID] from viewmodle collection. We have created the simple sample for ComboBox control based on your requirement and attached the sample for your reference.


Note:-

TextMemberPath - This property path is used to get the value for displaying in the selection box portion of the ComboBox control when an item is selected.


Code Snippet:

<inputs:SfComboBox DisplayMemberPath="Name"

                           MaxDropDownHeight="350"

                           TextMemberPath="ID"

                           ItemsSource="{Binding Months}"

                           SelectedIndex="{Binding SelectedIndex}"> 

</inputs:SfComboBox>


Please refer the  below help documentation link for more information about SfComboBox

https://help.syncfusion.com/maui/combobox/getting-started#populating-items-using-data-binding


Please take a look at the provided sample and feel free to reach out if you have any further questions or concerns.


Regards,

Brundha V


Attachment: ComboBox_40af9246.zip


LC Les Caudle August 21, 2023 02:30 PM UTC

HI Brundha !   I think you're missing what I need.

Let's take a real world scenario where I have a combo box where the display part is bound to a model with the Name of the month and the ID of the month. (kindof like you now have .. except you are now displaying the ID in the text part of the combo box when the month is chosen and that won't work at all).

Typically the Months would be in an ObservableCollection or other list like you have now.

The combo box Value field must be bound to a Different property in the ViewModel. 

You'd typically have a Class containing lots of ID's like StartMonthID, EndMonthId, etc. etc.

So you have several Months combo boxes bound to different ID fields.

So you'd have a property in the ViewModel that referenced an instance of this class.

So the end-user would see two combo boxes each displaying a different month .. and the Class storing the IDs would display different ID values for StartMonthID, EndMonthID, etc.

The combo box MUST be able to initialize itself (determine which ID's Name to display) based on the values in the Class containing the different StartMonthID, EndMonthID, etc.

The data in the class with the ID's will get stored to a database .. and a Different set of ID's will get loaded and of course the ComboBox must now update the Month Name shown according to the ID that it's bound to (which just changed).

So I appreciate the sample.  Can you modify it to do what I need or do I need to look elsewhere for a properly bound comboBox?

Thanks!



PR Preethi Rajakandham Syncfusion Team August 24, 2023 01:12 PM UTC

Hi Les Caudle,

A ticket has been created for further follow-up. Please check the ticket for further updates. We are marking this thread as solved. Please let us know if you have any further queries. We are happy to help.

Regards,

Preethi R



PH Phil February 15, 2024 05:49 PM UTC

Can't believe this is not possible. 



LC Les Caudle replied to Phil February 15, 2024 06:43 PM UTC

Hi Phil!  It's possible to data bind and also to set the class it's bound to have have the combo box reflect this.

However, it's needlessly complex and if you have 20-30 combo boxes and radio button groups in a Windows app (I have 72 on an IOS app), then the extra code is just unworkable.

And this is to do something I could do in Visual Basic way back in 1995 .. sooooo simply.

Infragistics does this for Winforms and WPF (maybe others) now but .. of course they aren't competent enough to have Maui controls.

SyncFusion just can't be beat as far as support and rock solid controls.

But in this one single area (that Really matters for a complex business application), I've yet to convince them that they need to revisit this?

The problem is that their programmers aren't designing applications that are used in the real world so .. they just don't realize how important being able to setup data binding .. Simply .. with minimal code .. really is?

I have a running dialog with SyncFusion about his now so .. hopefully I'll be able to bring them onto my side?

As their competitors bring out this functionality .. they'll be forced to so .. we shall see?



AJ AhamedAliNishad JahirHussain Syncfusion Team February 20, 2024 01:25 PM UTC

Hi Les,

 

We have reviewed your query and currently we don't have SelectedValue support in .NET MAUI. We have already created a feature request "Provide setter support for SelectedValue in SfComboBox in .NET MAUI "

 

Once we have implemented this feature, you will be able to observe that if the StatusID property of the Person class is changed programatically, the ComboBox will also be updated accordingly. Similarly, if the ComboBox is manually changed, the StatusID property of the Person class will reflect the modifications.

 

please find the link below to track the status of the feature implementation.

 

Feedback link:  https://www.syncfusion.com/feedback/45715/provide-setter-support-for-selectedvalue-in-sfcombobox-in-net-maui

 

Please cast your vote to make it count. We will prioritize the features every release based on the demands and we do not have an immediate plan to implement this feature since we have committed to already planned work. So, this feature will be available in any of our upcoming releases.

 

If you have any more specifications/suggestions for the feature request, you can add them as a comment in the portal. We will share the release details in the feedback itself.

 

Note: We have already updated the response in the ticket under your name.

 

Regards,

Ahamed Ali Nishad.


Loader.
Up arrow icon