0

I want to get all the places which are active for bid. I tries this but I'm getting null.

testObservableList = testObservableList.Where(
                         x => x.IsActiveForBid) as ObservableCollection<Places>;
rekire
  • 47,260
  • 30
  • 167
  • 264
  • You good good answers to solve your problem. Be aware though that these solutions (technically) are not type casts. A type-cast is rarely possible between unrelated `IEnumerable` implementations. However, it's neither what you usually need. Creating a new sort of collection with the desired result is usually fine. – Matthias Meid Sep 24 '12 at 12:48

3 Answers3

4

try this.

testObservableList = 
new ObservableCollection(testObservableList.Where(x => x.IsActiveForBid)); 

This will make a shallow copy of the current IEnumerable and turn it in to a ObservableCollection

Jonas W
  • 3,200
  • 1
  • 31
  • 44
  • Error: Using the generic type 'System.Collections.ObjectModel.ObservableCollection' requires 1 type arguments –  Sep 24 '12 at 17:30
  • Error:Using the generic type 'System.Collections.ObjectModel.ObservableCollection' requires 1 type arguments –  Sep 24 '12 at 17:31
3

While an ObservableCollection<T> is IEnumerable<T> the opposite does not hold. Try a constructor:

new ObservableCollection<SometypeType>(
              testObservableList.Where(x => x.IsActiveForBid))
spender
  • 117,338
  • 33
  • 229
  • 351
2

Try this:

ObservableCollection coll1 = new ObservableCollection(testObservableList.Where(x => x.IsActiveForBid);

I guess this will do it.

Ken D
  • 5,880
  • 2
  • 36
  • 58