Convert List to IBindingList

Posted on 2008-10-01
Last Modified: 2013-11-07
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?
Question by:RabEDF
  • 6
  • 5
LVL 96

Expert Comment

by:Bob Learned
ID: 22623844
BindingList(Of aBusinessObject)

Author Comment

ID: 22624295
I have tried that but to be able to sort requires an IBindingList (I think) - not just the BindingList
LVL 96

Expert Comment

by:Bob Learned
ID: 22624341
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


Author Comment

ID: 22632405
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

LVL 96

Expert Comment

by:Bob Learned
ID: 22634598
It looks like you are binding the DataGridView to a BindingSource:

   BatchdataGridView.DataSource = SDCBatchesBindingSource

Try binding directly to the BindingList(Of T).
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.


Author Comment

ID: 22648141
Tried BatchdataGridView.DataSource = batchAdapter.GetBatches

DataGridView still cannot be sorted by Column Header  

Am i missing something very basic??????
LVL 96

Expert Comment

by:Bob Learned
ID: 22649504
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?

Author Comment

ID: 22649630
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???

Author Comment

ID: 22649707
sorry amendment to my last comment - yes SP1 is installed
LVL 96

Accepted Solution

Bob Learned earned 250 total points
ID: 22649923
Do you have a small test form that I can test, so that I don't have to come up with something from scratch?

Author Closing Comment

ID: 31501922
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!!!!

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity checkbox 7 41
Server Error 11 48
Error on link 14 40
I need help making a collection from a class in VB.Net 3 27
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now