tags:

views:

44

answers:

2

Hi , i have the following piece of code, that for some reason that i'm unaware of, doesn't populate the LINQ resultset to the listbox (and there are many results in this list), however, i bind it to the original datatable, it works well. any ideas:

 DataTable t = _partitionsDataSet.Tables[0];

                var customizedPartitions = from r in t.AsEnumerable()
                                 select new 
                                            {
                                                Name = string.Format("{0}[{1}]", r["Name"], r["UserName"]),
                                                BlobId = r["BlobId"].ToString()
                                            };

                if (customizedPartitions.Count() > 0)
                {
                    _dataView.Sort = "Name";
                    listBoxPartitions.DisplayMember = "Name";
                    listBoxPartitions.ValueMember = "BlobId";
                    listBoxPartitions.DataSource = customizedPartitions;
                }
+1  A: 

You have to call the listBoxPartitions.DataBind() method after setting the data source.

Pavel Nikolov
The OP says binding to DataTable works but binding to LINQ doesn't. For binding to DataTable to be working, he must be calling DataBind somewhere else (would be nice if he specified though).
Sam
this is a Windows application and you don't have the DataBind() function there, and you also don't need to call it. it does it for you. beside, it works with datatable without calling to any function.
Or A
@Or A - I know how it works, but you haven't mentioned in your post that it is a Windows app.
Pavel Nikolov
A: 

it seems like that if i bind to "customizedPartitions.ToList()" its all works well. interesting..any comments why?

Or A
Odd, some linq queries actually execute when you iterate through or call ToList()... so maybe that's the issue... but I don't often have to do that with say LINQ to SQL (I'm not using LINQ to DataSets though).
Brian