We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Populating sfcombobox with business objects using Converter

Thread ID:

Created:

Updated:

Platform:

Replies:

146740 Aug 16,2019 04:10 PM UTC Aug 22,2019 06:14 AM UTC Xamarin.Forms 7
loading
Tags: SfComboBox
hassan salman
Asked On August 16, 2019 04:10 PM UTC

Hello, I am trying to populate sfComboBox with objects USING A CONVERTER. I am able to populate the data. when i open the combobox, it show correct values. but when i select a value from the combobox it shows the path of the object.
I set the ItemsSource programmatically.

 <combobox:SfComboBox x:Name="combo1" 
                                     SelectedIndex="{Binding }"
                                     MultiSelectMode="None"
                                     DisplayMemberPath="{Binding DateAndTime, Converter={StaticResource RelativeTimeConverter}}">
                    <combobox:SfComboBox.ItemTemplate>
                        <DataTemplate>
                            <Grid >
                                <StackLayout Orientation="Horizontal">
                                    <Label Text="{Binding DateAndTime, Converter={StaticResource RelativeTimeConverter}}" 
                                                  FontSize="Medium" HorizontalOptions="Center" VerticalOptions="Center"/>
                                </StackLayout>
                            </Grid>
                        </DataTemplate>
                    </combobox:SfComboBox.ItemTemplate>
                </combobox:SfComboBox>

  public class DateTimeObject
    {
        public DateTime DateAndTime { get; set; }
        public int Id { get; set; }

        public DateTimeObject(int id, DateTime dt)
        {
            id = Id;
            DateAndTime = dt;
        }
    }

I the the problem is to set DisplayMemberPath correctly. could you please help. Best regards.
           

Muneesh Kumar G [Syncfusion]
Replied On August 19, 2019 12:01 PM UTC

Hi Hassan, 
 
Greetings from Syncfusion. 
 
We have prepared a sample using Converter in SfComboBox Control using the code snippet provided. Please have the sample from the below link, 
 
 
Please check with the sample and if the requirement differs from the sample, please explain your requirement with more information that would be helpful for us to give better solution in this.   
  
Thanks,   
Muneesh Kumar G.  
 


hassan salman
Replied On August 19, 2019 04:07 PM UTC

Hi Muneesh, thank you for your reply and for the sample. Your sample produce the same problem as that i was described in my original thread. Could you please resolve the issue in your sample. When you select an item from the sfCombobox it show : SfComboBoxSample.DateTimeObject.

Thank you in advance.

Rabhia Beham Kathar Mideenar [Syncfusion]
Replied On August 20, 2019 07:35 AM UTC

Hi Hassan, 
 
Greetings from Syncfusion. 
 
We have modified the sample and for DisplayMemberPath is working fine without the Converter. Please have the sample from the below link, 
 

Screenshots:

 
Please check with the sample and if the issue is getting reproduced from your end, please modify the sample with the issue reproducing steps and also mention the platform details which will be helpful for us to analyse further and provide an appropriate solution.

Thanks,
Rabhia Beham K.


hassan salman
Replied On August 20, 2019 04:00 PM UTC

Thank you very much for your reply. In my project i convert the datetime to a human readable phrase. I reproduced the error by changing the convert method in your sample. Now it show the same error as in my case. could you please let the combobox show the phrase after the user make a select. i attached the sample with the new modifications. 
I am using the latest version of sfcombobox.
thank you in advance.
Best regards.

Attachment: SampleComboBox3243453991_de08eeb5.zip

Muneesh Kumar G [Syncfusion]
Replied On August 21, 2019 09:21 AM UTC

Hi Hassan, 
 
We have analyzed the reported issue “Populating SfComboBox with business objects using Converter” with your sample. We would like to inform you that Converter method return value should be presented in the given DataSource collection. Converter should not return the other string value. The way of your conversion for datetime is wrong. So that you have faced this issue. Please use the Converter in provided sample. 
 
 
Also, please let us know if you require any further assistance on this.  
 
Regards,  
Muneesh Kumar G 
 


hassan salman
Replied On August 21, 2019 01:55 PM UTC

Hi Muneesh, I have done that in the past using a pure universal windows project. The combobox in that project worked without any problem. So i think that in your xamarin syncfusion combobox control  you have a problem with the property that is responsible to show data after selection. 
Here is the combobox code in xaml used in that project.

<ComboBox 
                    x:Name="cbDate"  
                    SelectedIndex="{Binding Id}"                    
                    SelectedValuePath="Id"
                    SelectedValue="{Binding Path=DateAndTime}"
                    SelectionChanged="CbDate_SelectionChanged"  BorderThickness="1" >
                                                                <ComboBox.ItemTemplate>
                                                                    <DataTemplate>
                                                                        <StackPanel>
                                                                            <TextBlock Text="{Binding DateAndTime, Converter={StaticResource RelativeTimeConverter}}"/>
                                                                        </StackPanel>
                                                                    </DataTemplate>
                                                                </ComboBox.ItemTemplate>


Could you please reverify your control to resolve the issue. Best regards.

Muneesh Kumar G [Syncfusion]
Replied On August 22, 2019 06:14 AM UTC

Hi Hassan,   
 
We regret for your inconvenience,  
 
Still we are not able to replicate the reported problem. So, we have scheduled a web call and posted in the incident. Please follow that for further updates. 
  
Thanks,  
Muneesh Kumar G.   
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon