c# linq datagridview why can I bind to an anonymous type but not an object with same properties?

Hi,
I can bind to an anonymous type using linq and a datagridview.  I created a class so it would be strongly typed and it looks like it gets filled correctly.  If I try to bind to this list, my grid is blank, if I bind to the anontype, it works.

        public class SpreadSummary
        {
            public string Title;
            public Guid ID;
            public int ContractCount;
            public float Profit;
            public float TotalCost;
            public float NetLiquid;
            public string Symbols;

        }

        private void RefreshSpreads()
        {
            var dataGrid = dataGridViewSpreads;
            dataGridViewSpreads.DataSource = null;
            try
            {

//I can bind to this
                var spreadsView = (from s in _currentChain.Spreads
                                   select new
                                   {
                                       Title = s.Title,
                                       TotalCost = s.TotalCost(_currentChain),
                                       NetLiquid = s.NetLiquid(_currentChain),
                                       Profit = s.Profit(_currentChain),
                                       Symbols = string.Join(",", s.GetUniqueSymbolsForSpread(_currentChain)),
                                       ID = s.ID
                                   }).ToList();

///DOESN'T WORK - can't bind to this
                var spreadsView2 = (from s in _currentChain.Spreads
                                   select new SpreadSummary
                                   {
                                       Title = s.Title,
                                       TotalCost = s.TotalCost(_currentChain),
                                       NetLiquid = s.NetLiquid(_currentChain),
                                       Profit = s.Profit(_currentChain),
                                       Symbols = string.Join(",", s.GetUniqueSymbolsForSpread(_currentChain)),
                                       ID = s.ID
                                   }).ToList();


                //dataGrid.DataSource = spreadsView;
                dataGrid.DataSource = spreadsView2;

Open in new window

jackjohnson44Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
An anonymous type is still strongly-typed  = )

Are you receiving an error?
0
jackjohnson44Author Commented:
nope, the grid is just blank.  If you look above, the class I made is the same as the type.
0
jackjohnson44Author Commented:
I even just removed all columns except title from the object and that still didn't work.

                List<SpreadSummary> spreadsView2 = (from s in _currentChain.Spreads
                                   select new SpreadSummary
                                   {
                                       Title = s.Title,
                                   }).ToList();


                //dataGrid.DataSource = spreadsView;
                dataGrid.DataSource = spreadsView2;
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

jackjohnson44Author Commented:
I also removed the other class and tried to manually bind to a list of an object with just a title.  The grid did not show any results.

                var spreadSummary1 = new SpreadSummary();
                spreadSummary1.Title = "MY Title";
                var spreadSummary2 = new SpreadSummary();
                spreadSummary2.Title = "MY Title";
                List<SpreadSummary> mylist = new List<SpreadSummary>();
                mylist.Add(spreadSummary1);
                mylist.Add(spreadSummary2);
                dataGrid.DataSource = mylist;
0
jackjohnson44Author Commented:
The issue was that I was using public variables vs properties.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
käµfm³d 👽Commented:
You  should accept your own solution as the answer.
0
jackjohnson44Author Commented:
solved it, thanks though
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.