public void DumpGridColumnStylesCollection (GridColumnStylesCollection ts) { Console.WriteLine ("IsSynchronized {0} ", ts.IsSynchronized); Console.WriteLine ("SyncRoot {0} ", ts.SyncRoot); //Console.WriteLine ("IsFixedSize {0} ", ts.IsFixedSize); Console.WriteLine ("IsReadOnly {0} ", ts.IsReadOnly); }
/// <include file='doc\DataGridRow.uex' path='docs/doc[@for="DataGridRow.GetCellBounds"]/*' /> /// <devdoc> /// <para>When overridden in a derived class, gets the <see cref='System.Drawing.Rectangle'/> /// where a cell's contents gets painted.</para> /// </devdoc> public virtual Rectangle GetCellBounds(int col) { int firstVisibleCol = this.dgTable.DataGrid.FirstVisibleColumn; int cx = 0; Rectangle cellBounds = new Rectangle(); GridColumnStylesCollection columns = this.dgTable.GridColumnStyles; if (columns != null) { for (int i = firstVisibleCol; i < col; i++) { if (columns[i].PropertyDescriptor != null) { cx += columns[i].Width; } } int borderWidth = this.dgTable.GridLineWidth; cellBounds = new Rectangle(cx, 0, columns[col].Width - borderWidth, Height - borderWidth); } return(cellBounds); }
public DataGridTableStyle(bool isDefaultTableStyle) { is_default = isDefaultTableStyle; allow_sorting = true; datagrid = null; header_forecolor = def_header_forecolor; mapping_name = string.Empty; table_relations = new ArrayList(); column_styles = new GridColumnStylesCollection(this); alternating_backcolor = def_alternating_backcolor; columnheaders_visible = true; gridline_color = def_gridline_color; gridline_style = DataGridLineStyle.Solid; header_backcolor = def_header_backcolor; header_font = null; link_color = def_link_color; link_hovercolor = def_link_hovercolor; preferredcolumn_width = ThemeEngine.Current.DataGridPreferredColumnWidth; preferredrow_height = ThemeEngine.Current.DefaultFont.Height + 3; _readonly = false; rowheaders_visible = true; selection_backcolor = def_selection_backcolor; selection_forecolor = def_selection_forecolor; rowheaders_width = 35; backcolor = def_backcolor; forecolor = def_forecolor; }
public DataGridHeaderProvider(DataGridProvider provider, SWF.GridColumnStylesCollection styles) : base(null) { this.provider = provider; this.styles = styles; dictionary = new Dictionary <SWF.DataGridColumnStyle, DataGridHeaderItemProvider> (); }
internal protected override int MinimumRowHeight(GridColumnStylesCollection cols) { /* if (DataGrid != null && DataGrid.LinkFontHeight + this.dgTable.relationshipSpacing != relationshipHeight) { relationshipRect = Rectangle.Empty; relationshipHeight = DataGrid.LinkFontHeight + this.dgTable.relationshipSpacing; } */ return base.MinimumRowHeight(cols) + (this.expanded ? GetRelationshipRect().Height : 0); }
internal protected override int MinimumRowHeight(GridColumnStylesCollection cols) { /* * if (DataGrid != null && DataGrid.LinkFontHeight + this.dgTable.relationshipSpacing != relationshipHeight) { * relationshipRect = Rectangle.Empty; * relationshipHeight = DataGrid.LinkFontHeight + this.dgTable.relationshipSpacing; * } */ return(base.MinimumRowHeight(cols) + (this.expanded ? GetRelationshipRect().Height : 0)); }
/// <summary> /// 初始化mydataGrid网格 /// </summary> /// <param name="mydataGrid"></param> /// <param name="gridcolumn"></param> public static void myGridSelect(myDataGrid.myDataGrid mydataGrid, System.Windows.Forms.GridColumnStylesCollection gridcolumn) { for (int i = 0; i <= gridcolumn.Count - 1; i++) { if (gridcolumn[i].GetType().ToString() == "System.Windows.Forms.DataGridTextBoxColumn") { DataGridTextBoxColumn txtCol = (DataGridTextBoxColumn)gridcolumn[i]; txtCol.TextBox.Parent.Controls.Remove(txtCol.TextBox); } } }
private int PaintColumns(Graphics g, Rectangle bounds, DataGridState dgs, Font font, bool alignToRight, int[] colsNameWidths, int[] colsDataWidths, int skippedCells) { Rectangle containedRect = bounds; GridColumnStylesCollection gridColumnStyles = dgs.GridColumnStyles; int num = 0; for (int i = 0; i < gridColumnStyles.Count; i++) { if (num >= bounds.Width) { return(num); } if (((this.dataGrid.ParentRowsLabelStyle == DataGridParentRowsLabelStyle.ColumnName) || (this.dataGrid.ParentRowsLabelStyle == DataGridParentRowsLabelStyle.Both)) && (skippedCells >= this.horizOffset)) { containedRect.X = bounds.X + num; containedRect.Width = Math.Min(bounds.Width - num, colsNameWidths[i]); containedRect.X = this.MirrorRect(bounds, containedRect, alignToRight); string text = gridColumnStyles[i].HeaderText + ": "; this.PaintText(g, containedRect, text, font, false, alignToRight); num += containedRect.Width; } if (num >= bounds.Width) { return(num); } if (skippedCells < this.horizOffset) { skippedCells++; } else { containedRect.X = bounds.X + num; containedRect.Width = Math.Min(bounds.Width - num, colsDataWidths[i]); containedRect.X = this.MirrorRect(bounds, containedRect, alignToRight); gridColumnStyles[i].Paint(g, containedRect, (CurrencyManager)this.dataGrid.BindingContext[dgs.DataSource, dgs.DataMember], this.dataGrid.BindingContext[dgs.DataSource, dgs.DataMember].Position, this.BackBrush, this.ForeBrush, alignToRight); num += containedRect.Width; g.DrawLine(new Pen(SystemColors.ControlDark), alignToRight ? containedRect.X : containedRect.Right, containedRect.Y, alignToRight ? containedRect.X : containedRect.Right, containedRect.Bottom); num++; if (i < (gridColumnStyles.Count - 1)) { containedRect.X = bounds.X + num; containedRect.Width = Math.Min(bounds.Width - num, 3); containedRect.X = this.MirrorRect(bounds, containedRect, alignToRight); g.FillRectangle(this.BackBrush, containedRect); num += 3; } } } return(num); }
protected virtual void AddChildAccessibleObjects(IList children) { Debug.WriteLineIf(DataGrid.DataGridAcc.TraceVerbose, "Create row's accessible children"); Debug.Indent(); GridColumnStylesCollection cols = DataGrid.myGridTable.GridColumnStyles; int len = cols.Count; Debug.WriteLineIf(DataGrid.DataGridAcc.TraceVerbose, len + " columns present"); for (int i = 0; i < len; i++) { children.Add(CreateCellAccessibleObject(i)); } Debug.Unindent(); }
/// <include file='doc\DataGridRow.uex' path='docs/doc[@for="DataGridRow.OnKeyPress"]/*' /> /// <devdoc> /// <para>When overridden in a derived class, called by the <see cref='System.Windows.Forms.DataGrid'/> control when a key press occurs on a row with focus.</para> /// </devdoc> public virtual bool OnKeyPress(Keys keyData) { int currentColIndex = this.dgTable.DataGrid.CurrentCell.ColumnNumber; GridColumnStylesCollection columns = this.dgTable.GridColumnStyles; if (columns != null && currentColIndex >= 0 && currentColIndex < columns.Count) { DataGridColumnStyle currentColumn = columns[currentColIndex]; if (currentColumn.KeyPress(this.RowNumber, keyData)) { return(true); } } return(false); }
public virtual bool OnKeyPress(Keys keyData) { int columnNumber = this.dgTable.DataGrid.CurrentCell.ColumnNumber; GridColumnStylesCollection gridColumnStyles = this.dgTable.GridColumnStyles; if (((gridColumnStyles != null) && (columnNumber >= 0)) && (columnNumber < gridColumnStyles.Count)) { DataGridColumnStyle style = gridColumnStyles[columnNumber]; if (style.KeyPress(this.RowNumber, keyData)) { return(true); } } return(false); }
private int GetColDataBoxWidth(Graphics g, int colNum) { int num = 0; for (int i = 0; i < this.parentsCount; i++) { DataGridState state = (DataGridState)this.parents[i]; GridColumnStylesCollection gridColumnStyles = state.GridColumnStyles; if (colNum < gridColumnStyles.Count) { object columnValueAtRow = gridColumnStyles[colNum].GetColumnValueAtRow((CurrencyManager)this.dataGrid.BindingContext[state.DataSource, state.DataMember], state.LinkingRow.RowNumber); num = Math.Max(gridColumnStyles[colNum].GetPreferredSize(g, columnValueAtRow).Width, num); } } return(num); }
private int GetColBoxWidth(Graphics g, Font font, int colNum) { int num = 0; for (int i = 0; i < this.parentsCount; i++) { DataGridState state = (DataGridState)this.parents[i]; GridColumnStylesCollection gridColumnStyles = state.GridColumnStyles; if (colNum < gridColumnStyles.Count) { string text = gridColumnStyles[colNum].HeaderText + " :"; int width = (int)g.MeasureString(text, font).Width; num = Math.Max(width, num); } } return(num); }
// will return the width of the best fit for the column // private int GetColDataBoxWidth(Graphics g, int colNum) { int width = 0; for (int row = 0; row < parentsCount; row++) { DataGridState dgs = (DataGridState)parents[row]; GridColumnStylesCollection columns = dgs.GridColumnStyles; if (colNum < columns.Count) { object value = columns[colNum].GetColumnValueAtRow((CurrencyManager)dataGrid.BindingContext[dgs.DataSource, dgs.DataMember], dgs.LinkingRow.RowNumber); int size = columns[colNum].GetPreferredSize(g, value).Width; width = Math.Max(size, width); } } return(width); }
public virtual int PaintData(Graphics g, Rectangle bounds, int firstVisibleColumn, int columnCount, bool alignToRight) { Rectangle cellBounds = bounds; int width = this.dgTable.IsDefault ? this.DataGrid.GridLineWidth : this.dgTable.GridLineWidth; int num2 = 0; DataGridCell currentCell = this.dgTable.DataGrid.CurrentCell; GridColumnStylesCollection gridColumnStyles = this.dgTable.GridColumnStyles; int count = gridColumnStyles.Count; for (int i = firstVisibleColumn; i < count; i++) { if (num2 > bounds.Width) { break; } if ((gridColumnStyles[i].PropertyDescriptor != null) && (gridColumnStyles[i].Width > 0)) { cellBounds.Width = gridColumnStyles[i].Width - width; if (alignToRight) { cellBounds.X = (bounds.Right - num2) - cellBounds.Width; } else { cellBounds.X = bounds.X + num2; } Brush backBr = this.BackBrushForDataPaint(ref currentCell, gridColumnStyles[i], i); Brush foreBrush = this.ForeBrushForDataPaint(ref currentCell, gridColumnStyles[i], i); this.PaintCellContents(g, cellBounds, gridColumnStyles[i], backBr, foreBrush, alignToRight); if (width > 0) { g.FillRectangle(this.dgTable.IsDefault ? this.DataGrid.GridLineBrush : this.dgTable.GridLineBrush, alignToRight ? (cellBounds.X - width) : cellBounds.Right, cellBounds.Y, width, cellBounds.Height); } num2 += cellBounds.Width + width; } } if (num2 < bounds.Width) { g.FillRectangle(this.dgTable.DataGrid.BackgroundBrush, alignToRight ? bounds.X : (bounds.X + num2), bounds.Y, bounds.Width - num2, bounds.Height); } return(num2); }
// will return the width of the text box that will // fit all the column names private int GetColBoxWidth(Graphics g, Font font, int colNum) { int width = 0; for (int row = 0; row < parentsCount; row++) { DataGridState dgs = (DataGridState)parents[row]; GridColumnStylesCollection columns = dgs.GridColumnStyles; if (colNum < columns.Count) { // Graphics.MeasureString(...) returns different results for ": " than for " :" // string colName = columns[colNum].HeaderText + " :"; int size = (int)g.MeasureString(colName, font).Width; width = Math.Max(size, width); } } return(width); }
public void PushState(System.Windows.Forms.DataGrid dataGrid) { this.DataSource = dataGrid.DataSource; this.DataMember = dataGrid.DataMember; this.DataGrid = dataGrid; this.DataGridRows = dataGrid.DataGridRows; this.DataGridRowsLength = dataGrid.DataGridRowsLength; this.FirstVisibleRow = dataGrid.firstVisibleRow; this.FirstVisibleCol = dataGrid.firstVisibleCol; this.CurrentRow = dataGrid.currentRow; this.GridColumnStyles = new GridColumnStylesCollection(dataGrid.myGridTable); this.GridColumnStyles.Clear(); foreach (DataGridColumnStyle style in dataGrid.myGridTable.GridColumnStyles) { this.GridColumnStyles.Add(style); } this.ListManager = dataGrid.ListManager; this.ListManager.ItemChanged += new ItemChangedEventHandler(this.DataSource_Changed); this.ListManager.MetaDataChanged += new EventHandler(this.DataSource_MetaDataChanged); this.CurrentCol = dataGrid.currentCol; }
internal protected virtual int MinimumRowHeight(GridColumnStylesCollection columns) { int h = dgTable.IsDefault ? this.DataGrid.PreferredRowHeight : dgTable.PreferredRowHeight; try { if (this.dgTable.DataGrid.DataSource != null) { int nCols = columns.Count; for (int i = 0; i < nCols; ++i) { // if (columns[i].Visible && columns[i].PropertyDescriptor != null) if (columns[i].PropertyDescriptor != null) { h = Math.Max(h, columns[i].GetMinimumHeight()); } } } } catch (Exception) { } return(h); }
internal void OnLayout() { if (this.parentsCount != this.rowHeights.Count) { int num = 0; if (this.totalHeight == 0) { this.totalHeight += 2 * this.borderWidth; } this.textRegionHeight = this.dataGrid.Font.Height + 2; if (this.parentsCount > this.rowHeights.Count) { for (int i = this.rowHeights.Count; i < this.parentsCount; i++) { DataGridState state = (DataGridState)this.parents[i]; GridColumnStylesCollection gridColumnStyles = state.GridColumnStyles; int num4 = 0; for (int j = 0; j < gridColumnStyles.Count; j++) { num4 = Math.Max(num4, gridColumnStyles[j].GetMinimumHeight()); } num = Math.Max(num4, this.textRegionHeight) + 1; this.rowHeights.Add(num); this.totalHeight += num; } } else { if (this.parentsCount == 0) { this.totalHeight = 0; } else { this.totalHeight -= (int)this.rowHeights[this.rowHeights.Count - 1]; } this.rowHeights.RemoveAt(this.rowHeights.Count - 1); } } }
public virtual Rectangle GetCellBounds(int col) { int firstVisibleColumn = this.dgTable.DataGrid.FirstVisibleColumn; int x = 0; Rectangle rectangle = new Rectangle(); GridColumnStylesCollection gridColumnStyles = this.dgTable.GridColumnStyles; if (gridColumnStyles == null) { return(rectangle); } for (int i = firstVisibleColumn; i < col; i++) { if (gridColumnStyles[i].PropertyDescriptor != null) { x += gridColumnStyles[i].Width; } } int gridLineWidth = this.dgTable.GridLineWidth; return(new Rectangle(x, 0, gridColumnStyles[col].Width - gridLineWidth, this.Height - gridLineWidth)); }
/// <summary> /// Called by a DataGrid when it wishes to preserve its /// transient state in the current DataGridState object. /// </summary> public void PushState(DataGrid dataGrid) { DataSource = dataGrid.DataSource; DataMember = dataGrid.DataMember; DataGrid = dataGrid; DataGridRows = dataGrid.DataGridRows; DataGridRowsLength = dataGrid.DataGridRowsLength; FirstVisibleRow = dataGrid.firstVisibleRow; FirstVisibleCol = dataGrid.firstVisibleCol; CurrentRow = dataGrid.currentRow; GridColumnStyles = new GridColumnStylesCollection(dataGrid.myGridTable); GridColumnStyles.Clear(); foreach (DataGridColumnStyle style in dataGrid.myGridTable.GridColumnStyles) { GridColumnStyles.Add(style); } ListManager = dataGrid.ListManager; ListManager.ItemChanged += new ItemChangedEventHandler(DataSource_Changed); ListManager.MetaDataChanged += new EventHandler(DataSource_MetaDataChanged); CurrentCol = dataGrid.currentCol; }
protected internal virtual int MinimumRowHeight(GridColumnStylesCollection columns) { int num = this.dgTable.IsDefault ? this.DataGrid.PreferredRowHeight : this.dgTable.PreferredRowHeight; try { if (this.dgTable.DataGrid.DataSource == null) { return(num); } int count = columns.Count; for (int i = 0; i < count; i++) { if (columns[i].PropertyDescriptor != null) { num = Math.Max(num, columns[i].GetMinimumHeight()); } } } catch { } return(num); }
private int MoveLeftRight(GridColumnStylesCollection cols, int startCol, bool goRight) { int num; if (goRight) { num = startCol + 1; while (num < cols.Count) { if (cols[num].PropertyDescriptor != null) { return num; } num++; } return num; } num = startCol - 1; while (num >= 0) { if (cols[num].PropertyDescriptor != null) { return num; } num--; } return num; }
public DataGridTableStyle (bool isDefaultTableStyle) { is_default = isDefaultTableStyle; allow_sorting = true; datagrid = null; header_forecolor = def_header_forecolor; mapping_name = string.Empty; table_relations = new ArrayList (); column_styles = new GridColumnStylesCollection (this); alternating_backcolor = def_alternating_backcolor; columnheaders_visible = true; gridline_color = def_gridline_color; gridline_style = DataGridLineStyle.Solid; header_backcolor = def_header_backcolor; header_font = null; link_color = def_link_color; link_hovercolor = def_link_hovercolor; preferredcolumn_width = ThemeEngine.Current.DataGridPreferredColumnWidth; preferredrow_height = ThemeEngine.Current.DefaultFont.Height + 3; _readonly = false; rowheaders_visible = true; selection_backcolor = def_selection_backcolor; selection_forecolor = def_selection_forecolor; rowheaders_width = 35; backcolor = def_backcolor; forecolor = def_forecolor; }
public virtual int PaintData(Graphics g, Rectangle bounds, int firstVisibleColumn, int columnCount, bool alignToRight) { Debug.WriteLineIf(CompModSwitches.DGRowPaint.TraceVerbose, "Painting DataGridAddNewRow: bounds = " + bounds.ToString()); Rectangle cellBounds = bounds; int bWidth = this.dgTable.IsDefault ? this.DataGrid.GridLineWidth : this.dgTable.GridLineWidth; int cx = 0; DataGridCell current = this.dgTable.DataGrid.CurrentCell; GridColumnStylesCollection columns = dgTable.GridColumnStyles; int nCols = columns.Count; for (int col = firstVisibleColumn; col < nCols; ++col) { if (cx > bounds.Width) { break; } // if (!columns[col].Visible || columns[col].PropertyDescriptor == null) if (columns[col].PropertyDescriptor == null || columns[col].Width <= 0) { continue; } cellBounds.Width = columns[col].Width - bWidth; if (alignToRight) { cellBounds.X = bounds.Right - cx - cellBounds.Width; } else { cellBounds.X = bounds.X + cx; } // Paint the data with the the DataGridColumn Brush backBr = BackBrushForDataPaint(ref current, columns[col], col); Brush foreBrush = ForeBrushForDataPaint(ref current, columns[col], col); PaintCellContents(g, cellBounds, columns[col], backBr, foreBrush, alignToRight); // Paint the border to the right of each cell if (bWidth > 0) { g.FillRectangle(this.dgTable.IsDefault ? this.DataGrid.GridLineBrush : this.dgTable.GridLineBrush, alignToRight ? cellBounds.X - bWidth : cellBounds.Right, cellBounds.Y, bWidth, cellBounds.Height); } cx += cellBounds.Width + bWidth; } // Paint any exposed area to the right ( or left ) of the data cell area if (cx < bounds.Width) { g.FillRectangle(this.dgTable.DataGrid.BackgroundBrush, alignToRight ? bounds.X : bounds.X + cx, bounds.Y, bounds.Width - cx, bounds.Height); } return(cx); }
public DataGridTableStyle(bool isDefaultTableStyle) { this.relationshipRect = Rectangle.Empty; this.focusedRelation = -1; this.relationsList = new ArrayList(2); this.mappingName = ""; this.allowSorting = true; this.alternatingBackBrush = DefaultAlternatingBackBrush; this.backBrush = DefaultBackBrush; this.foreBrush = DefaultForeBrush; this.gridLineBrush = DefaultGridLineBrush; this.gridLineStyle = DataGridLineStyle.Solid; this.headerBackBrush = DefaultHeaderBackBrush; this.headerForeBrush = DefaultHeaderForeBrush; this.headerForePen = DefaultHeaderForePen; this.linkBrush = DefaultLinkBrush; this.preferredColumnWidth = 0x4b; this.prefferedRowHeight = defaultFontHeight + 3; this.selectionBackBrush = DefaultSelectionBackBrush; this.selectionForeBrush = DefaultSelectionForeBrush; this.rowHeaderWidth = 0x23; this.rowHeadersVisible = true; this.columnHeadersVisible = true; this.gridColumns = new GridColumnStylesCollection(this, isDefaultTableStyle); this.gridColumns.CollectionChanged += new CollectionChangeEventHandler(this.OnColumnCollectionChanged); this.isDefaultTableStyle = isDefaultTableStyle; }
protected internal virtual int MinimumRowHeight(GridColumnStylesCollection columns) { int num = this.dgTable.IsDefault ? this.DataGrid.PreferredRowHeight : this.dgTable.PreferredRowHeight; try { if (this.dgTable.DataGrid.DataSource == null) { return num; } int count = columns.Count; for (int i = 0; i < count; i++) { if (columns[i].PropertyDescriptor != null) { num = Math.Max(num, columns[i].GetMinimumHeight()); } } } catch { } return num; }
/// <include file='doc\DataGridTable.uex' path='docs/doc[@for="DataGridTableStyle.DataGridTableStyle"]/*' /> /// <internalonly/> /// <devdoc> /// <para>Initializes a new instance of the <see cref='System.Windows.Forms.DataGridTableStyle'/> class.</para> /// </devdoc> public DataGridTableStyle(bool isDefaultTableStyle) { gridColumns = new GridColumnStylesCollection(this, isDefaultTableStyle); gridColumns.CollectionChanged += new CollectionChangeEventHandler(this.OnColumnCollectionChanged); this.isDefaultTableStyle = isDefaultTableStyle; }
protected internal override int MinimumRowHeight(GridColumnStylesCollection cols) { return (base.MinimumRowHeight(cols) + (this.expanded ? this.GetRelationshipRect().Height : 0)); }
internal protected virtual int MinimumRowHeight(GridColumnStylesCollection columns) { int h = dgTable.IsDefault ? this.DataGrid.PreferredRowHeight : dgTable.PreferredRowHeight; try { if (this.dgTable.DataGrid.DataSource != null) { int nCols = columns.Count; for (int i = 0; i < nCols; ++i) { // if (columns[i].Visible && columns[i].PropertyDescriptor != null) if (columns[i].PropertyDescriptor != null) h = Math.Max(h, columns[i].GetMinimumHeight()); } } } catch { } return h; }
// called from DataGrid::OnLayout internal void OnLayout() { if (parentsCount == rowHeights.Count) { return; } int height = 0; if (totalHeight == 0) { totalHeight += 2 * borderWidth; } // figure out how tall each row's text will be // textRegionHeight = (int)dataGrid.Font.Height + 2; // make the height of the Column.Font count for the height // of the parentRows; // // if the user wants to programatically // navigate to a relation in the constructor of the form // ( ie, when the form does not process PerformLayout ) // the grid will receive an OnLayout message when there is more // than one parent in the grid if (parentsCount > rowHeights.Count) { Debug.Assert(parentsCount == rowHeights.Count + 1 || rowHeights.Count == 0, "see comment above for more info"); int rowHeightsCount = this.rowHeights.Count; for (int i = rowHeightsCount; i < parentsCount; i++) { DataGridState dgs = (DataGridState)parents[i]; GridColumnStylesCollection cols = dgs.GridColumnStyles; int colsHeight = 0; for (int j = 0; j < cols.Count; j++) { colsHeight = Math.Max(colsHeight, cols[j].GetMinimumHeight()); } height = Math.Max(colsHeight, textRegionHeight); // the height of the bottom border height++; rowHeights.Add(height); totalHeight += height; } } else { Debug.Assert(parentsCount == rowHeights.Count - 1, "we do layout only for push/popTop"); if (parentsCount == 0) { totalHeight = 0; } else { totalHeight -= (int)rowHeights[rowHeights.Count - 1]; } rowHeights.RemoveAt(rowHeights.Count - 1); } }
private int PaintColumns(Graphics g, Rectangle bounds, DataGridState dgs, Font font, bool alignToRight, int[] colsNameWidths, int[] colsDataWidths, int skippedCells) { Rectangle paintBounds = bounds; Rectangle rowBounds = bounds; GridColumnStylesCollection cols = dgs.GridColumnStyles; int cx = 0; for (int i = 0; i < cols.Count; i++) { if (cx >= bounds.Width) { break; } // paint the column name, if we have to if (dataGrid.ParentRowsLabelStyle == DataGridParentRowsLabelStyle.ColumnName || dataGrid.ParentRowsLabelStyle == DataGridParentRowsLabelStyle.Both) { if (skippedCells < horizOffset) { // skip this column } else { paintBounds.X = bounds.X + cx; paintBounds.Width = Math.Min(bounds.Width - cx, colsNameWidths[i]); paintBounds.X = MirrorRect(bounds, paintBounds, alignToRight); string colName = cols[i].HeaderText + ": "; PaintText(g, paintBounds, colName, font, false, alignToRight); // false is for not painting bold cx += paintBounds.Width; } } if (cx >= bounds.Width) { break; } if (skippedCells < horizOffset) { // skip this cell skippedCells++; } else { // paint the cell contents paintBounds.X = bounds.X + cx; paintBounds.Width = Math.Min(bounds.Width - cx, colsDataWidths[i]); paintBounds.X = MirrorRect(bounds, paintBounds, alignToRight); // when we paint the data grid parent rows, we want to paint the data at the position // stored in the currency manager. cols[i].Paint(g, paintBounds, (CurrencyManager)dataGrid.BindingContext[dgs.DataSource, dgs.DataMember], dataGrid.BindingContext[dgs.DataSource, dgs.DataMember].Position, BackBrush, ForeBrush, alignToRight); cx += paintBounds.Width; // draw the line to the right (or left, according to alignRight) // g.DrawLine(new Pen(SystemColors.ControlDark), alignToRight ? paintBounds.X : paintBounds.Right, paintBounds.Y, alignToRight ? paintBounds.X : paintBounds.Right, paintBounds.Bottom); // this is how wide the line is.... cx++; // put 3 pixels in between columns // see DonnaWa // if (i < cols.Count - 1) { paintBounds.X = bounds.X + cx; paintBounds.Width = Math.Min(bounds.Width - cx, 3); paintBounds.X = MirrorRect(bounds, paintBounds, alignToRight); g.FillRectangle(BackBrush, paintBounds); cx += 3; } } } return(cx); }
/// <summary> /// Get Header Title and Index of table of DataGridTableStyle /// </summary> /// <param name="view"></param> /// <param name="cols"></param> /// <param name="headers"></param> /// <param name="indexes"></param> /// <remarks> /// Author: PhatLT. FPTSS. /// Created date: 14/02/2011 /// </remarks> public void GetExportInfo(DataView view, GridColumnStylesCollection cols, ref string[]headers, ref int [] indexes) { int count = cols.Count; headers = new string[count]; indexes = new int[count]; DataTable dt = view.Table; for(int i = 0; i < count; i ++) { headers[i] = cols[i].HeaderText; indexes[i] = GetColumnIndex(dt, cols[i].MappingName); } }
public static void myGridSelect(TrasenClasses.GeneralControls.ButtonDataGridEx mydataGrid, System.Windows.Forms.GridColumnStylesCollection gridcolumn) { for (int i = 0; i <= gridcolumn.Count - 1; i++) { if (gridcolumn[i].GetType().ToString() == "TrasenClasses.GeneralControls.DataGridEnableTextBoxColumn") { DataGridEnableTextBoxColumn txtCol = (DataGridEnableTextBoxColumn)gridcolumn[i]; if (txtCol.TextBox.Parent != null) { txtCol.TextBox.Parent.Controls.Remove(txtCol.TextBox); } } } }
protected internal override int MinimumRowHeight(GridColumnStylesCollection cols) { return(base.MinimumRowHeight(cols) + (this.expanded ? this.GetRelationshipRect().Height : 0)); }
/// <summary> /// Initiates a recalculation of the needed filter GUI elements and their positions. /// </summary> private void RecreateGridFilters() { //first clean up what has beed done before foreach (DataGridColumnStyle columnStyle in _columnStyleToGridFilterHash.Keys) { IGridFilter gridFilter = _columnStyleToGridFilterHash[columnStyle] as IGridFilter; gridFilter.Changed -= new EventHandler(OnFilterChanged); gridFilter.FilterControl.KeyPress -= new KeyPressEventHandler(OnFilterControlKeyPress); gridFilter.FilterControl.Leave -= new EventHandler(OnFilterControlLeave); columnStyle.WidthChanged -= new EventHandler(OnColumnStyleWidthChanged); if (this.Controls.Contains(gridFilter.FilterControl)) { this.Controls.Remove(gridFilter.FilterControl); gridFilter.FilterControl.Dispose(); } } _columnStyleToGridFilterHash.Clear(); if (_currentTableStyle != null) { _currentTableStyle.RowHeaderWidthChanged -= new EventHandler(OnCurrentTableStyleRowHeaderWidthChanged); _currentTableStyle.RowHeadersVisibleChanged -= new EventHandler(OnCurrentTableStyleRowHeadersVisibleChanged); _currentColumnStyleCollection.CollectionChanged -= new CollectionChangeEventHandler(OnGridColumnStylesCollectionChanged); _currentTableStyle = null; _currentColumnStyleCollection = null; } //adjust the position for the filter GUI this.Height = _refBox.Height; if (_gridExtension == null) return; _lblFilter.Width = _grid.RowHeaderWidth; if (_gridExtension.CurrentView == null) { //provide a dummy represantation when nothing is set //this allows better desing time support _refBox.Visible = true; _refBox.Left = _grid.RowHeaderWidth + 1; _refBox.Width = this.Width - _grid.RowHeaderWidth - 1; return; } _refBox.Visible = false; if (_grid.TableStyles.Contains(_gridExtension.CurrentView.Table.TableName)) { //get the appropriate table style _currentTableStyle = _grid.TableStyles[_gridExtension.CurrentView.Table.TableName]; _currentTableStyle.RowHeaderWidthChanged += new EventHandler(OnCurrentTableStyleRowHeaderWidthChanged); _currentTableStyle.RowHeadersVisibleChanged += new EventHandler(OnCurrentTableStyleRowHeadersVisibleChanged); _currentColumnStyleCollection = _currentTableStyle.GridColumnStyles; _currentColumnStyleCollection.CollectionChanged += new CollectionChangeEventHandler(OnGridColumnStylesCollectionChanged); _filterFactory.BeginGridFilterCreation(); try { foreach (DataGridColumnStyle columnStyle in _currentColumnStyleCollection) { //we need notification when the width of the column changes columnStyle.WidthChanged += new EventHandler(OnColumnStyleWidthChanged); //get the datatype Type dataType = _gridExtension.CurrentView.Table.Columns[columnStyle.MappingName].DataType; //create a filter IGridFilter gridFilter = _filterFactory.CreateGridFilter(_gridExtension.CurrentView.Table.Columns[columnStyle.MappingName], columnStyle); if (!gridFilter.UseCustomFilterPlacement) { //adjust the vertical positions gridFilter.FilterControl.Top = 0; gridFilter.FilterControl.Height = this.Height; gridFilter.FilterControl.Visible = false; //add the GUI element to our controls collection this.Controls.Add(gridFilter.FilterControl); gridFilter.FilterControl.BringToFront(); } //notification needed when the filter settings are changed gridFilter.Changed += new EventHandler(OnFilterChanged); gridFilter.FilterControl.KeyPress += new KeyPressEventHandler(OnFilterControlKeyPress); gridFilter.FilterControl.Leave += new EventHandler(OnFilterControlLeave); //added to hash to provider fast access _columnStyleToGridFilterHash.Add(columnStyle, gridFilter); } } finally { _filterFactory.EndGridFilterCreation(); } if (_keepFilters && _keepFiltersHash.ContainsKey(_gridExtension.CurrentView.Table.TableName)) SetFilters((string[])_keepFiltersHash[_gridExtension.CurrentView.Table.TableName]); } RepositionGridFilters(); }
/// <summary> /// Returns an observable sequence wrapping the CollectionChanged event on the GridColumnStylesCollection instance. /// </summary> /// <param name="instance">The GridColumnStylesCollection instance to observe.</param> /// <returns>An observable sequence wrapping the CollectionChanged event on the GridColumnStylesCollection instance.</returns> public static IObservable <EventPattern <CollectionChangeEventArgs> > CollectionChangedObservable(this GridColumnStylesCollection instance) { return(Observable.FromEventPattern <CollectionChangeEventHandler, CollectionChangeEventArgs>( handler => instance.CollectionChanged += handler, handler => instance.CollectionChanged -= handler)); }