Convert List to IBindingList

I have a DataGridView with a BindingSource that's a List (Of aBusinessObject).  I am unable to sort the DataGridView by the column headings, presumably because the BindingSource is not an IBindingList.  How do I "convert" the List (Of ....) to a IBindingList?
Who is Participating?
Bob LearnedConnect With a Mentor Commented:
Do you have a small test form that I can test, so that I don't have to come up with something from scratch?
Bob LearnedCommented:
BindingList(Of aBusinessObject)
RabEDFAuthor Commented:
I have tried that but to be able to sort requires an IBindingList (I think) - not just the BindingList
The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Bob LearnedCommented:
You will notice that BindingList(Of T) implements IBindingList:

Public Class BindingList(Of T)
    Inherits Collection(Of T)
    Implements IBindingList, IList, ICollection, IEnumerable, ICancelAddNew, IRaiseItemChangedEvents

RabEDFAuthor Commented:
The datagridview does not sort when column header clicked.  When a data table is used as the datasource for the datagridview then sorting occurs quite happily.

Please see attached code for data access/population of datagridview

Public Class BatchAdapter
' Batch Adapter class to access SQL Server database and retrieve data (ADO.NET)
    Public Function GetBatches() As BindingList(Of Batch)
    Dim batchList As New BindingList(Of Batch)
    Dim batchRow As SDCCTDataSet.SDCBatchesRow
    For Each batchRow In mDataSet.SDCBatches
        Dim batch As New Batch
        With batch
            .BatchId = batchRow.BatchID
            .UserId = batchRow.UserID
            .BatchName = batchRow.BatchName
            .DateLoaded = batchRow.DateLoaded
            .BatchStatus = batchRow.BatchStatus
            .DateStatusChanged = batchRow.DateStatusChanged
            .BatchStatusDesc = batchRow.BatchStatusDesc
            .BatchSource = batchRow.BatchSource
        End With
    Return batchList
End Function
' Code in Presentation Layer Form to populate datagridview from list of data retrieved
BatchdataGridView.DataSource = SDCBatchesBindingSource
Me.SDCBatchesBindingSource.DataSource = batchAdapter.GetBatches

Open in new window

Bob LearnedCommented:
It looks like you are binding the DataGridView to a BindingSource:

   BatchdataGridView.DataSource = SDCBatchesBindingSource

Try binding directly to the BindingList(Of T).
RabEDFAuthor Commented:
Tried BatchdataGridView.DataSource = batchAdapter.GetBatches

DataGridView still cannot be sorted by Column Header  

Am i missing something very basic??????
Bob LearnedCommented:
No, I don't believe that you are missing something basic.  This should work, and I don't understand what could be wrong, other than a bug with the DataGridView.  Are you using 2005 SP1?
RabEDFAuthor Commented:
The version of VS2005 we are using is from the instalation disc with no upgrades from the the net etc!!!

Do you know if there is an upgrade for the basic software???
RabEDFAuthor Commented:
sorry amendment to my last comment - yes SP1 is installed
RabEDFAuthor Commented:
Thanks for your help - it looks like we were having trouble with our computer centre updating PC automatically - this has now been solved and your solution worksd!!!!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.