private int GetColumnBestHeight(DevExpress.XtraGrid.Columns.GridColumn column) { try { DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo viewInfo = GridView.GetViewInfo() as GridViewInfo; GridColumnInfoArgs ex = null; viewInfo.GInfo.AddGraphics(null); ex = new GridColumnInfoArgs(viewInfo.GInfo.Cache, null); try { ex.InnerElements.Add(new DrawElementInfo(new GlyphElementPainter(), new GlyphElementInfoArgs(viewInfo.View.Images, 0, null), StringAlignment.Near)); ex.SetAppearance(GridView.Appearance.HeaderPanel); ex.Caption = column.Caption; ex.CaptionRect = new Rectangle(0, 0, (int)(column.VisibleWidth - 10 * DpiXRel), 1000); } finally { viewInfo.GInfo.ReleaseGraphics(); } GraphicsInfo grInfo = new GraphicsInfo(); grInfo.AddGraphics(null); ex.Cache = grInfo.Cache; Size captionSize = CalcCaptionTextSize(grInfo.Cache, ex as HeaderObjectInfoArgs, column.Caption); bool canDrawMore = true; Size res = ex.InnerElements.CalcMinSize(grInfo.Graphics, ref canDrawMore); res.Height = Math.Max(res.Height, captionSize.Height); res.Width += captionSize.Width; if (viewInfo.Painter != null) { res = viewInfo.Painter.ElementsPainter.Column.CalcBoundsByClientRectangle(ex, new Rectangle(Point.Empty, res)).Size; m_dictColumnHeight[column.Name] = res.Height; return(res.Height); } } catch (Exception ex) { MyLocalizer.XtraMessageBoxShow("В программе произошла ошибка. Описание: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(-1); }
private void grdViewArea_MouseDown(object sender, MouseEventArgs e) { if ((Control.ModifierKeys & Keys.Control) != Keys.Control) { GridView view = sender as GridView; GridHitInfo hi = view.CalcHitInfo(e.Location); if (hi.InRowCell) { if (hi.Column.RealColumnEdit.GetType() == typeof(RepositoryItemCheckEdit)) { view.FocusedRowHandle = hi.RowHandle; view.FocusedColumn = hi.Column; view.ShowEditor(); CheckEdit checkEdit = view.ActiveEditor as CheckEdit; CheckEditViewInfo checkInfo = (CheckEditViewInfo)checkEdit.GetViewInfo(); Rectangle glyphRect = checkInfo.CheckInfo.GlyphRect; DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo viewInfo = view.GetViewInfo() as DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo; Rectangle gridGlyphRect = new Rectangle(viewInfo.GetGridCellInfo(hi).Bounds.X + glyphRect.X, viewInfo.GetGridCellInfo(hi).Bounds.Y + glyphRect.Y, glyphRect.Width, glyphRect.Height); if (!gridGlyphRect.Contains(e.Location)) { view.CloseEditor(); if (!view.IsCellSelected(hi.RowHandle, hi.Column)) { view.SelectCell(hi.RowHandle, hi.Column); } else { view.UnselectCell(hi.RowHandle, hi.Column); } } else { checkEdit.Checked = !checkEdit.Checked; view.CloseEditor(); } (e as DevExpress.Utils.DXMouseEventArgs).Handled = true; } } } }