Error with Repeated Selections

When selecting an item from my usersComboBox, the correct item is selected and the object is placed into a sfDataForm.  It works as expected the first time.  However, when I repeatedly select another item from the combobox, I'm getting the following error: 

Exception thrown: 'System.InvalidCastException' in Syncfusion.Maui.DataForm.dll

Here is my xaml for the combobox:

     <editors:SfComboBox Grid.Row="5" Grid.Column="1" x:Name="usersComboBox"
                         DisplayMemberPath="username"
                         TextMemberPath="username"
                         ItemsSource="{Binding Users}"
                         SelectionChanged="usersComboBox_SelectionChanged"
                         IsEditable="true"
                         IsFilteringEnabled="true"
                           SelectedItem="{Binding Users,Mode=TwoWay}"
                   Text="Search" />

And here is my code for the SelectionChanged:

    private async void usersComboBox_SelectionChanged(object sender, Syncfusion.Maui.Inputs.SelectionChangedEventArgs e)

    {
        try
        {
            Users selectedItem = (e.CurrentSelection[0] as Users);


            usersDataForm.DataObject = selectedItem;
        }
        catch (Exception ex)
        {
            await DisplayAlert("Error", ex.Message, "OK");
        }




    }


The dataform control is included in a ScrollView, if I change the scroolview, either up/down, the control does not crash with the error. ​

1 Reply

VM Vidyalakshmi Mani Syncfusion Team January 24, 2024 11:52 AM UTC

Hi Frederick,


Based on the information provided, we have checked your query and are unable to replicate the issue from our end. We used the `SelectionChanged` event for the MAUI ComboBox and set the current selected item as the data object for the MAUI DataForm control as shown in the below code snippet. We repeatedly selected different items in the ComboBox, and the selected item was displayed in the DataForm as expected. It is working fine. We have prepared a simple sample; please see the attached sample for your reference.


 

public partial class MainPage : ContentPage

{

    public User SelectedPerson { get; set; }

              public MainPage()

              {

                             InitializeComponent();

              }

 

    private async void comboBox_SelectionChanged(object sender, Syncfusion.Maui.Inputs.SelectionChangedEventArgs e)

    {

        try

        {

            SelectedPerson = (e.CurrentSelection[0] as User);

            dataForm.DataObject = SelectedPerson;           

        }

        catch (Exception ex)

        {

            await DisplayAlert("Error", ex.Message, "OK");

        }

    }

}

 


Additional information

SfDataForm version: 24.1.47


Please check our sample and let us know if you are still facing the same issue. If not, please modify our sample so that the issue you are facing is replicated. Revert to us with the modified sample, which would be helpful for us to check and provide you a solution as soon as possible:


Regards,

Vidyalakshmi M.



Attachment: GettingStarted_1bfc0a1c.zip

Loader.
Up arrow icon