private void Window1_Loaded(object sender, RoutedEventArgs e) { IQueryable<Order> query = from o in db.Orders.Include("OrderDetails") //where o.OrderDate >= System.Convert.ToDateTime("1/1/2009") orderby o.OrderDate descending, o.Customer.LastName select o; this.OrderData = new OrdersCollection(query, db); IQueryable<Customer> customerList = from c in db.Customers where c.Orders.Count > 0 orderby c.LastName, c.FirstName select c; IQueryable<Product> productList = from p in db.Products orderby p.Name select p; this.MasterViewSource = (CollectionViewSource)this.FindResource("MasterViewSource"); this.DetailViewSource = (CollectionViewSource)this.FindResource("DetailsViewSource"); this.MasterViewSource.Source = this.OrderData; CollectionViewSource customerSource = (CollectionViewSource)this.FindResource("CustomerLookup"); customerSource.Source = customerList.ToList(); // A simple list is OK here since we are not editing Customers CollectionViewSource productSource = (CollectionViewSource)this.FindResource("ProductLookup"); productSource.Source = productList.ToList(); // A simple list is OK here since we are not editing Products this.MasterView = (ListCollectionView)this.MasterViewSource.View; MasterView.CurrentChanged += new EventHandler(MasterView_CurrentChanged); this.DetailsView = (BindingListCollectionView)this.DetailViewSource.View; }
public Window4() { InitializeComponent(); mycontext=MakeDataSource(); bv= new BindingListCollectionView(mycontext.DefaultView); myCanvas.DataContext = bv; }
private void MasterDetailBindingWindow_Loaded(object sender, RoutedEventArgs e) { IQueryable<Order> query = from o in db.Orders.Include("OrderDetails") //where o.OrderDate >= System.Convert.ToDateTime("1/1/2009") orderby o.OrderDate descending, o.Customer.LastName select o; this.OrderData = new OrdersCollection(query, db); // Make sure the lookup lists are pulled from the same ObjectContext // (OMSEntities) that the order query uses above. // Also have to make sure you return a list of whole entites and not a // projection of just a few fields otherwise the binding won// t work. IQueryable<Customer> customerList = from c in db.Customers where c.Orders.Count > 0 orderby c.LastName, c.FirstName select c; IQueryable<Product> productList = from p in db.Products orderby p.Name select p; this.MasterViewSource = (CollectionViewSource)this.FindResource("MasterViewSource"); this.DetailViewSource = (CollectionViewSource)this.FindResource("DetailsViewSource"); this.MasterViewSource.Source = this.OrderData; CollectionViewSource customerSource = (CollectionViewSource)this.FindResource("CustomerLookup"); customerSource.Source = customerList.ToList(); // A simple list is OK here since we are not editing Customers CollectionViewSource productSource = (CollectionViewSource)this.FindResource("ProductLookup"); productSource.Source = productList.ToList(); // A simple list is OK here since we are not editing Products this.MasterView = (ListCollectionView)this.MasterViewSource.View; MasterView.CurrentChanged += new EventHandler(MasterView_CurrentChanged); this.DetailsView = (BindingListCollectionView)this.DetailViewSource.View; }
/// <summary> /// Return the object associated with (collection, cvs, type). /// If this is the first reference to this view, add it to the tables. /// </summary> /// <exception cref="ArgumentException"> /// Thrown when the collectionViewType does not implement ICollectionView /// or does not have a constructor that accepts the type of collection. /// Also thrown when the named collection view already exists and is /// not the specified collectionViewType. /// </exception> internal ViewRecord GetViewRecord(object collection, CollectionViewSource cvs, Type collectionViewType, bool createView) { // Order of precendence in acquiring the View: // 0) If collection is already a CollectionView, return it. // 1) If the CollectionView for this collection has been cached, then // return the cached instance. // 2) If a CollectionView derived type has been passed in collectionViewType // create an instance of that Type // 3) If the collection is an ICollectionViewFactory use ICVF.CreateView() // from the collection // 4) If the collection is an IListSource call GetList() and perform 5), // etc. on the returned list // 5) If the collection is an IBindingList return a new BindingListCollectionView // 6) If the collection is an IList return a new ListCollectionView // 7) If the collection is an IEnumerable, return a new CollectionView // (it uses the ListEnumerable wrapper) // 8) return null // An IListSource must share the view with its underlying list. // if the view already exists, just return it // Also, return null if it doesn't exist and we're called in "lazy" mode ViewRecord viewRecord = GetExistingView(collection, cvs, collectionViewType); if (viewRecord != null || !createView) { return viewRecord; } // If the collection is an IListSource, it uses the same view as its // underlying list. IListSource ils = collection as IListSource; IList ilsList = null; if (ils != null) { ilsList = ils.GetList(); viewRecord = GetExistingView(ilsList, cvs, collectionViewType); if (viewRecord != null) { return CacheView(collection, cvs, (CollectionView)viewRecord.View, viewRecord); } } // Create a new view ICollectionView icv = collection as ICollectionView; if (icv != null) { icv = new CollectionViewProxy(icv); } else if (collectionViewType == null) { // Caller didn't specify a type for the view. ICollectionViewFactory icvf = collection as ICollectionViewFactory; if (icvf != null) { // collection is a view factory - call its factory method icv = icvf.CreateView(); } else { // collection is not a factory - create an appropriate view IList il = (ilsList != null) ? ilsList : collection as IList; if (il != null) { // create a view on an IList or IBindingList IBindingList ibl = il as IBindingList; if (ibl != null) icv = new BindingListCollectionView(ibl); else icv = new ListCollectionView(il); } else { // collection is not IList, wrap it IEnumerable ie = collection as IEnumerable; if (ie != null) { icv = new EnumerableCollectionView(ie); } } } } else { // caller specified a type for the view. Try to honor it. if (!typeof(ICollectionView).IsAssignableFrom(collectionViewType)) throw new ArgumentException(SR.Get(SRID.CollectionView_WrongType, collectionViewType.Name)); // if collection is IListSource, get its list first (bug 1023903) object arg = (ilsList != null) ? ilsList : collection; try { icv = Activator.CreateInstance(collectionViewType, System.Reflection.BindingFlags.CreateInstance, null, new object[1]{arg}, null) as ICollectionView; } catch (MissingMethodException e) { throw new ArgumentException(SR.Get(SRID.CollectionView_ViewTypeInsufficient, collectionViewType.Name, collection.GetType()), e); } } // if we got a view, add it to the tables if (icv != null) { // if the view doesn't derive from CollectionView, create a proxy that does CollectionView cv = icv as CollectionView; if (cv == null) cv = new CollectionViewProxy(icv); if (ilsList != null) // IListSource's list shares the same view viewRecord = CacheView(ilsList, cvs, cv, null); viewRecord = CacheView(collection, cvs, cv, viewRecord); } return viewRecord; }
private void MasterView_CurrentChanged(object sender, System.EventArgs e) { // We need to grab the new child view when the master's position changes this.DetailsView = (BindingListCollectionView)this.DetailViewSource.View; }
private void Window_Loaded(object sender, RoutedEventArgs e) { var items = from item in no.Employees orderby item.LastName select item; this.DataContext = items; //turn Collection of employee int BindindListCollectionView //This is need for add/delete/edit this.employeeView = (BindingListCollectionView) (CollectionViewSource.GetDefaultView(items)); }
public MeaningFinderModel(DataTable tableTranslations) { Debug.Assert(tableTranslations != null); this.viewTranslations = new DataView(tableTranslations); this.viewTranslations.Sort = "Translation"; this.propertyTranslation = BindingListUtils.GetProperty(this.viewTranslations, Strings.TRANSLATION); this.modelTranslations = new DataPresentationList<TranslationFinderItemModel>(this.viewTranslations); this.collectionTranslations = new BindingListCollectionView(this.modelTranslations); this.collectionTranslations.CurrentChanged += new EventHandler(collectionTranslations_CurrentChanged); AdjustCurrent(); }
public WordFinderModel(DataTable tableWords, Guid filterTypeId, String filterWordText) { Debug.Assert(tableWords != null); Debug.Assert(filterWordText != null); this.viewWords = new DataView(tableWords); this.viewWords.Sort = "Word, Prefix"; this.propertyWord = BindingListUtils.GetProperty(this.viewWords, Strings.WORD); this.filterTypeId = filterTypeId; this.filterWordText = filterWordText; ApplyFilter(); this.collectionWords = new BindingListCollectionView(this.viewWords); this.collectionWords.CurrentChanged += new EventHandler(collectionWords_CurrentChanged); AdjustCurrent(); }