Solved

Convert List to IBindingList

Posted on 2008-10-01
11
2,697 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
 

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now