Link to home
Start Free TrialLog in
Avatar of RabEDF
RabEDF

asked on

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?
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

BindingList(Of aBusinessObject)
Avatar of RabEDF
RabEDF

ASKER

I have tried that but to be able to sort requires an IBindingList (I think) - not just the BindingList
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

Avatar of RabEDF

ASKER

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
 
    BatchTableAdapter.Fill(mDataSet.SDCBatches)
 
    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
    batchList.Add(batch)
    Next
    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

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

   BatchdataGridView.DataSource = SDCBatchesBindingSource

Try binding directly to the BindingList(Of T).
Avatar of RabEDF

ASKER

Tried BatchdataGridView.DataSource = batchAdapter.GetBatches

DataGridView still cannot be sorted by Column Header  

Am i missing something very basic??????
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?
Avatar of RabEDF

ASKER

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???
Avatar of RabEDF

ASKER

sorry amendment to my last comment - yes SP1 is installed
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RabEDF

ASKER

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!!!!