Trying to bind devxpress button.Enabled to an extended binding list property and it is not working-Collection of common programming errors
I have an extended binding list for my purposes:
public class MyList : BindingList, INotifyPropertyChanged
{
private List invalidObjectsList;
public MyList() : base()
{
invalidObjectsList = new List();
}
...
public bool IsValid
{
get
{
return invalidObjectsList.Count == 0;
}
}
...
// I have similar method for deletion
AddElementToInvalidList(T element)
{
invalidObjectsList.Add(element);
OnPropertyChanged("IsValid");
}
...
// Stuff for the INotifyPropertyChanged interface
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
...
}
I am designing the UI to be able to use that list to modify and save data to let’s say database. So in the UI I have a DevXpress button to “Save Data”. The actual list is assigned as dynamic, meaning:
dynamic list = DataProvider.GetObjectsList();
For that “Save data” button I am trying to bind it’s “Enabled” property to the “IsValid” property of my list as follows:
saveButton.DataBindings.Add("Enabled", list, "IsValid");
At run time I am getting unhandled Exception:
Cannot bind to the property or column IsValid on the DataSource.
Parameter name: dataMember
I can’t figure out what’s wrong here. Please, help.
Thanks in advance!