I have a ComboBox with a number of items on a Page, when I open the page and select an item from the ComboBox, the item is in the text field as expected, however, when I leave the page and then return to the page, items are appended to the original list of items.
I have tried to set the ItemSource=null; but this does not reset the list of items in the ComboBox.
Here is how the items are added.
CategoryCombo.ItemsSource = null;
patientComboBox.ItemsSource = null;
FacilityCombo.ItemsSource = null;
LoadRecords();
private void LoadRecords()
{
PatientRepository pr = new PatientRepository();
var plist = pr.GetPatients();
patientComboBox.ItemsSource = plist;
categories.Add("No Show");
categories.Add("Office Visit");
categories.Add("Established Patient");
categories.Add("New Patient");
categories.Add("Health and Behavior Assessment");
categories.Add("Preventative Care Services");
categories.Add("Opthalomolical Services");
CategoryCombo.ItemsSource = categories;
facility.Add("Main Office");
facility.Add("Mobile Office");
facility.Add("Branch Office");
FacilityCombo.ItemsSource = facility;
FacilityCombo.Text = "Main Office";
}
private void UnloadRecords()
{
patientComboBox.ItemsSource = null;
CategoryCombo.ItemsSource = null;
FacilityCombo.ItemsSource = null;
FacilityCombo.Text = "Main Office";
}
How do I add and clear the items when I change from page to page?
Hi Frederick,
We have reviewed your query, and based on the provided information, we have created a sample. In the sample, we added a combobox in the ComboBoxPage.Xaml. We load the item source records in the Loaded event method and set the item source to null in the Page Unloaded event method. The MainPage contains a button that navigates to ComboBoxPage.
While investigating the reported case, when navigating to the ComboBoxPage and selecting an item from the ComboBox, the item appears in the text field as expected. However, when leaving the page and then returning to it, the original list of items is the only thing shown in the SfComboBox. Despite our efforts, we were unable to reproduce the reported issue. We have attached the sample for your reference.
To better understand the root cause and assist with resolving the issue, it would be helpful if you could provide more detailed information about the scenario in which our control was used, including a sample demonstrating the issue with replication steps. Please let us know if you have any other queries.
Kindly review the attached example and apply any required modifications to reproduce the problem. Afterward, kindly forward the sample to us, as it would enable us to conduct a more thorough investigation of the issue.
Regards,
Ahamed Ali Nishad.
AAN,
I can't find the ContentPage_Loaded and ContentPage_UnLoaded so I changed to OnAppearing and OnDisappering.
Are they equiva
Hi Frederick,
We would like to inform you that the OnAppearing and OnDisappearing behaviors are similar to a ContentPage being loaded and unloaded, respectively. You can place the LoadRecords method in the OnAppearing event and the UnLoadRecords method in the OnDisappearing event. If you encounter any further issues, please provide details, and we will be happy to assist.
Regards,
Ahamed Ali Nishad.