private void toolTipController1_GetActiveObjectInfo(object sender, DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs e) { Point pt = e.ControlMousePosition; GridView view = gridView1; GridHitInfo hi = view.CalcHitInfo(pt); GridViewInfo viewInfo = view.GetViewInfo() as GridViewInfo; if (viewInfo == null) { return; } if (hi.InColumnPanel && hi.Column != null) { viewInfo.GetColumnLeftCoord(hi.Column); int columnLeftCoord = viewInfo.GetColumnLeftCoord(hi.Column); DevExpress.XtraGrid.Drawing.GridColumnInfoArgs columnInfo = viewInfo.ColumnsInfo[hi.Column]; e.Info = new DevExpress.Utils.ToolTipControlInfo(hi.Column, string.Format("'{0}'; left coord:{1}", columnInfo.Caption, columnLeftCoord)); } if (hi.InRowCell) { GridCellInfo cellInfo = viewInfo.GetGridCellInfo(hi); e.Info = new DevExpress.Utils.ToolTipControlInfo(cellInfo, string.Format("{0}: ({1}, {2})", cellInfo.ViewInfo.DisplayText, cellInfo.RowHandle, cellInfo.Column)); } if (hi.InGroupPanel) { Rectangle clientBounds = viewInfo.GroupPanel.ViewInfo.ClientBounds; e.Info = new DevExpress.Utils.ToolTipControlInfo(viewInfo.GroupPanel, string.Format("Group Panel: {0}", clientBounds)); } }
private void UpdateGridSize() { GridViewInfo viewInfo = (GridViewInfo)gridView1.GetViewInfo(); FieldInfo fi = typeof(GridView).GetField("scrollInfo", BindingFlags.Instance | BindingFlags.NonPublic); ScrollInfo scrollInfo = (ScrollInfo)fi.GetValue(gridView1); int width = viewInfo.ViewRects.IndicatorWidth; foreach (GridColumn column in gridView1.VisibleColumns) { if (viewInfo.GetColumnLeftCoord(column) < viewInfo.ViewRects.ColumnPanelWidth) { gridView1.LeftCoord = width; } width += viewInfo.ColumnsInfo[column].Bounds.Width; } if (scrollInfo.VScrollVisible) { width += scrollInfo.VScrollSize; } int height = viewInfo.CalcRealViewHeight(new Rectangle(0, 0, ClientSize.Width, ClientSize.Height), true); if (scrollInfo.HScrollVisible) { height += scrollInfo.HScrollSize; } width = Math.Max(GridMinWidth, width); width = Math.Min(ClientSize.Width - gridControl1.Location.X, width); height = Math.Max(GridMinHeight, height); height = Math.Min(ClientSize.Height - gridControl1.Location.Y, height); gridControl1.Size = new Size(width, height); gridView1.LayoutChanged(); }
private bool sortRuleSelect = true;//任务列排列的方式,true表示正序,false表示倒序 private void gridSelectAttribute_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { try { GridHitInfo gridHitInfo = gviewSelect.CalcHitInfo(e.X, e.Y); if (gridHitInfo.InColumnPanel) { GridViewInfo gridViewInfo = (GridViewInfo)gviewSelect.GetViewInfo(); if (!gridHitInfo.InColumn) { return; } int x = gridViewInfo.GetColumnLeftCoord(gridHitInfo.Column) + gridHitInfo.Column.Width; if (e.X < x + 20) { string sortColnumName = gridHitInfo.Column.FieldName; sortRuleSelect = !sortRuleSelect; selectionRowsTable = SortTable(selectionRowsTable.Copy(), sortColnumName, sortRuleSelect); ctrlGridNavigation1.InitCtrl(selectionRowsTable, gridSelectAttribute, new int[] { 50, 100, 500 }); gviewSelect.BestFitColumns(); gridSelectAttribute.RefreshDataSource(); } } } catch (Exception ex) { XtraMessageBox.Show("属性表排序错误"); } } }
private bool sortRuleAll = true;//任务列排列的方式,true表示正序,false表示倒序 private void gridAllAttribute_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { try { GridHitInfo gridHitInfo = gviewAll.CalcHitInfo(e.X, e.Y); if (gridHitInfo.InColumnPanel) { GridViewInfo gridViewInfo = (GridViewInfo)gviewAll.GetViewInfo(); if (!gridHitInfo.InColumn) { return; } int x = gridViewInfo.GetColumnLeftCoord(gridHitInfo.Column) + gridHitInfo.Column.Width; if (e.X <= x + 20) { string sortColnumName = gridHitInfo.Column.FieldName; sortRuleAll = !sortRuleAll; allRowsTable = SortTable(allRowsTable.Copy(), sortColnumName, sortRuleAll); allRowsTable.PrimaryKey = new DataColumn[] { allRowsTable.Columns[oidFieldName] }; ctrlGridNavigation1.InitCtrl(allRowsTable, gridAllAttribute, new int[] { 50, 100, 500 }); gviewAll.BestFitColumns(); gridAllAttribute.RefreshDataSource(); } } } catch (Exception ex) { XtraMessageBox.Show("排序错误"); } } else if (e.Button == MouseButtons.Right) { GridHitInfo gridHitInfo = gviewAll.CalcHitInfo(e.X, e.Y); if (gridHitInfo.InColumnPanel) { GridViewInfo gridViewInfo = (GridViewInfo)gviewAll.GetViewInfo(); if (!gridHitInfo.InColumn) { return; } if (gridHitInfo.Column.FieldName == "选中要素") { int x = Control.MousePosition.X; int y = Control.MousePosition.Y; popupMenu1.ShowPopup(new System.Drawing.Point(x, y)); } } } }