SfComboBox with sqlite

Hi, I am trying to make a program with SfComboBox that let the user create a new object with a database in sqlite and show the new object in comboBox in the 
MainPage. hen the user creates another object the comboBox shows the new object, i tried but my sample does not show the name of the object in comboBox.

In my sample the content page "Creacion" is where the object is created and the content page and the content page "VerDatos" shows the name and id but 
but im having problem showing the name of each object, the page just shows the id


Sample:
http://www.mediafire.com/file/tcfa0d2okv7t6nl/MedidorSpinner.zipx/file

5 Replies 1 reply marked as answer

RS Ruba Shanmugam Syncfusion Team February 26, 2021 01:02 PM UTC

Hi Miguel,

Greetings from Syncfusion.

We have validated your query and we would like to inform you, You have set the DisplayMemberPath as IDM So only it display’s the ID. If you want to displays the name set the DisplayMemberPath as NombreMaquina as like in the code snippet below.

Code snippet: 
<combobox:SfComboBox HeightRequest="40"
                  x:Name="comboBox" 
                  IsEditableMode="true"
                  ItemsSource="{Binding Data}" 
                  DisplayMemberPath="NombreMaquina" />
 
  
To know more about DisplayMemberPath, Please refer the below UG link.

User guidance: https://help.syncfusion.com/xamarin/combobox/populating-data#setting-displaymemberpath

Or if your requirement is need to display the both Name and ID, you can use SfComboBox ItemTemplate as described below.

User guidance: https://help.syncfusion.com/xamarin/combobox/populating-data#setting-itemtemplate

 
<combobox:SfComboBox HeightRequest="40"
           x:Name="comboBox" IsEditableMode="true" 
           ItemsSource="{Binding Data}"
 
           DisplayMemberPath="NombreMaquina" >
  <combobox:SfComboBox.ItemTemplate>
       <DataTemplate>
          <StackLayout Orientation="Vertical">
                 <Label Text="{Binding NombreMaquina}"/>
                 <Label Text="{Binding IDM}"/>
           </StackLayout>
       </DataTemplate>
   </combobox:SfComboBox.ItemTemplate>
</combobox:SfComboBox>
 
 
  
Please let us know, if you have any other concerns.

Regards,
Ruba Shanmugam 



MG Miguel García García March 1, 2021 01:02 AM UTC

Hi Ruba, thanks for answer me
I analyzed the samples but i couldnt display in ComboBox the name of the object  created in sqlite. I did not find samples with pattern MVVM, will there be an basic sample with this pattern(MVVM)?
 i reviewed my program and i could not find errors 
attach my updated sample. Regards
http://www.mediafire.com/file/cli3ns6xuk7to1v/MedidorSpinner2.zip/file


RS Ruba Shanmugam Syncfusion Team March 1, 2021 12:10 PM UTC

Hi Miguel,

Thanks for the update. We have analyzed the provided sample and you have loaded the data in async way by using SfComboBox ItemsSource property with the type of List.

List: When you update it (let us say by adding or removing something) your UI won't show that change even though in memory it is different\

ObservableCollection: This is a dynamic collection of objects of a given type. When an object is added to or removed from an observable collection, the UI is automatically updated.

So we have modified the provided sample using ObservableCollection and the sample and code snippet from below link.

Sample:
https://www.syncfusion.com/downloads/support/directtrac/general/ze/MedidorSpinnerModified1173065942

Code Snippet:
 
SpinnerPage.XAML: 
<combobox:SfComboBox HeightRequest="40"
               x:Name="comboBox" IsEditableMode="true"
               DataSource="{Binding Data}" 
               DisplayMemberPath="Nombre" />
  
SpinnerPage.XAML.cs:
private async void GetValues()
{
         //set data values from the database data
         var data = await App.appBaseDatos.GetMaquinaAsync();
         
var dataColl = new ObservableCollection<Maquina>(data);
         ViewModel.Data = dataColl;

}
 
 
  
Please let us know, if you have any other concerns.

Regards,
Ruba Shanmugam
 



MG Miguel García García March 2, 2021 04:43 AM UTC

Hi Ruba! thanks for reply
I reviewed the sample but i still have the problem at the moment to show a created object in SfComboBox, i tried different ways but SfComboBox do not shows the object, i find this sample but the link is not working, 


there will be another similar sample?

Regards


RS Ruba Shanmugam Syncfusion Team March 2, 2021 12:12 PM UTC

Hi Miguel,

We have prepared a sample using SQLite with MVVM application using SfComboBox. Get the sample from below link.

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ComboBoxSQLite1775659420

We hope that this helps you, if the sample doesn’t meet your requirement kindly revert us with more details, which help us to analyze and resolve your requirement.

We will update the modified sample link with the updated Nuget in this KB.

Regards,
Ruba Shanmugam

Marked as answer
Loader.
Up arrow icon