我試圖篩選的BindingSource用的BindingList作爲數據源。我試過BindingSource.Filter ='Text Condition'但它沒有工作,沒有任何反應,屏幕上的數據保持不變。但是,如果我使用DataSet作爲它的數據源的作品。是否可以使用BindingSource.Filter屬性過濾對象列表?的DataGridView過濾一個BindingSource的與對象的列表作爲數據源
我有以下類:
class Person
{
public String Nombre { get; set; }
public String Apellido { get; set; }
public int DNI { get; set; }
public int Edad { get; set; }
public Decimal Tamano { get; set; }
}
這是我如何使用它:
BindingList<Person> personas = new BindingList<Person> {
new Person{ Apellido = "App1", DNI = 3011, Edad = 20, Nombre ="Name1", Tamano = new decimal(1.7)}
,new Person{ Apellido = "App2", DNI = 1520, Edad = 30, Nombre ="Name2", Tamano = new decimal(1.5)}
,new Person{ Apellido = "App3", DNI = 5654, Edad = 21, Nombre ="Name3", Tamano = new decimal(1.6)}
,new Person{ Apellido = "App4", DNI = 778, Edad = 40, Nombre ="Name4", Tamano = new decimal(1.68)}
};
BindingSource bs = new BindingSource();
bs.DataSource = personas;
grid.DataSource = bs;
bs.Filter = "Apellido like 'App1'";
這只是一個例子想法是測試是否可以過濾這樣的一個數據源。我將使用新項目中的知識。
PD:我們的想法是能夠使用BindingSource.Filter如果可能的話。
謝謝!有了你的信息,我發現IBindingListView的實現,它的工作原理。這裏是鏈接:http://blogs.msdn.com/b/winformsue/archive/2008/05/19/implementing-filtering-on-the-ibindinglistview.aspx – 2012-04-09 14:20:48
我碰到這個前幾年,該溶液來爲我工作得很好。今天我使用相同的代碼只是有點不同:需要兩個datagridviews顯示相同的FilteredBindingList具有不同的過濾/排序選項。 有關如何實現這一目標的任何想法? – Afshin 2015-07-29 00:38:06