Get Syncfusion ComboBox Id Value

Ronald Rex 1,666 Reputation points
2024-01-24T21:59:40.0566667+00:00

Hey Friends, I am using .Net Maui and a Syncfusion ComboBoc and I am trying to adhere to the MVVM pattern and I was wondering if you have a simple model of type collection with Name and Id like the code below, how would I create a binding to the Id property in my ViewModel so that I can save this value to a field in my database table. I have tried to follow some syncfusion docs and can't seem to get anything to work. I tried using SelectedItem = SocialMedias.ElementAtOrDefault(3) but it just returned a model of type SocialMedias instead of the Id proerty. Thanks !

            Name= "Facebook", ID = 0 
            Name = "Google Plus", ID = 1 
            Name = "Instagram", ID = 2 
          
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,587 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,005 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
814 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 76,471 Reputation points Microsoft Vendor
    2024-01-25T03:12:09.81+00:00

    Hello,

    I tried using SelectedItem = SocialMedias.ElementAtOrDefault(3) but it just returned a model of type SocialMedia instead of the Id proerty.

    If you can get SocialMedia object, you can get id by following code directly.

    int id = SocialMedias.ElementAtOrDefault(3).ID;
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.