Ich habe eine Funktion, die eine IList < T> zurückgibt und die DataSource für ein DataGridView ist. Ich habe gelernt, dass DataGridView IList nicht sortieren wird. Ich lese This stackoverflow Q&A und versuche, SortableBindingList zu implementieren. Ich muss etwas falsch machen, weil meine DataGridView leer ist. Ich habe auch versucht, auf ein Element von der SortableBindingSource mit einer TextBox und nichts auch zuzugreifen.DataGridView Verwenden von SortableBindingList
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;
}
}
Ich inspizierte die Microsoft.SqlServer.Management.Controls dieses Recht aus?
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();
}
}
Ich schätze die Hilfe und hilft mir zu lernen. Danke allen!
ich dies durch die Schaffung von meiner eigenen SortableBindingList Klasse wie im Beispiel Stackoverflow zu arbeiten hätte. Ich wollte jedoch die Microsoft.SqlServer.Management.Controls.dll verwenden. Was ist das Problem? – waltmagic