/// ------------------------------------------------------------------------------------ public void Show(DataGridViewCell cell, IEnumerable<string> items) { // This is sort of a kludge, but right before the first time the list is // displayed, it's handle hasn't been created therefore the preferred // size cannot be accurately determined and the preferred width is needed // below. So to ensure the handle gets created, show then hide the drop-down. if (!IsHandleCreated) { Size = new Size(0, 0); _dropDown.Show(0, 0); _dropDown.Close(); } Items.Clear(); Items.AddRange(items.ToArray()); SelectedItem = cell.Value as string; if (SelectedIndex < 0 && Items.Count > 0) SelectedIndex = 0; _associatedCell = cell; int col = cell.ColumnIndex; int row = cell.RowIndex; Width = Math.Max(cell.DataGridView.Columns[col].Width, _listBox.PreferredSize.Width); Height = (Math.Min(Items.Count, 15) * _listBox.ItemHeight) + Padding.Vertical + 2; var rc = cell.DataGridView.GetCellDisplayRectangle(col, row, false); rc.Y += rc.Height; _dropDown.Show(cell.DataGridView.PointToScreen(rc.Location)); _listBox.Focus(); }
public object getValueFromCell(DataGridViewCell cell) { object value = null; switch (cell.ValueType.Name) //need to do this because row.Cells["Value"].ValueType returns a string value for all cells { case "Boolean": value = bool.Parse(cell.EditedFormattedValue.ToString()); break; case "Byte": value = byte.Parse(cell.EditedFormattedValue.ToString()); break; case "List`1": value = new List<String>(new[] { cell.EditedFormattedValue.ToString() }); break; case "UInt32": value = UInt32.Parse(cell.EditedFormattedValue.ToString()); break; case "String": value = cell.EditedFormattedValue.ToString(); break; case "TraceType": value = Enum.Parse(typeof(TraceType), cell.Value.ToString()); break; default: break; } return value; }
void dataGridView_CurrentCellChanged(object sender, EventArgs e) { if (blockMessage) return; ClearInfo(); if (dataGridView.CurrentCell == null) return; int rowIndex = dataGridView.CurrentCell.RowIndex; int columnIndex = dataGridView.CurrentCell.ColumnIndex; if (!barcodes.IsTubeExists(rowIndex, columnIndex)) { ShowEmptyTubeWarning(); return; } RecoverSelectedCell();//recover light blue backcolor to its original one selectedCell = dataGridView.CurrentCell; string errMsg = ""; bool bConsistBarcode = barcodes.IsConsist(columnIndex,rowIndex,ref errMsg); if (!bConsistBarcode) { SetInfo(errMsg, Color.Red); } }
public bool Remove(DataGridViewCell dataGridViewCell) { DataGridViewCellLinkedListElement element = null; DataGridViewCellLinkedListElement headElement = this.headElement; while (headElement != null) { if (headElement.DataGridViewCell == dataGridViewCell) { break; } element = headElement; headElement = headElement.Next; } if (headElement.DataGridViewCell != dataGridViewCell) { return false; } DataGridViewCellLinkedListElement next = headElement.Next; if (element == null) { this.headElement = next; } else { element.Next = next; } this.count--; this.lastAccessedElement = null; this.lastAccessedIndex = -1; return true; }
private void editMenu_Clicked(object sender, ToolStripItemClickedEventArgs e) { //srcGrid.SelectedColumns[0].Index source = srcGrid.SelectedCells[0]; srcTab = cTab.SelectedIndex; cTab.SelectedIndex = destTab; }
/// <summary> /// Perform a function on grid cells. /// </summary> /// <param name="startCell">Cell from which to start. Does not wrap to start.</param> /// <param name="processStartCell">Whether to apply <see cref="function"/> to <see cref="startCell"/></param> /// <param name="stopOnFirstAction">Whether to halt processing the first time <see cref="function"/> returns true</param> /// <param name="function">Function to perform on the cell. Processing stops when this function returns true.</param> /// <returns>Whether the function ever returned true.</returns> public bool PerformOnCells(DataGridViewCell startCell, bool processStartCell, bool stopOnFirstAction, Func<DataGridViewCell, bool> function) { if (_grid == null || _grid.RowCount == 0 || _grid.ColumnCount == 0) return false; bool performed = false; int initialRow = startCell == null ? 0 : startCell.RowIndex; int initialCol = startCell == null ? 0 : startCell.ColumnIndex; int startRow = initialCol == 0 ? initialRow : initialRow + 1; for (int rowIndex = startRow; rowIndex < _grid.Rows.Count; rowIndex++) { DataGridViewRow row = _grid.Rows[rowIndex]; int startCol = (rowIndex == initialRow && !processStartCell && _grid.ColumnCount > 1) ? 1 : 0; for (int colIndex = startCol; colIndex < row.Cells.Count; colIndex++) { DataGridViewCell cell = row.Cells[colIndex]; performed |= function(cell); if (performed && stopOnFirstAction) return true; } } return performed; }
/// <summary> /// 显示药品字典最小元素信息查询窗体 /// </summary> /// <param name="p_strSearchCon">查询条件</param> /// <param name="p_dtbMedicint">字典内容</param> internal void m_mthShowQueryMedicineForm(string p_strSearchCon, DataTable p_dtbMedicint) { System.Windows.Forms.DataGridViewCell cCell = this.m_objViewer.m_dtgvMedicineDetail.CurrentCell; System.Drawing.Rectangle rect = m_objViewer.m_dtgvMedicineDetail.GetCellDisplayRectangle(cCell.ColumnIndex, cCell.RowIndex, true); if (m_ctlQueryMedicint == null) { m_ctlQueryMedicint = new ctlQueryMedicintLeastElement(p_dtbMedicint); m_objViewer.Controls.Add(m_ctlQueryMedicint); m_ctlQueryMedicint.ReturnInfo += new ReturnMedicineInfo(frmQueryForm_ReturnInfo); m_ctlQueryMedicint.RefreshMedicine += new RefreshMedicineInfo(m_ctlQueryMedicint_RefreshMedicine); } m_ctlQueryMedicint.Location = new System.Drawing.Point(rect.X + m_objViewer.m_dtgvMedicineDetail.Location.X, rect.Y + m_objViewer.m_dtgvMedicineDetail.Location.Y + rect.Height); if ((m_objViewer.Size.Height - m_ctlQueryMedicint.Location.Y) < m_ctlQueryMedicint.Size.Height) { m_ctlQueryMedicint.Location = new System.Drawing.Point(rect.X + m_objViewer.m_dtgvMedicineDetail.Location.X, rect.Y + m_objViewer.m_dtgvMedicineDetail.Location.Y - m_ctlQueryMedicint.Size.Height); } m_ctlQueryMedicint.Visible = true; m_ctlQueryMedicint.BringToFront(); m_ctlQueryMedicint.Focus(); m_ctlQueryMedicint.m_mthSetSearchText(p_strSearchCon); }
public static void disableCell(DataGridViewCell cell) { cell.ReadOnly = true; cell.Style.ForeColor = Color.DarkGray; cell.Style.BackColor = Color.LightGray; cell.Style.SelectionBackColor = Color.LightBlue; }
private void PerformExpandOrCollapse(bool expand) { if (provider.ItemProvider.DataGridView.InvokeRequired) { provider.ItemProvider.DataGridView.BeginInvoke(new ExpandOrCollapseDelegate(PerformExpandOrCollapse), new object [] { expand }); return; } SWF.DataGridViewCell oldCell = provider.ItemProvider.DataGridView.CurrentCell; provider.ItemProvider.DataGridView.CurrentCell = provider.ComboBoxCell; provider.ItemProvider.DataGridView.BeginEdit(false); SWF.ComboBox combobox = provider.ItemProvider.DataGridView.EditingControl as SWF.ComboBox; if (combobox != null) { // We we'll basically are keeping a reference to the EditingControl // to listen for DroppedDown event and set it when it changes. if (lastComboBox != combobox) { expandCollapseEvent.CurrentComboBox = combobox; } lastComboBox = combobox; lastComboBox.DroppedDown = expand; } else { provider.ItemProvider.DataGridView.EndEdit(); } provider.ItemProvider.DataGridView.CurrentCell = oldCell; }
public CellInfo(DataGridViewCell cell, DateTime monday) { int day = cell.ColumnIndex - 1; this.name = (cell.Value != null ? cell.Value.ToString() : ""); this.tag = (cell.Tag != null ? cell.Tag.ToString() : ""); this.toolTip = cell.ToolTipText; this.date = monday.AddDays(day); this.classTime = cell.RowIndex; // Get Homework string selectedDay = this.date.ToString("d.MM.yy"); foreach (HomeWork hw in Data.homework) { if (hw.date.ToString("d.MM.yy") == selectedDay) { if (hw.time == this.classTime) { this.homework.Add(hw); } } } }
public int getCellValue(System.Windows.Forms.DataGridView dgv) { System.Windows.Forms.DataGridViewCell dgvRow = dgv.FirstDisplayedCell; int val = Convert.ToInt32(dgvRow.Value.ToString()); return(val); }
private static Color GetForeColor(DataGridViewCell cell) { if (cell.Style.ForeColor != Color.Empty) return cell.Style.ForeColor; else return cell.OwningRow.DataGridView.DefaultCellStyle.ForeColor; }
public virtual int Add(DataGridViewCell e) { var x = (__DataGridViewCell)(object)e; InternalItems.Add(x); return InternalItems.Count - 1; }
private void ShowErrorMsgForCell(DataGridViewCell cell) { ShowErrorMsg(cell.ErrorText); _grid.Select(); foreach (DataGridViewCell c in _grid.SelectedCells) c.Selected = false; cell.Selected = true; }
private void SetCellColor(DataGridViewCell cell, Color fore, Color back) { cell.Style.BackColor = back; cell.Style.SelectionBackColor = back; cell.Style.ForeColor = fore; cell.Style.SelectionForeColor = fore; }
/// <include file='doc\DataGridViewCellStateChangedEventArgs.uex' path='docs/doc[@for="DataGridViewCellStateChangedEventArgs.DataGridViewCellStateChangedEventArgs"]/*' /> public DataGridViewCellStateChangedEventArgs(DataGridViewCell dataGridViewCell, DataGridViewElementStates stateChanged) { if (dataGridViewCell == null) { throw new ArgumentNullException("dataGridViewCell"); } this.dataGridViewCell = dataGridViewCell; this.stateChanged = stateChanged; }
public void add_grid_column(string name, string header, DataGridViewCell cell_template, DataGridView dgrdview) { DataGridViewColumn dgrdview_col = new DataGridViewColumn(); dgrdview_col.Width = column_width; dgrdview_col.Name = name; dgrdview_col.HeaderText = header; dgrdview_col.CellTemplate = cell_template; dgrdview.Columns.Add(dgrdview_col); }
public void Display(ref DataGridViewCell cell) { Opened = true; listBox1.DataSource = new BindingSource(Helper._elReader.Items, null); listBox1.DisplayMember = "Key"; listBox1.SelectedValueChanged += listBox1_SelectedValueChanged; _cell = cell; this.Show(); }
public ReceiptFilterInfoForm(DataGridViewCell cell, DataTable dt, string fieldName, string SStorehouseId, int matType) { InitializeComponent(); this.dt = dt; this.cell = cell; this.fieldName = fieldName; this.SStorehouseId = SStorehouseId; this.matType = matType; }
public void Display(int list, ref TextBox vv) { Result = null; cell = null; Opened = true; Show(); listBox1.DataSource = new BindingSource(Helper._elReader.Items.ElementAt(list - 1).Value, null); listBox1.DisplayMember = "EditorView"; Result = vv; }
public static string getCellValue(DataGridViewCell cell, bool text = false) { string str = ""; str += cell.Value; if (text) { str = "'" + str + "'"; } return str; }
public static int checkNullcell(DataGridViewCell cell) { if (cell.Value.ToString() == "") { MessageBox.Show("กรุณาระบุข้อมูลให้ครบถ้วน"); cell.Selected = true; return 0; } return 1; }
private static Font GetFont(DataGridViewCell cell, FontStyle fontStyle = FontStyle.Regular) { Font font; if (cell.Style.Font != null) font = cell.Style.Font; else font = cell.OwningRow.DataGridView.Font; return new Font(font, fontStyle); }
private void destDoubleClick(object sender, DataGridViewCellEventArgs e) { if (source == null) { return; } if (e.ColumnIndex < 1) { content = Field.getCellValue(destGrid.Rows[e.RowIndex].Cells[e.ColumnIndex]); source.Value = content; cTab.SelectedIndex = srcTab; source = null; } }
private void SetCellColor(DataGridViewCell cell) { if (cell.Style.BackColor == Color.Red) { cell.Style.BackColor = Color.Blue; } else { cell.Style.BackColor = Color.Red; } }
public static int checkNullcellMt(Form frm,DataGridViewCell cell) { if (cell.Value.ToString() == "") { cell.DataGridView.ClearSelection(); MetroFramework.MetroMessageBox.Show(frm, "กรุณาระบุข้อมูลให้ครบถ้วน", "ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Question); cell.Selected = true; return 0; } return 1; }
/// <include file='doc\DataGridViewColumn.uex' path='docs/doc[@for="DataGridViewColumn.DataGridViewColumn3"]/*' /> public DataGridViewColumn(DataGridViewCell cellTemplate) : base() { this.fillWeight = DATAGRIDVIEWCOLUMN_defaultFillWeight; this.usedFillWeight = DATAGRIDVIEWCOLUMN_defaultFillWeight; this.Thickness = DATAGRIDVIEWCOLUMN_defaultWidth; this.MinimumThickness = DATAGRIDVIEWCOLUMN_defaultMinColumnThickness; this.name = String.Empty; this.bandIsRow = false; this.displayIndex = -1; this.cellTemplate = cellTemplate; this.autoSizeMode = DataGridViewAutoSizeColumnMode.NotSet; }
public ViewColumn(IViewContext viewContext, ColumnPropertyDescriptor columnPropertyDescriptor, DataGridViewCell cellTemplate) : base(cellTemplate) { ViewContext = viewContext; ColumnPropertyDescriptor = columnPropertyDescriptor; SortMode = DataGridViewColumnSortMode.Automatic; if (columnPropertyDescriptor != null) { HeaderText = columnPropertyDescriptor.DisplayName; DataPropertyName = columnPropertyDescriptor.Name; Name = columnPropertyDescriptor.Name; } }
private void NewRow(int rowCount) { int lastEditableRow = gridDiveProfil.RowCount - 1; if (rowCount == lastEditableRow) { setDefault(); System.Windows.Forms.DataGridViewCell defautCell = gridDiveProfil["finialD", lastEditableRow]; gridDiveProfil.CurrentCell = defautCell; updateChartAndGridDiveProfile(); } }
internal int AddInternal(DataGridViewCell dataGridViewCell) { int num = this.items.Add(dataGridViewCell); dataGridViewCell.OwningRowInternal = this.owner; DataGridView dataGridView = this.owner.DataGridView; if ((dataGridView != null) && (dataGridView.Columns.Count > num)) { dataGridViewCell.OwningColumnInternal = dataGridView.Columns[num]; } this.OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Add, dataGridViewCell)); return num; }
public void Add(DataGridViewCell dataGridViewCell) { DataGridViewCellLinkedListElement element = new DataGridViewCellLinkedListElement(dataGridViewCell); if (this.headElement != null) { element.Next = this.headElement; } this.headElement = element; this.count++; this.lastAccessedElement = null; this.lastAccessedIndex = -1; }
public virtual int Add(DataGridViewCell dataGridViewCell) { if (this.owner.DataGridView != null) { throw new InvalidOperationException(System.Windows.Forms.SR.GetString("DataGridViewCellCollection_OwningRowAlreadyBelongsToDataGridView")); } if (dataGridViewCell.OwningRow != null) { throw new InvalidOperationException(System.Windows.Forms.SR.GetString("DataGridViewCellCollection_CellAlreadyBelongsToDataGridViewRow")); } return this.AddInternal(dataGridViewCell); }
public ContratoForm() { InitializeComponent(); InicializarCargaHorariaDGV(); CostoCB.SelectedIndex = 0; bcUC.cliPronto += new EventHandler(bcUC_cliPronto); stbuffer = @"N/T"; celda = null; bcUC.Controls["ClienteMT"].Focus(); idser = -1; }
private void setSegmentToGrid(int tableRow, Data.DiveSegment segment) { System.Windows.Forms.DataGridViewCell defautCell = gridDiveProfil["initialD", tableRow]; defautCell.Value = segment.InitialDepth; defautCell = gridDiveProfil["finialD", tableRow]; defautCell.Value = segment.FinialDepth; defautCell = gridDiveProfil["time", tableRow]; defautCell.Value = segment.Time; defautCell = gridDiveProfil["runTime", tableRow]; defautCell.Value = diving.getRunTime(0); defautCell = gridDiveProfil["gasName", tableRow]; defautCell.Value = segment.GasName; }
public ScriptEditor(FileManager fileManager, DataGridViewCell dataGridViewCell, String rowName, String colName) { InitializeComponent(); _fileManager = fileManager; _dataGridViewCell = dataGridViewCell; Text = String.Format("Script Editor: Row({0}) '{1}', Col({2}) '{3}'", dataGridViewCell.RowIndex, rowName, dataGridViewCell.ColumnIndex, colName); FontFamily fontFamily = new FontFamily("Courier New"); Font font = new Font(fontFamily, 10, FontStyle.Regular, GraphicsUnit.Point); _scriptEditor_RichTextBox.Font = font; _scriptEditor_RichTextBox.Text = (String)dataGridViewCell.Value; }
private void PerformSetValue(string value) { if (provider.ItemProvider.DataGridView.InvokeRequired) { provider.ItemProvider.DataGridView.BeginInvoke(new SetValueDelegate(PerformSetValue), new object [] { value }); return; } // Notice however that this is the weird behavior in .NET, because // editing an IsNewRow Row *WONT ADD* a new row SWF.DataGridViewCell oldCell = provider.ItemProvider.DataGridView.CurrentCell; provider.ItemProvider.DataGridView.CurrentCell = provider.TextBoxCell; provider.TextBoxCell.Value = value; provider.ItemProvider.DataGridView.CurrentCell = oldCell; }
private void PerformToggle(SWF.CheckState state) { if (provider.ItemProvider.DataGridView.InvokeRequired) { provider.ItemProvider.DataGridView.BeginInvoke(new PerformToggleDelegate(PerformToggle), new object [] { state }); return; } // FIXME: Validate InvalidCastException ? (thrown usually because of ValueType) SWF.DataGridViewCell oldCell = provider.ItemProvider.DataGridView.CurrentCell; provider.ItemProvider.DataGridView.CurrentCell = provider.CheckBoxCell; // provider.ItemProvider.DataGridView.BeginEdit (false); provider.CheckBoxCell.Value = state; // provider.ItemProvider.DataGridView.EndEdit (); provider.ItemProvider.DataGridView.CurrentCell = oldCell; }
private void m_dgvItem_CurrentCellChanged(object sender, EventArgs e) { if (this.m_dgvItem.CurrentCell.ColumnIndex == 6) { System.Windows.Forms.DataGridViewCell cCell = this.m_dgvItem.CurrentCell; string strOrgSFLBBH = ((DataRow)this.m_dgvItem.Rows[cCell.RowIndex].Tag)["sflb"].ToString(); System.Drawing.Rectangle rect = this.m_dgvItem.GetCellDisplayRectangle(cCell.ColumnIndex, cCell.RowIndex, true); DataView dtvSFLB = this.m_dtBseSFLB.DefaultView; dtvSFLB.RowFilter = "sflbbh in( " + m_strIDS + "'" + strOrgSFLBBH + "')"; this.cobSFLB.DataSource = dtvSFLB.ToTable(); this.cobSFLB.DisplayMember = "SFLB"; this.cobSFLB.ValueMember = "sflbbh"; DataGridViewRow cDGVR = this.m_dgvItem.CurrentRow; cobSFLB.Location = new System.Drawing.Point(rect.X + m_dgvItem.Location.X, rect.Y + m_dgvItem.Location.Y); this.cobSFLB.BringToFront(); this.cobSFLB.Focus(); DataRow[] m_dataRow = null; if (cDGVR.Cells[0].Tag == null) { m_dataRow = this.m_dtBseSFLB.Select("sflbbh = '" + cDGVR.Cells[6].Tag.ToString() + "'"); if (m_dataRow.Length > 0) { this.cobSFLB.Text = m_dataRow[0]["sflb"].ToString(); this.cobSFLB.SelectedValue = m_dataRow[0]["sflbbh"].ToString(); } } else { m_dataRow = this.m_dtBseSFLB.Select("sflbbh = '" + cDGVR.Cells[0].Tag.ToString() + "'"); if (m_dataRow.Length > 0) { this.cobSFLB.Text = m_dataRow[0]["sflb"].ToString(); this.cobSFLB.SelectedValue = m_dataRow[0]["sflbbh"].ToString(); } } } }
public void Insert(int index, DataGridViewCell dataGridViewCell) { throw new NotSupportedException(string.Format(SR.DataGridView_ReadOnlyCollection)); }
public DataGridViewLinkCellAccessibleObject(DataGridViewCell owner) : base(owner) { //DO NOTHING }
private Rectangle GetAdjustedEditingControlBounds(Rectangle editingControlBounds, DataGridViewCellStyle cellStyle) { Debug.Assert(cellStyle.WrapMode != DataGridViewTriState.NotSet); Debug.Assert(this.DataGridView != null); TextBox txtEditingControl = this.DataGridView.EditingControl as TextBox; int originalWidth = editingControlBounds.Width; if (txtEditingControl != null) { switch (cellStyle.Alignment) { case DataGridViewContentAlignment.TopLeft: case DataGridViewContentAlignment.MiddleLeft: case DataGridViewContentAlignment.BottomLeft: // Add 3 pixels on the left of the editing control to match non-editing text position if (this.DataGridView.RightToLeftInternal) { editingControlBounds.X += 1; editingControlBounds.Width = Math.Max(0, editingControlBounds.Width - DATAGRIDVIEWTEXTBOXCELL_horizontalTextOffsetLeft - 2); } else { editingControlBounds.X += DATAGRIDVIEWTEXTBOXCELL_horizontalTextOffsetLeft; editingControlBounds.Width = Math.Max(0, editingControlBounds.Width - DATAGRIDVIEWTEXTBOXCELL_horizontalTextOffsetLeft - 1); } break; case DataGridViewContentAlignment.TopCenter: case DataGridViewContentAlignment.MiddleCenter: case DataGridViewContentAlignment.BottomCenter: editingControlBounds.X += 1; editingControlBounds.Width = Math.Max(0, editingControlBounds.Width - 3); break; case DataGridViewContentAlignment.TopRight: case DataGridViewContentAlignment.MiddleRight: case DataGridViewContentAlignment.BottomRight: // Shorten the editing control by 5 pixels to match non-editing text position if (this.DataGridView.RightToLeftInternal) { editingControlBounds.X += DATAGRIDVIEWTEXTBOXCELL_horizontalTextOffsetRight - 1; editingControlBounds.Width = Math.Max(0, editingControlBounds.Width - DATAGRIDVIEWTEXTBOXCELL_horizontalTextOffsetRight); } else { editingControlBounds.X += 1; editingControlBounds.Width = Math.Max(0, editingControlBounds.Width - DATAGRIDVIEWTEXTBOXCELL_horizontalTextOffsetRight - 1); } break; } switch (cellStyle.Alignment) { case DataGridViewContentAlignment.TopLeft: case DataGridViewContentAlignment.TopCenter: case DataGridViewContentAlignment.TopRight: editingControlBounds.Y += DATAGRIDVIEWTEXTBOXCELL_verticalTextOffsetTop; editingControlBounds.Height = Math.Max(0, editingControlBounds.Height - DATAGRIDVIEWTEXTBOXCELL_verticalTextOffsetTop); break; case DataGridViewContentAlignment.MiddleLeft: case DataGridViewContentAlignment.MiddleCenter: case DataGridViewContentAlignment.MiddleRight: editingControlBounds.Height++; break; case DataGridViewContentAlignment.BottomLeft: case DataGridViewContentAlignment.BottomCenter: case DataGridViewContentAlignment.BottomRight: editingControlBounds.Height = Math.Max(0, editingControlBounds.Height - DATAGRIDVIEWTEXTBOXCELL_verticalTextOffsetBottom); break; } int preferredHeight; if (cellStyle.WrapMode == DataGridViewTriState.False) { preferredHeight = txtEditingControl.PreferredSize.Height; } else { string editedFormattedValue = (string)((IDataGridViewEditingControl)txtEditingControl).GetEditingControlFormattedValue(DataGridViewDataErrorContexts.Formatting); if (string.IsNullOrEmpty(editedFormattedValue)) { editedFormattedValue = " "; } TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(this.DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode); using (Graphics g = WindowsFormsUtils.CreateMeasurementGraphics()) { preferredHeight = DataGridViewCell.MeasureTextHeight(g, editedFormattedValue, cellStyle.Font, originalWidth, flags); } } if (preferredHeight < editingControlBounds.Height) { switch (cellStyle.Alignment) { case DataGridViewContentAlignment.TopLeft: case DataGridViewContentAlignment.TopCenter: case DataGridViewContentAlignment.TopRight: // Single pixel move - leave it as is for now break; case DataGridViewContentAlignment.MiddleLeft: case DataGridViewContentAlignment.MiddleCenter: case DataGridViewContentAlignment.MiddleRight: editingControlBounds.Y += (editingControlBounds.Height - preferredHeight) / 2; break; case DataGridViewContentAlignment.BottomLeft: case DataGridViewContentAlignment.BottomCenter: case DataGridViewContentAlignment.BottomRight: editingControlBounds.Y += editingControlBounds.Height - preferredHeight; break; } } } return(editingControlBounds); }
/// <include file='doc\DataGridViewCell.uex' path='docs/doc[@for="DataGridViewCell.GetPreferredSize"]/*' /> protected override Size GetPreferredSize(Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize) { if (this.DataGridView == null) { return(new Size(-1, -1)); } if (cellStyle == null) { throw new ArgumentNullException("cellStyle"); } Size preferredSize; Rectangle borderWidthsRect = this.StdBorderWidths; int borderAndPaddingWidths = borderWidthsRect.Left + borderWidthsRect.Width + cellStyle.Padding.Horizontal; int borderAndPaddingHeights = borderWidthsRect.Top + borderWidthsRect.Height + cellStyle.Padding.Vertical; DataGridViewFreeDimension freeDimension = DataGridViewCell.GetFreeDimensionFromConstraint(constraintSize); object formattedValue = GetFormattedValue(rowIndex, ref cellStyle, DataGridViewDataErrorContexts.Formatting | DataGridViewDataErrorContexts.PreferredSize); string formattedString = formattedValue as string; if (string.IsNullOrEmpty(formattedString)) { formattedString = " "; } TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(this.DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode); if (cellStyle.WrapMode == DataGridViewTriState.True && formattedString.Length > 1) { switch (freeDimension) { case DataGridViewFreeDimension.Width: { preferredSize = new Size(DataGridViewCell.MeasureTextWidth(graphics, formattedString, cellStyle.Font, Math.Max(1, constraintSize.Height - borderAndPaddingHeights - DATAGRIDVIEWTEXTBOXCELL_verticalTextMarginTopWithWrapping - DATAGRIDVIEWTEXTBOXCELL_verticalTextMarginBottom), flags), 0); break; } case DataGridViewFreeDimension.Height: { preferredSize = new Size(0, DataGridViewCell.MeasureTextHeight(graphics, formattedString, cellStyle.Font, Math.Max(1, constraintSize.Width - borderAndPaddingWidths - DATAGRIDVIEWTEXTBOXCELL_horizontalTextMarginLeft - DATAGRIDVIEWTEXTBOXCELL_horizontalTextMarginRight), flags)); break; } default: { preferredSize = DataGridViewCell.MeasureTextPreferredSize(graphics, formattedString, cellStyle.Font, 5.0F, flags); break; } } } else { switch (freeDimension) { case DataGridViewFreeDimension.Width: { preferredSize = new Size(DataGridViewCell.MeasureTextSize(graphics, formattedString, cellStyle.Font, flags).Width, 0); break; } case DataGridViewFreeDimension.Height: { preferredSize = new Size(0, DataGridViewCell.MeasureTextSize(graphics, formattedString, cellStyle.Font, flags).Height); break; } default: { preferredSize = DataGridViewCell.MeasureTextSize(graphics, formattedString, cellStyle.Font, flags); break; } } } if (freeDimension != DataGridViewFreeDimension.Height) { preferredSize.Width += DATAGRIDVIEWTEXTBOXCELL_horizontalTextMarginLeft + DATAGRIDVIEWTEXTBOXCELL_horizontalTextMarginRight + borderAndPaddingWidths; if (this.DataGridView.ShowCellErrors) { // Making sure that there is enough room for the potential error icon preferredSize.Width = Math.Max(preferredSize.Width, borderAndPaddingWidths + DATAGRIDVIEWCELL_iconMarginWidth * 2 + iconsWidth); } } if (freeDimension != DataGridViewFreeDimension.Width) { int verticalTextMarginTop = cellStyle.WrapMode == DataGridViewTriState.True ? DATAGRIDVIEWTEXTBOXCELL_verticalTextMarginTopWithWrapping : DATAGRIDVIEWTEXTBOXCELL_verticalTextMarginTopWithoutWrapping; preferredSize.Height += verticalTextMarginTop + DATAGRIDVIEWTEXTBOXCELL_verticalTextMarginBottom + borderAndPaddingHeights; if (this.DataGridView.ShowCellErrors) { // Making sure that there is enough room for the potential error icon preferredSize.Height = Math.Max(preferredSize.Height, borderAndPaddingHeights + DATAGRIDVIEWCELL_iconMarginHeight * 2 + iconsHeight); } } return(preferredSize); }
public void Insert(int index, DataGridViewCell dataGridViewCell) { throw new NotSupportedException("Can't insert to selected cell base.List"); }
public DataGridViewCheckBoxCellAccessibleObject(DataGridViewCell owner) : base(owner) { }
// PaintPrivate is used in three places that need to duplicate the paint code: // 1. DataGridViewCell::Paint method // 2. DataGridViewCell::GetContentBounds // 3. DataGridViewCell::GetErrorIconBounds // // if computeContentBounds is true then PaintPrivate returns the contentBounds // else if computeErrorIconBounds is true then PaintPrivate returns the errorIconBounds // else it returns Rectangle.Empty; private Rectangle PaintPrivate(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts, bool computeContentBounds, bool computeErrorIconBounds, bool paint) { // Parameter checking. // One bit and one bit only should be turned on Debug.Assert(paint || computeContentBounds || computeErrorIconBounds); Debug.Assert(!paint || !computeContentBounds || !computeErrorIconBounds); Debug.Assert(!computeContentBounds || !computeErrorIconBounds || !paint); Debug.Assert(!computeErrorIconBounds || !paint || !computeContentBounds); Debug.Assert(cellStyle != null); // If computeContentBounds == TRUE then resultBounds will be the contentBounds. // If computeErrorIconBounds == TRUE then resultBounds will be the error icon bounds. // Else resultBounds will be Rectangle.Empty; Rectangle resultBounds = Rectangle.Empty; Rectangle valBounds = cellBounds; Rectangle borderWidths = BorderWidths(advancedBorderStyle); valBounds.Offset(borderWidths.X, borderWidths.Y); valBounds.Width -= borderWidths.Right; valBounds.Height -= borderWidths.Bottom; bool cellSelected = (cellState & DataGridViewElementStates.Selected) != 0; if (paint && DataGridViewCell.PaintBackground(paintParts)) { if (this.DataGridView.ApplyVisualStylesToHeaderCells) { // Theming int state = (int)HeaderItemState.Normal; if (this.ButtonState != ButtonState.Normal) { Debug.Assert(this.ButtonState == ButtonState.Pushed); state = (int)HeaderItemState.Pressed; } else if (this.DataGridView.MouseEnteredCellAddress.Y == rowIndex && this.DataGridView.MouseEnteredCellAddress.X == this.ColumnIndex) { state = (int)HeaderItemState.Hot; } valBounds.Inflate(16, 16); DataGridViewTopLeftHeaderCellRenderer.DrawHeader(graphics, valBounds, state); valBounds.Inflate(-16, -16); } else { SolidBrush br = this.DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && cellSelected) ? cellStyle.SelectionBackColor : cellStyle.BackColor); if (br.Color.A == 255) { graphics.FillRectangle(br, valBounds); } } } if (paint && DataGridViewCell.PaintBorder(paintParts)) { PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } if (cellStyle.Padding != Padding.Empty) { if (this.DataGridView.RightToLeftInternal) { valBounds.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top); } else { valBounds.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top); } valBounds.Width -= cellStyle.Padding.Horizontal; valBounds.Height -= cellStyle.Padding.Vertical; } Rectangle errorBounds = valBounds; string formattedValueStr = formattedValue as string; // Font independent margins valBounds.Offset(DATAGRIDVIEWTOPLEFTHEADERCELL_horizontalTextMarginLeft, DATAGRIDVIEWTOPLEFTHEADERCELL_verticalTextMargin); valBounds.Width -= DATAGRIDVIEWTOPLEFTHEADERCELL_horizontalTextMarginLeft + DATAGRIDVIEWTOPLEFTHEADERCELL_horizontalTextMarginRight; valBounds.Height -= 2 * DATAGRIDVIEWTOPLEFTHEADERCELL_verticalTextMargin; if (valBounds.Width > 0 && valBounds.Height > 0 && !string.IsNullOrEmpty(formattedValueStr) && (paint || computeContentBounds)) { Color textColor; if (this.DataGridView.ApplyVisualStylesToHeaderCells) { textColor = DataGridViewTopLeftHeaderCellRenderer.VisualStyleRenderer.GetColor(ColorProperty.TextColor); } else { textColor = cellSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor; } TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(this.DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode); if (paint) { if (DataGridViewCell.PaintContentForeground(paintParts)) { if ((flags & TextFormatFlags.SingleLine) != 0) { flags |= TextFormatFlags.EndEllipsis; } TextRenderer.DrawText(graphics, formattedValueStr, cellStyle.Font, valBounds, textColor, flags); } } else { Debug.Assert(computeContentBounds); resultBounds = DataGridViewUtilities.GetTextBounds(valBounds, formattedValueStr, flags, cellStyle); } } else if (computeErrorIconBounds && !string.IsNullOrEmpty(errorText)) { resultBounds = ComputeErrorIconBounds(errorBounds); } if (this.DataGridView.ShowCellErrors && paint && DataGridViewCell.PaintErrorIcon(paintParts)) { PaintErrorIcon(graphics, cellStyle, rowIndex, cellBounds, errorBounds, errorText); } return(resultBounds); }
internal static Size GetPreferredRowHeaderSize(Graphics graphics, string val, DataGridViewCellStyle cellStyle, int borderAndPaddingWidths, int borderAndPaddingHeights, bool showRowErrors, bool showGlyph, Size constraintSize, TextFormatFlags flags) { Size preferredSize; DataGridViewFreeDimension freeDimension = DataGridViewCell.GetFreeDimensionFromConstraint(constraintSize); switch (freeDimension) { case DataGridViewFreeDimension.Width: { int preferredWidth = 0, allowedHeight = constraintSize.Height - borderAndPaddingHeights; if (!string.IsNullOrEmpty(val)) { int maxHeight = allowedHeight - 2 * DATAGRIDVIEWROWHEADERCELL_verticalTextMargin; if (maxHeight > 0) { if (cellStyle.WrapMode == DataGridViewTriState.True) { preferredWidth = DataGridViewCell.MeasureTextWidth(graphics, val, cellStyle.Font, maxHeight, flags); } else { preferredWidth = DataGridViewCell.MeasureTextSize(graphics, val, cellStyle.Font, flags).Width; } preferredWidth += 2 * DATAGRIDVIEWROWHEADERCELL_contentMarginWidth + DATAGRIDVIEWROWHEADERCELL_horizontalTextMarginLeft + DATAGRIDVIEWROWHEADERCELL_horizontalTextMarginRight; } } if (allowedHeight >= DATAGRIDVIEWROWHEADERCELL_iconsHeight + 2 * DATAGRIDVIEWROWHEADERCELL_iconMarginHeight) { if (showGlyph) { preferredWidth += DATAGRIDVIEWROWHEADERCELL_iconsWidth + 2 * DATAGRIDVIEWROWHEADERCELL_iconMarginWidth; } if (showRowErrors) { preferredWidth += DATAGRIDVIEWROWHEADERCELL_iconsWidth + 2 * DATAGRIDVIEWROWHEADERCELL_iconMarginWidth; } } preferredWidth = Math.Max(preferredWidth, 1); preferredWidth += borderAndPaddingWidths; return(new Size(preferredWidth, 0)); } case DataGridViewFreeDimension.Height: { int minHeightIcon = 1, minHeightContent = 1; int allowedWidth = constraintSize.Width - borderAndPaddingWidths; if (!string.IsNullOrEmpty(val)) { if (showGlyph && allowedWidth >= 2 * DATAGRIDVIEWROWHEADERCELL_iconMarginWidth + DATAGRIDVIEWROWHEADERCELL_iconsWidth) { // There is enough room for the status icon minHeightIcon = DATAGRIDVIEWROWHEADERCELL_iconsHeight + 2 * DATAGRIDVIEWROWHEADERCELL_iconMarginHeight; // Status icon takes priority allowedWidth -= 2 * DATAGRIDVIEWROWHEADERCELL_iconMarginWidth + DATAGRIDVIEWROWHEADERCELL_iconsWidth; } if (showRowErrors && allowedWidth >= 2 * DATAGRIDVIEWROWHEADERCELL_iconMarginWidth + DATAGRIDVIEWROWHEADERCELL_iconsWidth) { // There is enough room for the error icon minHeightIcon = DATAGRIDVIEWROWHEADERCELL_iconsHeight + 2 * DATAGRIDVIEWROWHEADERCELL_iconMarginHeight; // There is enough room for both the status and error icons allowedWidth -= 2 * DATAGRIDVIEWROWHEADERCELL_iconMarginWidth + DATAGRIDVIEWROWHEADERCELL_iconsWidth; } if (allowedWidth > 2 * DATAGRIDVIEWROWHEADERCELL_contentMarginWidth + DATAGRIDVIEWROWHEADERCELL_horizontalTextMarginLeft + DATAGRIDVIEWROWHEADERCELL_horizontalTextMarginRight) { // There is enough room for text allowedWidth -= 2 * DATAGRIDVIEWROWHEADERCELL_contentMarginWidth + DATAGRIDVIEWROWHEADERCELL_horizontalTextMarginLeft + DATAGRIDVIEWROWHEADERCELL_horizontalTextMarginRight; if (cellStyle.WrapMode == DataGridViewTriState.True) { minHeightContent = DataGridViewCell.MeasureTextHeight(graphics, val, cellStyle.Font, allowedWidth, flags); } else { minHeightContent = DataGridViewCell.MeasureTextSize(graphics, val, cellStyle.Font, flags).Height; } minHeightContent += 2 * DATAGRIDVIEWROWHEADERCELL_verticalTextMargin; } } else { if ((showGlyph || showRowErrors) && allowedWidth >= 2 * DATAGRIDVIEWROWHEADERCELL_iconMarginWidth + DATAGRIDVIEWROWHEADERCELL_iconsWidth) { minHeightIcon = DATAGRIDVIEWROWHEADERCELL_iconsHeight + 2 * DATAGRIDVIEWROWHEADERCELL_iconMarginHeight; } } return(new Size(0, Math.Max(minHeightIcon, minHeightContent) + borderAndPaddingHeights)); } default: { if (!string.IsNullOrEmpty(val)) { if (cellStyle.WrapMode == DataGridViewTriState.True) { preferredSize = DataGridViewCell.MeasureTextPreferredSize(graphics, val, cellStyle.Font, 5.0F, flags); } else { preferredSize = DataGridViewCell.MeasureTextSize(graphics, val, cellStyle.Font, flags); } preferredSize.Width += 2 * DATAGRIDVIEWROWHEADERCELL_contentMarginWidth + DATAGRIDVIEWROWHEADERCELL_horizontalTextMarginLeft + DATAGRIDVIEWROWHEADERCELL_horizontalTextMarginRight; preferredSize.Height += 2 * DATAGRIDVIEWROWHEADERCELL_verticalTextMargin; } else { preferredSize = new Size(0, 1); } if (showGlyph) { preferredSize.Width += DATAGRIDVIEWROWHEADERCELL_iconsWidth + 2 * DATAGRIDVIEWROWHEADERCELL_iconMarginWidth; } if (showRowErrors) { preferredSize.Width += DATAGRIDVIEWROWHEADERCELL_iconsWidth + 2 * DATAGRIDVIEWROWHEADERCELL_iconMarginWidth; } if (showGlyph || showRowErrors) { preferredSize.Height = Math.Max(preferredSize.Height, DATAGRIDVIEWROWHEADERCELL_iconsHeight + 2 * DATAGRIDVIEWROWHEADERCELL_iconMarginHeight); } preferredSize.Width += borderAndPaddingWidths; preferredSize.Height += borderAndPaddingHeights; return(preferredSize); } } }
private IRawElementProviderFragmentRoot ColumnCellTest(SWF.DataGridViewColumn column, SWF.DataGridViewCell cell, bool cellChildrenExpected, SWF.DataGridViewCell newCell) { SWF.DataGridView datagridview = GetControlInstance() as SWF.DataGridView; datagridview.Size = new Size(200, 200); datagridview.AllowUserToAddRows = false; datagridview.Columns.Add(column); IRawElementProviderFragmentRoot provider = GetProviderFromControl(datagridview) as IRawElementProviderFragmentRoot; Assert.IsNotNull(provider, "Missing DataGridView provider"); IRawElementProviderFragmentRoot header = null; IRawElementProviderFragment child = provider.Navigate(NavigateDirection.FirstChild); Assert.IsNotNull(child, "FirstChild is null"); int childCount = 0; while (child != null) { childCount++; if ((int)child.GetPropertyValue(AutomationElementIdentifiers.ControlTypeProperty.Id) == ControlType.Header.Id) { header = child as IRawElementProviderFragmentRoot; } child = child.Navigate(NavigateDirection.NextSibling); } Assert.IsNotNull(header, "Header is missing"); Assert.AreEqual(1, childCount, "Children (Header)"); // Exposes BNC #478840 TestChildPatterns(header); SWF.DataGridViewRow row = new SWF.DataGridViewRow(); row.Cells.Add(cell); datagridview.Rows.Add(row); IRawElementProviderFragment dataItem = null; childCount = 0; child = provider.Navigate(NavigateDirection.FirstChild); while (child != null) { childCount++; if ((int)child.GetPropertyValue(AutomationElementIdentifiers.ControlTypeProperty.Id) == ControlType.DataItem.Id) { dataItem = child; } child = child.Navigate(NavigateDirection.NextSibling); } Assert.IsNotNull(dataItem, "DataItem is missing"); Assert.AreEqual(2, childCount, "Children (Header/DataItem)"); IRawElementProviderFragment buttonChild = dataItem.Navigate(NavigateDirection.FirstChild); Assert.IsNotNull(buttonChild, "DataItem.Child missing"); TestPatterns(buttonChild); Assert.AreEqual(dataItem, buttonChild.Navigate(NavigateDirection.Parent), "DataItem != ButtonChild.Parent"); IGridItemProvider gridItemProvider = (IGridItemProvider)buttonChild.GetPatternProvider(GridItemPatternIdentifiers.Pattern.Id); Assert.IsNotNull(gridItemProvider, "Child should support IGridItemProvider"); Assert.IsNotNull(gridItemProvider.ContainingGrid, "ContainingGrid should not be null"); // http://msdn.microsoft.com/en-us/library/system.windows.automation.provider.igriditemprovider.containinggrid.aspx Assert.IsNotNull(gridItemProvider.ContainingGrid.GetPatternProvider(GridPatternIdentifiers.Pattern.Id), "ContainingGrid must implement GridPatternProvider"); childCount = 0; child = buttonChild.Navigate(NavigateDirection.FirstChild); while (child != null) { childCount++; child = child.Navigate(NavigateDirection.NextSibling); } if (!cellChildrenExpected) { Assert.AreEqual(0, childCount, "No children expected."); } else { Assert.Greater(childCount, 0, "Children expected."); } TestChildPatterns(provider); if (newCell != null) { // Lets add a new row, to make sure everything is ok. SWF.DataGridViewRow newRow = new SWF.DataGridViewRow(); newRow.Cells.Add(newCell); datagridview.Rows.Add(newRow); TestChildPatterns(provider); } // Exposes BNC #513476 cell.ReadOnly = false; Assert.IsTrue((bool)dataItem.GetPropertyValue(AutomationElementIdentifiers.IsEnabledProperty.Id)); cell.ReadOnly = true; Assert.IsTrue((bool)dataItem.GetPropertyValue(AutomationElementIdentifiers.IsEnabledProperty.Id)); cell.ReadOnly = false; datagridview.Enabled = false; Assert.IsFalse((bool)dataItem.GetPropertyValue(AutomationElementIdentifiers.IsEnabledProperty.Id)); datagridview.Enabled = true; Assert.IsTrue((bool)dataItem.GetPropertyValue(AutomationElementIdentifiers.IsEnabledProperty.Id)); return(provider); }
public bool Contains(DataGridViewCell dataGridViewCell) { return(base.List.Contains(dataGridViewCell)); }
internal void InternalRemove(DataGridViewCell dataGridViewCell) { base.List.Remove(dataGridViewCell); }
internal void InternalAdd(DataGridViewCell dataGridViewCell) { base.List.Add(dataGridViewCell); }
/// <devdoc> /// Checks to see if a DataGridViewCell is contained in this collection. /// </devdoc> public bool Contains(DataGridViewCell dataGridViewCell) { return(this.items.IndexOf(dataGridViewCell) != -1); }
/// <include file='doc\DataGridViewCellCollection.uex' path='docs/doc[@for="DataGridViewCellCollection.IndexOf"]/*' /> public int IndexOf(DataGridViewCell dataGridViewCell) { return(this.items.IndexOf(dataGridViewCell)); }
/// <devdoc> /// <para>Adds a <see cref='System.Windows.Forms.DataGridViewCell'/> to this collection.</para> /// </devdoc> internal int Add(DataGridViewCell dataGridViewCell) { Debug.Assert(!Contains(dataGridViewCell)); return(this.items.Add(dataGridViewCell)); }
public DataGridViewCellAccessibleObject(DataGridViewCell owner) { _owner = owner; }
/// <include file='doc\DataGridViewImageCell.uex' path='docs/doc[@for="DataGridViewImageCellAccessibleObject.DataGridViewImageCellAccessibleObject"]/*' /> public DataGridViewImageCellAccessibleObject(DataGridViewCell owner) : base(owner) { }
// PaintPrivate is used in three places that need to duplicate the paint code: // 1. DataGridViewCell::Paint method // 2. DataGridViewCell::GetContentBounds // 3. DataGridViewCell::GetErrorIconBounds // // if computeContentBounds is true then PaintPrivate returns the contentBounds // else if computeErrorIconBounds is true then PaintPrivate returns the errorIconBounds // else it returns Rectangle.Empty; private Rectangle PaintPrivate(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts, bool computeContentBounds, bool computeErrorIconBounds, bool paint) { // Parameter checking. // One bit and one bit only should be turned on Debug.Assert(paint || computeContentBounds || computeErrorIconBounds); Debug.Assert(!paint || !computeContentBounds || !computeErrorIconBounds); Debug.Assert(!computeContentBounds || !computeErrorIconBounds || !paint); Debug.Assert(!computeErrorIconBounds || !paint || !computeContentBounds); Debug.Assert(cellStyle != null); // If computeContentBounds == TRUE then resultBounds will be the contentBounds. // If computeErrorIconBounds == TRUE then resultBounds will be the error icon bounds. // Else resultBounds will be Rectangle.Empty; Rectangle resultBounds = Rectangle.Empty; if (paint && DataGridViewCell.PaintBorder(paintParts)) { PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } Rectangle borderWidths = BorderWidths(advancedBorderStyle); Rectangle valBounds = cellBounds; valBounds.Offset(borderWidths.X, borderWidths.Y); valBounds.Width -= borderWidths.Right; valBounds.Height -= borderWidths.Bottom; SolidBrush br; Point ptCurrentCell = this.DataGridView.CurrentCellAddress; bool cellCurrent = ptCurrentCell.X == this.ColumnIndex && ptCurrentCell.Y == rowIndex; bool cellEdited = cellCurrent && this.DataGridView.EditingControl != null; bool cellSelected = (cellState & DataGridViewElementStates.Selected) != 0; if (DataGridViewCell.PaintSelectionBackground(paintParts) && cellSelected && !cellEdited) { br = this.DataGridView.GetCachedBrush(cellStyle.SelectionBackColor); } else { br = this.DataGridView.GetCachedBrush(cellStyle.BackColor); } if (paint && DataGridViewCell.PaintBackground(paintParts) && br.Color.A == 255 && valBounds.Width > 0 && valBounds.Height > 0) { graphics.FillRectangle(br, valBounds); } if (cellStyle.Padding != Padding.Empty) { if (this.DataGridView.RightToLeftInternal) { valBounds.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top); } else { valBounds.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top); } valBounds.Width -= cellStyle.Padding.Horizontal; valBounds.Height -= cellStyle.Padding.Vertical; } if (paint && cellCurrent && !cellEdited) { // Draw focus rectangle if (DataGridViewCell.PaintFocus(paintParts) && this.DataGridView.ShowFocusCues && this.DataGridView.Focused && valBounds.Width > 0 && valBounds.Height > 0) { ControlPaint.DrawFocusRectangle(graphics, valBounds, Color.Empty, br.Color); } } Rectangle errorBounds = valBounds; string formattedString = formattedValue as string; if (formattedString != null && ((paint && !cellEdited) || computeContentBounds)) { // Font independent margins int verticalTextMarginTop = cellStyle.WrapMode == DataGridViewTriState.True ? DATAGRIDVIEWTEXTBOXCELL_verticalTextMarginTopWithWrapping : DATAGRIDVIEWTEXTBOXCELL_verticalTextMarginTopWithoutWrapping; valBounds.Offset(DATAGRIDVIEWTEXTBOXCELL_horizontalTextMarginLeft, verticalTextMarginTop); valBounds.Width -= DATAGRIDVIEWTEXTBOXCELL_horizontalTextMarginLeft + DATAGRIDVIEWTEXTBOXCELL_horizontalTextMarginRight; valBounds.Height -= verticalTextMarginTop + DATAGRIDVIEWTEXTBOXCELL_verticalTextMarginBottom; if (valBounds.Width > 0 && valBounds.Height > 0) { TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(this.DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode); if (paint) { if (DataGridViewCell.PaintContentForeground(paintParts)) { if ((flags & TextFormatFlags.SingleLine) != 0) { flags |= TextFormatFlags.EndEllipsis; } TextRenderer.DrawText(graphics, formattedString, cellStyle.Font, valBounds, cellSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor, flags); } } else { resultBounds = DataGridViewUtilities.GetTextBounds(valBounds, formattedString, flags, cellStyle); } } } else if (computeErrorIconBounds) { if (!String.IsNullOrEmpty(errorText)) { resultBounds = ComputeErrorIconBounds(errorBounds); } } else { Debug.Assert(cellEdited || formattedString == null); Debug.Assert(paint || computeContentBounds); } if (this.DataGridView.ShowCellErrors && paint && DataGridViewCell.PaintErrorIcon(paintParts)) { PaintErrorIcon(graphics, cellStyle, rowIndex, cellBounds, errorBounds, errorText); } return(resultBounds); }
private IRawElementProviderFragmentRoot ColumnCellTest(SWF.DataGridViewColumn column, SWF.DataGridViewCell cell, bool cellChildrenExpected) { return(ColumnCellTest(column, cell, cellChildrenExpected, null)); }
// PaintPrivate is used in three places that need to duplicate the paint code: // 1. DataGridViewCell::Paint method // 2. DataGridViewCell::GetContentBounds // 3. DataGridViewCell::GetErrorIconBounds // // if computeContentBounds is true then PaintPrivate returns the contentBounds // else if computeErrorIconBounds is true then PaintPrivate returns the errorIconBounds // else it returns Rectangle.Empty; private Rectangle PaintPrivate(Graphics g, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts, bool computeContentBounds, bool computeErrorIconBounds, bool paint) { // Parameter checking. // One bit and one bit only should be turned on Debug.Assert(paint || computeContentBounds || computeErrorIconBounds); Debug.Assert(!paint || !computeContentBounds || !computeErrorIconBounds); Debug.Assert(!computeContentBounds || !computeErrorIconBounds || !paint); Debug.Assert(!computeErrorIconBounds || !paint || !computeContentBounds); Debug.Assert(cellStyle != null); if (paint && DataGridViewCell.PaintBorder(paintParts)) { PaintBorder(g, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } Rectangle resultBounds; Rectangle valBounds = cellBounds; Rectangle borderWidths = BorderWidths(advancedBorderStyle); valBounds.Offset(borderWidths.X, borderWidths.Y); valBounds.Width -= borderWidths.Right; valBounds.Height -= borderWidths.Bottom; if (valBounds.Width > 0 && valBounds.Height > 0 && (paint || computeContentBounds)) { Rectangle imgBounds = valBounds; if (cellStyle.Padding != Padding.Empty) { if (this.DataGridView.RightToLeftInternal) { imgBounds.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top); } else { imgBounds.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top); } imgBounds.Width -= cellStyle.Padding.Horizontal; imgBounds.Height -= cellStyle.Padding.Vertical; } bool cellSelected = (elementState & DataGridViewElementStates.Selected) != 0; SolidBrush br = this.DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && cellSelected) ? cellStyle.SelectionBackColor : cellStyle.BackColor); if (imgBounds.Width > 0 && imgBounds.Height > 0) { Image img = formattedValue as Image; Icon ico = null; if (img == null) { ico = formattedValue as Icon; } if (ico != null || img != null) { DataGridViewImageCellLayout imageLayout = this.ImageLayout; if (imageLayout == DataGridViewImageCellLayout.NotSet) { if (this.OwningColumn is DataGridViewImageColumn) { imageLayout = ((DataGridViewImageColumn)this.OwningColumn).ImageLayout; Debug.Assert(imageLayout != DataGridViewImageCellLayout.NotSet); } else { imageLayout = DataGridViewImageCellLayout.Normal; } } if (imageLayout == DataGridViewImageCellLayout.Stretch) { if (paint) { if (DataGridViewCell.PaintBackground(paintParts)) { DataGridViewCell.PaintPadding(g, valBounds, cellStyle, br, this.DataGridView.RightToLeftInternal); } if (DataGridViewCell.PaintContentForeground(paintParts)) { if (img != null) { // ImageAttributes attr = new ImageAttributes(); attr.SetWrapMode(WrapMode.TileFlipXY); g.DrawImage(img, imgBounds, 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, attr); attr.Dispose(); } else { g.DrawIcon(ico, imgBounds); } } } resultBounds = imgBounds; } else { Rectangle imgBounds2 = ImgBounds(imgBounds, (img == null) ? ico.Width : img.Width, (img == null) ? ico.Height : img.Height, imageLayout, cellStyle); resultBounds = imgBounds2; if (paint) { if (DataGridViewCell.PaintBackground(paintParts) && br.Color.A == 255) { g.FillRectangle(br, valBounds); } if (DataGridViewCell.PaintContentForeground(paintParts)) { //paint the image Region reg = g.Clip; g.SetClip(Rectangle.Intersect(Rectangle.Intersect(imgBounds2, imgBounds), Rectangle.Truncate(g.VisibleClipBounds))); if (img != null) { g.DrawImage(img, imgBounds2); } else { g.DrawIconUnstretched(ico, imgBounds2); } g.Clip = reg; } } } } else { if (paint && DataGridViewCell.PaintBackground(paintParts) && br.Color.A == 255) { g.FillRectangle(br, valBounds); } resultBounds = Rectangle.Empty; } } else { if (paint && DataGridViewCell.PaintBackground(paintParts) && br.Color.A == 255) { g.FillRectangle(br, valBounds); } resultBounds = Rectangle.Empty; } Point ptCurrentCell = this.DataGridView.CurrentCellAddress; if (paint && DataGridViewCell.PaintFocus(paintParts) && ptCurrentCell.X == this.ColumnIndex && ptCurrentCell.Y == rowIndex && this.DataGridView.ShowFocusCues && this.DataGridView.Focused) { // Draw focus rectangle ControlPaint.DrawFocusRectangle(g, valBounds, Color.Empty, br.Color); } if (this.DataGridView.ShowCellErrors && paint && DataGridViewCell.PaintErrorIcon(paintParts)) { PaintErrorIcon(g, cellStyle, rowIndex, cellBounds, valBounds, errorText); } } else if (computeErrorIconBounds) { if (!string.IsNullOrEmpty(errorText)) { resultBounds = ComputeErrorIconBounds(valBounds); } else { resultBounds = Rectangle.Empty; } } else { Debug.Assert(valBounds.Height <= 0 || valBounds.Width <= 0); resultBounds = Rectangle.Empty; } return(resultBounds); }
/// <include file='doc\DataGridViewCellCollection.uex' path='docs/doc[@for="DataGridViewCellCollection.Contains"]/*' /> /// <devdoc> /// Checks to see if a DataGridViewCell is contained in this collection. /// </devdoc> public virtual bool Contains(DataGridViewCell dataGridViewCell) { int index = this.items.IndexOf(dataGridViewCell); return(index != -1); }
/// <include file='doc\DataGridViewImageCell.uex' path='docs/doc[@for="DataGridViewImageCell.GetPreferredSize"]/*' /> protected override Size GetPreferredSize(Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize) { if (this.DataGridView == null) { return(new Size(-1, -1)); } if (cellStyle == null) { throw new ArgumentNullException(nameof(cellStyle)); } Size preferredSize; Rectangle borderWidthsRect = this.StdBorderWidths; int borderAndPaddingWidths = borderWidthsRect.Left + borderWidthsRect.Width + cellStyle.Padding.Horizontal; int borderAndPaddingHeights = borderWidthsRect.Top + borderWidthsRect.Height + cellStyle.Padding.Vertical; DataGridViewFreeDimension freeDimension = DataGridViewCell.GetFreeDimensionFromConstraint(constraintSize); object formattedValue = GetFormattedValue(rowIndex, ref cellStyle, DataGridViewDataErrorContexts.Formatting | DataGridViewDataErrorContexts.PreferredSize); Image img = formattedValue as Image; Icon ico = null; if (img == null) { ico = formattedValue as Icon; } if (freeDimension == DataGridViewFreeDimension.Height && this.ImageLayout == DataGridViewImageCellLayout.Zoom) { if (img != null || ico != null) { if (img != null) { int imgWidthAllowed = constraintSize.Width - borderAndPaddingWidths; if (imgWidthAllowed <= 0 || img.Width == 0) { preferredSize = Size.Empty; } else { preferredSize = new Size(0, Math.Min(img.Height, decimal.ToInt32((decimal)img.Height * imgWidthAllowed / img.Width))); } } else { int icoWidthAllowed = constraintSize.Width - borderAndPaddingWidths; if (icoWidthAllowed <= 0 || ico.Width == 0) { preferredSize = Size.Empty; } else { preferredSize = new Size(0, Math.Min(ico.Height, decimal.ToInt32((decimal)ico.Height * icoWidthAllowed / ico.Width))); } } } else { preferredSize = new Size(0, 1); } } else if (freeDimension == DataGridViewFreeDimension.Width && this.ImageLayout == DataGridViewImageCellLayout.Zoom) { if (img != null || ico != null) { if (img != null) { int imgHeightAllowed = constraintSize.Height - borderAndPaddingHeights; if (imgHeightAllowed <= 0 || img.Height == 0) { preferredSize = Size.Empty; } else { preferredSize = new Size(Math.Min(img.Width, decimal.ToInt32((decimal)img.Width * imgHeightAllowed / img.Height)), 0); } } else { int icoHeightAllowed = constraintSize.Height - borderAndPaddingHeights; if (icoHeightAllowed <= 0 || ico.Height == 0) { preferredSize = Size.Empty; } else { preferredSize = new Size(Math.Min(ico.Width, decimal.ToInt32((decimal)ico.Width * icoHeightAllowed / ico.Height)), 0); } } } else { preferredSize = new Size(1, 0); } } else { if (img != null) { preferredSize = new Size(img.Width, img.Height); } else if (ico != null) { preferredSize = new Size(ico.Width, ico.Height); } else { preferredSize = new Size(1, 1); } if (freeDimension == DataGridViewFreeDimension.Height) { preferredSize.Width = 0; } else if (freeDimension == DataGridViewFreeDimension.Width) { preferredSize.Height = 0; } } if (freeDimension != DataGridViewFreeDimension.Height) { preferredSize.Width += borderAndPaddingWidths; if (this.DataGridView.ShowCellErrors) { // Making sure that there is enough room for the potential error icon preferredSize.Width = Math.Max(preferredSize.Width, borderAndPaddingWidths + DATAGRIDVIEWCELL_iconMarginWidth * 2 + iconsWidth); } } if (freeDimension != DataGridViewFreeDimension.Width) { preferredSize.Height += borderAndPaddingHeights; if (this.DataGridView.ShowCellErrors) { // Making sure that there is enough room for the potential error icon preferredSize.Height = Math.Max(preferredSize.Height, borderAndPaddingHeights + DATAGRIDVIEWCELL_iconMarginHeight * 2 + iconsHeight); } } return(preferredSize); }