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?
BindingList(Of aBusinessObject)
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
Public Class BindingList(Of T)
Inherits Collection(Of T)
Implements IBindingList, IList, ICollection, IEnumerable, ICancelAddNew, IRaiseItemChangedEvents
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
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
It looks like you are binding the DataGridView to a BindingSource:
BatchdataGridView.DataSour ce = SDCBatchesBindingSource
Try binding directly to the BindingList(Of T).
BatchdataGridView.DataSour
Try binding directly to the BindingList(Of T).
ASKER
Tried BatchdataGridView.DataSour ce = batchAdapter.GetBatches
DataGridView still cannot be sorted by Column Header
Am i missing something very basic??????
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?
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???
Do you know if there is an upgrade for the basic software???
ASKER
sorry amendment to my last comment - yes SP1 is installed
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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!!!!