Example #1
0
		protected override void OnMouseDown (MouseEventArgs e)
		{
			base.OnMouseDown (e);

			bool ctrl_pressed = ((Control.ModifierKeys & Keys.Control) != 0);
			bool shift_pressed = ((Control.ModifierKeys & Keys.Shift) != 0);

			HitTestInfo testinfo;
			testinfo = HitTest (e.X, e.Y);

			switch (testinfo.Type) {
			case HitTestType.Cell:
				if (testinfo.Row < 0 || testinfo.Column < 0)
					break;

				if (rows[testinfo.Row].IsExpanded) {
					Rectangle relation_area = rows[testinfo.Row].relation_area;
					relation_area.Y = rows[testinfo.Row].VerticalOffset + cells_area.Y + rows[testinfo.Row].Height - rows[testinfo.Row].RelationHeight;
					if (relation_area.Contains (e.X, e.Y)) {
						/* the click happened in the relation area, navigate to the new table */
						int relative = e.Y - relation_area.Y;
						NavigateTo (testinfo.Row, CurrentTableStyle.Relations[relative / LinkFont.Height]);
						return;
					}
				}

				DataGridCell new_cell = new DataGridCell (testinfo.Row, testinfo.Column);

				if ((new_cell.Equals (current_cell) == false) || (!is_editing)) {
					ResetSelection ();
					CurrentCell = new_cell;
					Edit ();
				} else {
					CurrentTableStyle.GridColumnStyles[testinfo.Column].OnMouseDown (e, testinfo.Row, testinfo.Column);
				}

				break;

			case HitTestType.RowHeader:
				bool expansion_click = false;
				if (CurrentTableStyle.HasRelations) {
					if (e.X > row_headers_area.X + row_headers_area.Width / 2) {
						/* it's in the +/- space */
						if (IsExpanded (testinfo.Row))
							Collapse (testinfo.Row);
						else
							Expand (testinfo.Row);

						expansion_click = true;
					}
				}

				CancelEditing ();
				CurrentRow = testinfo.Row;

				if (!ctrl_pressed && !shift_pressed && !expansion_click) {
					ResetSelection (); // Invalidates selected rows
				}

				if ((shift_pressed || expansion_click) && selection_start != -1) {
					ShiftSelection (testinfo.Row);
				} else { // ctrl_pressed or single item
					selection_start = testinfo.Row;
					Select (testinfo.Row);
				}

				OnRowHeaderClick (EventArgs.Empty);

				break;

			case HitTestType.ColumnHeader:
				if (CurrentTableStyle.GridColumnStyles.Count == 0)
					break;

				if (AllowSorting == false)
					break;

				if (ListManager.List is IBindingList == false)
					break;

				// Don't do any sort if we are empty, as .net does
				if (ListManager.Count == 0)
					return;
			
				ListSortDirection direction = ListSortDirection.Ascending;
				PropertyDescriptor prop = CurrentTableStyle.GridColumnStyles[testinfo.Column].PropertyDescriptor;
				IBindingList list = (IBindingList) ListManager.List;

				if (list.SortProperty != null) {
					CurrentTableStyle.GridColumnStyles[list.SortProperty].ArrowDrawingMode 
						= DataGridColumnStyle.ArrowDrawing.No;
				}

				if (prop == list.SortProperty && list.SortDirection == ListSortDirection.Ascending) {
					direction = ListSortDirection.Descending;
				}
				
				CurrentTableStyle.GridColumnStyles[testinfo.Column].ArrowDrawingMode =
					direction == ListSortDirection.Ascending ? 
					DataGridColumnStyle.ArrowDrawing.Ascending : DataGridColumnStyle.ArrowDrawing.Descending;
				
				list.ApplySort (prop, direction);
				Refresh ();
				if (this.is_editing)
					//CurrentTableStyle.GridColumnStyles[CurrentColumn].UpdateUI ();
					this.InvalidateColumn (CurrentTableStyle.GridColumnStyles[CurrentColumn]);

				break;

			case HitTestType.ColumnResize:
				if (e.Clicks == 2) {
					EndEdit ();
					ColumnResize (testinfo.Column);
				} else {
					resize_column = testinfo.Column;
					column_resize_active = true;
					resize_column_x = e.X;
					resize_column_width_delta = 0;
					EndEdit ();
					DrawResizeLineVert (resize_column_x);
				}
				break;

			case HitTestType.RowResize:
				if (e.Clicks == 2) {
					EndEdit ();
					RowResize (testinfo.Row);
				} else {
					resize_row = testinfo.Row;
					row_resize_active = true;
					resize_row_y = e.Y;
					resize_row_height_delta = 0;
					EndEdit ();
					DrawResizeLineHoriz (resize_row_y);
				}
				break;

			case HitTestType.Caption:
				if (back_button_rect.Contains (e.X, e.Y)) {
					back_button_active = true;
					Invalidate (back_button_rect);
				}
				if (parent_rows_button_rect.Contains (e.X, e.Y)) {
					parent_rows_button_active = true;
					Invalidate (parent_rows_button_rect);
				}
				break;

			default:
				break;
			}
		}
Example #2
0
		private void GoTo(string nodePath, DataGridCell cell)
		{
			lock(syncRoot)
			{
				if(this.tablesLoading == null) return;  // The tree is being loaded
				if(this.navigating) return;  // This method is already on the callstack

				DataView table = (DataView) this.data[nodePath];
				if(table != null && table == this.dataGrid.DataSource)
				{
					// Grid is already in view
					if(!cell.Equals(anyCell)) this.dataGrid.CurrentCell = cell;
					return;
				}
				if(cell.Equals(anyCell)) cell = zeroCell;

				if(this.historyBack.Count == 0 || nodePath != (string) this.historyBack.Peek())
				{
					this.historyBack.Push(nodePath);
					if(this.cellHistoryBack.Count > 0 && this.historyForward != null)
					{
						this.cellHistoryBack.Pop();
						this.cellHistoryBack.Push(this.dataGrid.CurrentCell);
					}
					this.cellHistoryBack.Push(cell);
				}
				if(this.historyForward != null)
				{
					this.historyForward.Clear();
					this.cellHistoryForward.Clear();
				}

				if(table != null || nodePath.Length == 0 || this.dataProviderMap[nodePath] == null)
				{
					this.dataGrid.CaptionText = nodePath;
					this.dataGrid.CaptionBackColor = SystemColors.ActiveCaption;
					this.dataGrid.CaptionForeColor = SystemColors.ActiveCaptionText;
					this.dataGrid.DataSource = table;
					this.dataGrid.CurrentCell = cell;
					this.dataGrid.Focus();
				}
				else
				{
					this.dataGrid.CaptionText = nodePath + " (loading...)";
					this.dataGrid.CaptionBackColor = SystemColors.InactiveCaption;
					this.dataGrid.CaptionForeColor = SystemColors.InactiveCaptionText;
					this.dataGrid.DataSource = table;
					if(!this.tablesLoading.Contains(nodePath))
					{
						this.tablesLoading.Add(nodePath);
						this.SetCursor();
						#if SINGLETHREAD
						this.LoadTable(nodePath);
						#else
						new WaitCallback(this.LoadTable).BeginInvoke(nodePath, null, null);
						#endif
					}
				}

				this.findButton.Enabled = this.findTextBox.Text.Length > 0 && !searching;

				TreeNode treeNode = this.FindNode(nodePath);
				if(treeNode != this.treeView.SelectedNode)
				{
					this.navigating = true;
					this.treeView.SelectedNode = treeNode;
					this.navigating = false;
				}
			}
		}