I have this code:
public class SelectionList<T> : ObservableCollection<SelectionItem<T>> where T : IComparable<T>
{
// Code
}
public class SelectionItem<T> : INotifyPropertyChanged
{
// Code
}
I need to create a property which is of the type SelectionList as follows:
public SelectionList<string> Sports { get; set; }
But when I replace string with DataRowView, as
public SelectionList<DataRowView> Sports { get; set; }`
I am getting an error. Why doesn’t this work?
Your problem is that
stringimplementsIComparable<string>andDataRowViewdoesn’t.SelectionList<T>has a constraint thatTmust implementIComparable<T>, hence the error.One solution would be to subclass DataRowView and implement
IComparable:Then
SelectionList<MyDataRowView>should compile fine.