I have a function that returns an IList< T > and is the DataSource for a DataGridView. I learned that DataGridView won't sort IList. I read This stackoverflow Q&A and am trying to implement SortableBindingList. I must be doing something wrong because my DataGridView is empty. I also tried to access an element from the SortableBindingSource with a TextBox and nothing as well.
using Microsoft.SqlServer.Management.Controls;
public partial class Form1 : Form
{
IBusinessLayer businessLayer;
IList<Category> categories;
SortableBindingList<Category> catSortable;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
businessLayer = new BusinessLayer();
categories = businessLayer.GetAllCategories();
catSortable = new SortableBindingList<Category>(categories);
categoryBindingSource.DataSource = catSortable;
categoryDataGridView.DataSource = categoryBindingSource;
textBox1.Text = catSortable[0].CategoryName;
}
}
I inspected the Microsoft.SqlServer.Management.Controls, does this look right?
namespace Microsoft.SqlServer.Management.Controls
{
public class SortableBindingList<T> : BindingList<T>
{
public SortableBindingList();
public SortableBindingList(IList<T> list);
protected override bool IsSortedCore { get; }
protected override ListSortDirection SortDirectionCore { get; }
protected override PropertyDescriptor SortPropertyCore { get; }
protected override bool SupportsSortingCore { get; }
protected override void ApplySortCore(PropertyDescriptor prop, ListSortDirection direction);
protected override void RemoveSortCore();
}
}
I really appreciate the help and helping me learn. Thanks everyone!