I have a CombBoxEdit with data which can change a lot, that's why I am each time the popup is being loaded reload the data. Currently my code is:
XAML<dxe:ComboBoxEdit ItemsSource="{Binding Suppliers}"
ValueMember="Id" DisplayMember="Name"
ValidateOnTextInput="False" AutoComplete="True" IncrementalFiltering="True" FilterCondition="Contains" ImmediatePopup="True"
SelectedItem="{Binding Supplier,ValidatesOnDataErrors=True,UpdateSourceTrigger=PropertyChanged}"
PopupOpening="ComboBoxEdit_PopupOpening"/>
C#private void ComboBoxEdit_PopupOpening(object sender, DevExpress.Xpf.Editors.OpenPopupEventArgs e)
{
if (DataContext is LotEditorViewModel viewmodel && viewmodel.ReloadSuppliersCommand.CanExecute(null))
{
viewmodel.ReloadSuppliersCommand.Execute(null);
}
}
I then wanted to test whether it rerenders the data as I want to be certain about it and did the following in my viewmodel.
C#private async void OnReloadSuppliersCommand(object obj)
{
try
{
Suppliers = Enumerable.Empty<Supplier>();
await Task.Delay(250);
Suppliers = await _supplierService.GetAllByLocation(locationId);
}
catch (Exception ex)
{
}
}
The code of Suppliers in my viewmodel.
C#private IEnumerable<Supplier> _suppliers;
public IEnumerable<Supplier> Suppliers
{
get => _suppliers?.OrderBy((supplier) => supplier.Name);
set
{
_suppliers = value;
RaisePropertyChanged(nameof(Suppliers)); // Using Prism.MVVM
}
}
What's happening is my comboboxedit renders an empty list, while I do load the Suppliers a bit later.
Now I'm wondering how I'm able to make the ComboboxEdit detect itemssource changes and renders the newest items put in the variable?
Hi Tom,
Our suite includes a control designed for scenarios when it's necessary to dynamically load items to the popup: AutoSuggestEdit. Please check this control and let us know if it meets your requirements.
Thanks,
Alexander
The AutoSuggestEdit control is indeed what I was searching for, yet, is there a possibility for it to submit a query even when no input was given? I'd love to refresh my data each time the control is opened while also keeping filtering in mind. Upon binding it to the PopupOpening event I run into the problem my EditValue of my object is seen as the filtering, making so I don't see other objects when starting from an object.
Hello Tom,
The use of the
PopupOpening
event is a correct solution if you wish to refresh data every time the popup is opened. Regarding the issue you described,AutoSuggestEdit
does not filter data on its own, so most likely an extra filter is applied in your code. Please check your logic to populate theItemsSource
collection.In the meantime, I tested your original code snippet and see that the editor's popup is never opened because
Suppliers
is set to an empty collection. If that's the issue you meant, you can set ShowPopupIfItemsSourceEmpty totrue
. I demonstrated this in my sample.Hi Ivan
Thanks, that solves my problem indeed. What now is occurring is often the popup shows no items, while there are items in the ItemsSource though.
Or is it because of the usage of async/ await?
With the code you sent initially,
Suppliers
is temporarily set to an empty collection. So yes, the popup will appear empty untilSuppliers
is set to another collection asynchronously. If you wish to avoid this behavior, cancel opening the popup and show it again when data is loaded. For example:bool isDataLoaded; private async void OnPopupOpening(object sender, OpenPopupEventArgs e) { if (isDataLoaded) return; if (DataContext is LotEditorViewModel viewmodel) { e.Cancel = true; await viewmodel.ReloadSuppliers(); isDataLoaded = true; ((PopupBaseEdit)sender).ShowPopup(); isDataLoaded = false; } }