Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am working with a data bound grid for which i am providing a generic typed list as the datasource.

This generic list (Generics.List<T>) is being generated from a Linq Query.

The databound grid in question, ideally should have as its datasource a BindngList (System.ComponentModel.BindingList<T>).

As per my understanding in order to create a binding list I need to create a class based on either collectionbase or System.Collections.ObjectModel.Collection<T> and implement the IBindingList interface.

Questions
1. Am I on the right track?
2. Is there an easier way out by creating a binding list when i am creating the LINQ Query?

I face the prospect of rewriting an entire set of programs because of this issue.

Any help would be greatly appreciated

Thanks in advance!
Posted
Updated 26-Nov-10 20:49pm
v2

1 solution

C#
// Using global data connection string.
         MultiTestDataContext _DC_MultiTest = new MultiTestDataContext(global::Infrastructure.Properties.Settings.Default.Linq_TestConnectionString);
         using (_DC_MultiTest) // Using allows the Dispose() to execute when it steps out of block code
         {
            IQueryable _IQueryMultiTestA_Details = (from MultiTestADetails in _DC_MultiTest.tbl_MultiTestAs
                                                    select MultiTestADetails).AsQueryable();
            foreach (var _var in _IQueryMultiTestA_Details)
            {
               MessageBox.Show(((Infrastructure.Linq_Database.tbl_MultiTestA)_var).ColA);
            }
            IQueryable<tbl_MultiTestA> _IQueryMultiTestA_Details_ByType = (from MultiTestADetails in _DC_MultiTest.tbl_MultiTestAs
                                                                           select MultiTestADetails).AsQueryable<tbl_MultiTestA>();
            foreach (tbl_MultiTestA _TableRecordDetails in _IQueryMultiTestA_Details_ByType)
            {
               MessageBox.Show(_TableRecordDetails.ColA);
            }
            // Using Global Scope Instance of MultiTestDataContext
            if (DC_MultiTest_GLOBAL.DatabaseExists())
            {
               dgvMultiJoins.DataBindings.Clear(); // Reset the data connection(s)
               dgvMultiJoins.DataSource = (from MultiTestADetails in DC_MultiTest_GLOBAL.tbl_MultiTestAs
                                           select MultiTestADetails);
               // Or
               dgvMultiJoins.DataBindings.Clear(); // Reset the data connection(s)
               dgvMultiJoins.DataSource = (from MultiTestADetails in DC_MultiTest_GLOBAL.tbl_MultiTestAs
                                           select MultiTestADetails).AsQueryable();
            }
         } // using (_DC_MultiTest)
 
Share this answer
 
v2
Comments
fjdiewornncalwe 29-Nov-10 15:01pm    
Just wrapped in pre tag for readability.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900