4 Answers, 1 is accepted
Thank you for your question.
You are right about that it takes time to load the ComboBox and the databinding fails because the ComboBox is not done loading. When RadComboBox has no items, but you set its SelectedValue (SelectedItem/SelectedIndex) property, it keeps the value until its Items collection changes and then tries to select the specified item. If you add the items one by one and the item that should be selected is not the first, the selection will fail and RadComboBox will not try to select items again. The workaround is to set all items at once, for example, to put them in a collection. That will avoid the issue with the missing selected item ComboBox.
Attached you will find a sample running project for reference.
If you need further assistance please feel free to contact us again.
All the best,
Konstantina
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Thank you for your help
Here is the code snippet where I think the problem is:
public class GeneralVM
{
private MyContext _vmContext = new MyContext();
private static IEnumerable<State> _states = null;
public IEnumerable<State> States
{
get
{
if (_states == null)
{
_vmContext.Load(_vmContext.GetStatesQuery());
_states = (IEnumerable<State>)_vmContext.States;
}
return _states;
}
}
}
The States property of MyContext is an empty ObservableCollection, that is filled with items when they come from the server, one by one (hence the problem we described in our previous reply). You need to change the code like this:
public class GeneralVM : INotifyPropertyChanged
{
private MyContext _vmContext = new MyContext();
private static IEnumerable<State> _states = null;
public IEnumerable<State> States
{
get
{
if (_states == null)
{
_vmContext.Load(_vmContext.GetStatesQuery(), (o) =>
{
_states = o.Entities;
this.OnPropertyChanged("States");
}, null);
}
return _states;
}
}
private void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
All the best,
Valeri Hristov
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Thank you