[RESOLVED] [2008] LINQ to SQL class, IBindingListView properties and AutoFiltering DGV columns
I have a DataGridView and a LINQ to SQL class called linqFillItemSearch. On the SQL Server 2005 there is an sp called fillItemSearchDGV which simply creates a View containing the columns that are needed to populate the dgv. The dgv is bound @ design time to the QryItemsFillSearchBindingSource. My question is: Is this type of Binding Source, using a LINQ to SQL class, bound to an IBindingListView implementation or do I need to Implement it myself?
If the implementation is by default, how do I go about setting the IBindingListView.SupportsFiltering property to True?
Also, when I set the Column Type of the dgv to DataGridViewAutoFilterTextBoxColumn the app returns a "The DataSource property of the containing DataGridView control must be set to a BindingSource." error. Obviously, at least to me, it is bound both early and late, so how does it "forget" that it IS bound? It only throws this error when I try to use the AutoFilter on the columns of the dgv. It works fine when I have the column type set to DataGridViewTextBoxColumn.
So... From that I would surmise that since to support filtering, the BindingSource must be bound to an IBindingListView with a SupportsFiltering property, that this type of object doesn't possess this property. HOWEVER, there is an error trap that traps this specific error and returns the message "DataSource is not an IBindingListView or does not support filtering", which is not being thrown. "Curiouser and curiouser".
Below is the code:
Code:
Public Sub fillItemSearch()
Dim ProdDBfill As New linqFillItemSearchDataContext
frmSearchItems.dgvSearchItems.DataSource = ProdDBfill.fillItemSearchDGV.ToList
End Sub
Re: [2008] LINQ to SQL class, IBindingListView properties and AutoFiltering DGV columns
If setting the type to DataGridViewAutoFilterTextBoxColumn complains about not having a BindingSource, then you'll need a BindingSource. Obvious. Which in turn means that the BindingSource needs a data source that in turn implements IBindingListView, and if this is your datacontext class, then yes, you should need to implement this in your datacontext class and perform the sorting yourself. That's also where you specify the values for SupportsFiltering.
I see that you're using your IEnumerable.ToList(), which gives a List<>, which doesn't support IBindingListView either. So you're going to have to do this somewhere. You could potentially wrap the List<> in a class that does the filtering and sorting on it (implementing IBindingListView of course) as an alternative to doing it in the datacontext.
Re: [2008] LINQ to SQL class, IBindingListView properties and AutoFiltering DGV colum
The sorting and filtering logic needs some optimisation but here's an example that I cooked up some time ago for a project that my employer canned before I'd finished it.
Re: [2008] LINQ to SQL class, IBindingListView properties and AutoFiltering DGV columns
@mendhak: Thanks for the explanation! It answered my question exactly! And I too found the "oakleafblog" page, and it was also very helpful, thanks again!
@JMc: That is awesome, thank you VERY MUCH!
I haven't finished it yet, but your guidance has been invaluable!