Solved

Convert List to IBindingList

Posted on 2008-10-01
11
2,775 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

687 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