views:

147

answers:

2

I'm creating a control that should be able to take any kind of list. Essentially the following code:

void BindData(IList list)
{
    BindingSource bs = new BindindSource();
    bs.DataSource = list;
    this.DataGridView.DataSource = bs;    
}

Now I have a textbox that I want to use to filter the data in my grid. I figured it'd be as simple as setting the bs.Filter property but apparently not. The bs.SupportsFiltering returns false as well.

Is this an issue with me using the IList? If so, is there another collection class / interface that I can use to achieve the same effect? (Again, I'm not sure what the type is of the objects in the list.

A: 

The IBindingListView interface supplements the data-binding capabilities of the IBindingList interface by adding support for filtering of the list.

A couple of solutions for generic IBindingListView implementations can be found here.

Jacob Seleznev
A: 

Not knowing the type I'm getting passed, I resulted in filtering the data by hand. Here's my code snippet. It works well. Hopefully it doesn't prove to be too slow with larger amounts of data. :: Fingers Crossed ::

List<object> filteredData = new List<object>();
foreach (object data in this.DataSource)
{
    foreach (var column in this.Columns)
    {
        var value = data.GetType().GetProperty(column.Field).GetValue(data,null)
                                                            .ToString();
        if (value.Contains(this.ddFind.Text))
        {
            filteredData.Add(data);
            break;
        }
    }
 }

 this.ddGrid.DataSource = filteredData;
Buddy Lee