Ho una funzione che restituisce un IList < T> ed è il DataSource per un DataGridView. Ho saputo che DataGridView non ordinerà IList. Ho letto This stackoverflow Q&A e sto cercando di implementare SortableBindingList. Devo fare qualcosa di sbagliato perché il mio DataGridView è vuoto. Ho anche provato ad accedere a un elemento da SortableBindingSource con un TextBox e anche niente.DataGridView utilizzando 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;
}
}
ho ispezionato la Microsoft.SqlServer.Management.Controls, fa questo guardare a destra?
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();
}
}
Apprezzo molto l'aiuto e mi aiuta a imparare. Grazie a tutti!
ho ottenuto questo per sviluppare la mia stessa classe SortableBindingList come nell'esempio StackOverflow. Volevo usare il Microsoft.SqlServer.Management.Controls.dll però. Qual è l'accordo? – waltmagic