Solved

Convert List to IBindingList

Posted on 2008-10-01
11
2,740 Views
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?
0
Comment
Question by:RabEDF
  • 6
  • 5
11 Comments
 
LVL 96

Expert Comment

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

Author Comment

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

0
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

by:RabEDF
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
 
    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

0
 
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).
0
 

Author Comment

by:RabEDF
ID: 22648141
Tried BatchdataGridView.DataSource = batchAdapter.GetBatches

DataGridView still cannot be sorted by Column Header  

Am i missing something very basic??????
0
 
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?
0
 

Author Comment

by:RabEDF
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???
0
 

Author Comment

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

Accepted Solution

by:
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?
0
 

Author Closing Comment

by:RabEDF
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!!!!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

821 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