Example #1
0
		void ChangeSelection(Action a)
		{
			state = GridViewSelectionState.SelectionChanging;
			a(); // Causes GridView.OnSelectionChanged to trigger which calls SuppressSelectionChanged which returns true.
			state = GridViewSelectionState.SelectionChanged;
			gridView.OnSelectionChanged(EventArgs.Empty); // Calls SuppressSelectionChanged which returns false.
			state = GridViewSelectionState.Normal; // This should already be done in SuppressSelectionChanged but repeated for robustness
		}
Example #2
0
		/// <summary>
		/// Initializes a new instance of the <see cref="Eto.Forms.GridViewSelection"/> class.
		/// </summary>
		/// <param name="gridView">Grid view associated with the selection object</param>
		/// <param name="dataStore">Data store to iterate</param>
		public GridViewSelection(GridView gridView, IDataStore dataStore)
		{
			this.gridView = gridView;
			this.selectedRows = new SortedSet<int>();
			this.state = GridViewSelectionState.Normal;
			var collection = dataStore as INotifyCollectionChanged;
			if (collection != null)
				collection.CollectionChanged += OnCollectionChanged;
		}
Example #3
0
		/// <summary>
		/// Resets the selection to the specified model indexes.
		/// Called by
		/// a) SelectionPreserver.Dispose() during sort and filter operations
		/// b) OnCollectionChanged when the model collection is changed.
		/// </summary>
		private void ResetSelection(SortedSet<int> newSelectedRows, 
			HashSet<object> selectedItems = null, 
			HashSet<object> removedSelectedItems = null)
		{
			state = GridViewSelectionState.SelectionChanging; // causes selection events to be suppressed.

			// Set the selection model indexes
			selectedRows.Clear();
			foreach (var i in newSelectedRows)
				selectedRows.Add(i);

			// Create the set of selected items if it wasn't supplied
			if (selectedItems == null)
			{
				selectedItems = new HashSet<object>();
				foreach (var i in selectedRows)
					selectedItems.Add(DataStoreView.Model[i]);
			}

			// Calculate the view indexes
			var view = DataStoreView.View;
			var selectedRowViewIndexes = new SortedSet<int>();
			for (var i = 0; i < view.Count; ++i) // O(nlogn)
				if (selectedItems.Contains(view[i]))
					selectedRowViewIndexes.Add(i);

			// Reselect the rows in the handler.
			Handler.UnselectAll();
			foreach (var i in selectedRowViewIndexes)
				Handler.SelectRow(i);

			state = GridViewSelectionState.Normal; // start firing selection changed events again.

			// TODO: should we fire SelectionChanged events if
			// selected items were removed? This is an edge case;
			// implement only if needed.
		}