?
Solved

Convert List to IBindingList

Posted on 2008-10-01
11
Medium Priority
?
2,883 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
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 

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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month15 days, 14 hours left to enroll

850 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