ObservableCollection Constructor
-
I'm facing some problems with ObservableCollection constructor.. Any idea why this code is not working? entity.Currencies = new ObservableCollection(CurreniesList.Where( c => c.IsSelected)); Note: 1. entity.Currencies is ObservableCollection(). 2. CurrenciesList is ObservableCollection(). 3. CurrencyEntity class has a proprety called "IsSelected". Thanks in advance. Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)
-
I'm facing some problems with ObservableCollection constructor.. Any idea why this code is not working? entity.Currencies = new ObservableCollection(CurreniesList.Where( c => c.IsSelected)); Note: 1. entity.Currencies is ObservableCollection(). 2. CurrenciesList is ObservableCollection(). 3. CurrencyEntity class has a proprety called "IsSelected". Thanks in advance. Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)
ObservableCollection < T > 's constructor takes a List < T >, and not IEnumerable < T >, presumably because only then can it "observe" addition and removal of elements. Simply wrapping the result of CurrenciesList.Where in a list should solve the problem.
new ObservableCollection <CurrencyEntity>(
new List<CurrencyEntity>(currenciesList.Where(c => c.IsSelected)));Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro
-
ObservableCollection < T > 's constructor takes a List < T >, and not IEnumerable < T >, presumably because only then can it "observe" addition and removal of elements. Simply wrapping the result of CurrenciesList.Where in a list should solve the problem.
new ObservableCollection <CurrencyEntity>(
new List<CurrencyEntity>(currenciesList.Where(c => c.IsSelected)));Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro
Hi Senthil, Thanks but I'm still getting the error. There are 3 constructors[^] in ObservableCollection. IEnumerable[^] is one of them. Or, Am I missing something??
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)
-
I'm facing some problems with ObservableCollection constructor.. Any idea why this code is not working? entity.Currencies = new ObservableCollection(CurreniesList.Where( c => c.IsSelected)); Note: 1. entity.Currencies is ObservableCollection(). 2. CurrenciesList is ObservableCollection(). 3. CurrencyEntity class has a proprety called "IsSelected". Thanks in advance. Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)
This sounds a bit strange, because this is working for me:
public class CurrencyEntity
{
public bool IsSelected
{
get { return true; }
}
}This is just a stub, and here's the code:
List<CurrencyEntity> c1 = new List<CurrencyEntity>() { new CurrencyEntity() };
ObservableCollection<CurrencyEntity> ob = new ObservableCollection<CurrencyEntity>(c1.Where(c => c.IsSelected)); -
Hi Senthil, Thanks but I'm still getting the error. There are 3 constructors[^] in ObservableCollection. IEnumerable[^] is one of them. Or, Am I missing something??
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)
My bad, I missed out the third overload. Can you paste the error that you are getting? [EDIT] .NET 3.0 has only two overloads (http://msdn.microsoft.com/en-us/library/ms658737(VS.85).aspx[^])
Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro
-
My bad, I missed out the third overload. Can you paste the error that you are getting? [EDIT] .NET 3.0 has only two overloads (http://msdn.microsoft.com/en-us/library/ms658737(VS.85).aspx[^])
Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro
The error message is like it doesn't a constructor that takes 1 argument. I'm using 3.5.... Am i referencing the wrong dll or need to import some namespaces? it's very strange
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)
-
This sounds a bit strange, because this is working for me:
public class CurrencyEntity
{
public bool IsSelected
{
get { return true; }
}
}This is just a stub, and here's the code:
List<CurrencyEntity> c1 = new List<CurrencyEntity>() { new CurrencyEntity() };
ObservableCollection<CurrencyEntity> ob = new ObservableCollection<CurrencyEntity>(c1.Where(c => c.IsSelected));I will try again and let you know. it's very strange..
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)
-
The error message is like it doesn't a constructor that takes 1 argument. I'm using 3.5.... Am i referencing the wrong dll or need to import some namespaces? it's very strange
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)
What does hitting F12 (Go to Definition) on the ObservableCollection show?
Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro
-
I will try again and let you know. it's very strange..
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)
Thanks. I think it doesn't work because of Silverlight. I'm using Prism v2 (with multi-targeting feature). so, i need to create the class in SL project and link that class from wpf. that's why the code doesn't work. Thanks for your help.
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)