使用waynebloss / BindingListView与DevExpress XtraGrid

时间:2017-08-25 14:29:30

标签: c# winforms datagridview bindingsource xtragrid

我有几个DevExpress.XtraGrid(DataGrids),并且希望在代码中将它们全部过滤掉。

所以我的想法是过滤底层的BindingSource。这意味着List of BindingSource需要实现IBindingListView。所以我遇到了似乎很合适的BindingListView项目。

它适用于DataGridView,但不适用于XtraGrid。

我在WinForm和以下代码中放置了两个DataGridViews和两个XtraGrids:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        BindingList<Person> persons = new BindingList<Person>();

        persons.Add(new Person("Ray", "Rochester", 18));
        persons.Add(new Person("Scott", "Cupertino", 33));
        persons.Add(new Person("Samuel", "Boston", 54));


        BindingListView<Person> blvPersons = new BindingListView<Person>(persons);
        dataGridView1.DataSource = blvPersons;
        dataGridView2.DataSource = blvPersons;

        gridControl1.DataSource = blvPersons;
        gridControl2.DataSource = blvPersons;

        blvPersons.ApplyFilter(delegate (Person customer) { return customer.Age > 20; });
    }
}


public class Person
{
    public Person(string name, string city, int age)
    {
        Name = name;
        City = city;
        Age = age;
    }
    public string Name { get; set; }
    public string  City { get; set; }
    public int Age { get; set; }
}

行gridControl1.DataSource = blvPersons;给了我:

  

{“无法将'Equin.ApplicationFramework.ObjectView`1 [GridView_Test.Person]'类型的对象强制转换为'GridView_Test.Person'。”}

堆栈跟踪的第一行:

  

at(Object)      在DevExpress.Data.Access.DataListDescriptor.FastPropertyDescriptor.GetValue(对象组件)      在DevExpress.Data.Helpers.BaseListDataControllerHelper.GetRowValue(Int32 listSourceRow,Int32列,OperationCompleted完成)      在DevExpress.Data.DataController.GetRowValue(Int32 controllerRow,Int32列,OperationCompleted完成)      在DevExpress.Data.BaseListSourceDataController.GetRowValue(Int32 controllerRow,Int32列,OperationCompleted完成)

现在我被卡住了。有人有什么想法吗?

0 个答案:

没有答案