1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
23 // Pedro MartÃnez Juliá <pedromj@gmail.com>
24 // Ivan N. Zlatev <contact@i-nz.net>
31 using System.ComponentModel;
32 using System.Runtime.InteropServices;
34 namespace System.Windows.Forms {
36 [TypeConverter (typeof (DataGridViewCellConverter))]
37 public abstract class DataGridViewCell : DataGridViewElement, ICloneable, IDisposable
39 private DataGridView dataGridViewOwner;
41 private AccessibleObject accessibilityObject;
42 private int columnIndex;
43 private ContextMenuStrip contextMenuStrip;
44 private bool displayed;
45 private string errorText;
46 private bool isInEditMode;
47 private DataGridViewRow owningRow;
48 private DataGridViewTriState readOnly;
49 private bool selected;
50 private DataGridViewCellStyle style;
52 private string toolTipText;
53 private object valuex;
54 private Type valueType;
56 protected DataGridViewCell ()
59 dataGridViewOwner = null;
60 errorText = string.Empty;
69 public AccessibleObject AccessibilityObject {
71 if (accessibilityObject == null) {
72 accessibilityObject = CreateAccessibilityInstance();
74 return accessibilityObject;
78 public int ColumnIndex {
80 if (DataGridView == null)
87 public Rectangle ContentBounds {
89 return GetContentBounds (RowIndex);
94 public virtual ContextMenuStrip ContextMenuStrip {
95 get { return contextMenuStrip; }
96 set { contextMenuStrip = value; }
100 public virtual object DefaultNewRowValue {
105 public virtual bool Displayed {
106 get { return displayed; }
110 [EditorBrowsable (EditorBrowsableState.Advanced)]
111 public object EditedFormattedValue {
113 return GetEditedFormattedValue (RowIndex, DataGridViewDataErrorContexts.Formatting);
118 [EditorBrowsable (EditorBrowsableState.Advanced)]
119 public virtual Type EditType {
121 return typeof (DataGridViewTextBoxEditingControl);
126 [EditorBrowsable (EditorBrowsableState.Advanced)]
127 public Rectangle ErrorIconBounds {
129 if (this is DataGridViewTopLeftHeaderCell)
130 return GetErrorIconBounds (null, null, RowIndex);
132 if (DataGridView == null || columnIndex < 0)
133 throw new InvalidOperationException ();
134 if (RowIndex < 0 || RowIndex >= DataGridView.Rows.Count)
135 throw new ArgumentOutOfRangeException ("rowIndex", "Specified argument was out of the range of valid values.");
137 return GetErrorIconBounds (null, null, RowIndex);
142 public string ErrorText {
144 if (this is DataGridViewTopLeftHeaderCell)
145 return GetErrorText (-1);
147 if (OwningRow == null)
150 return GetErrorText (OwningRow.Index);
153 if (errorText != value) {
155 OnErrorTextChanged(new DataGridViewCellEventArgs(ColumnIndex, RowIndex));
161 public object FormattedValue {
163 if (DataGridView == null)
166 DataGridViewCellStyle style = InheritedStyle;
167 return GetFormattedValue (Value, RowIndex, ref style, null, null, DataGridViewDataErrorContexts.Formatting);
172 public virtual Type FormattedValueType {
177 public virtual bool Frozen {
179 if (DataGridView == null)
183 return OwningRow.Frozen && OwningColumn.Frozen;
190 public bool HasStyle {
191 get { return style != null; }
195 public DataGridViewElementStates InheritedState {
197 return GetInheritedState (RowIndex);
202 public DataGridViewCellStyle InheritedStyle {
204 return GetInheritedStyle (null, RowIndex, true);
209 public bool IsInEditMode {
211 if (DataGridView == null)
215 throw new InvalidOperationException ("Operation cannot be performed on a cell of a shared row.");
222 [EditorBrowsable (EditorBrowsableState.Advanced)]
223 public DataGridViewColumn OwningColumn {
225 if (DataGridView == null || columnIndex < 0 || columnIndex >= DataGridView.Columns.Count)
228 return DataGridView.Columns[columnIndex];
233 [EditorBrowsable (EditorBrowsableState.Advanced)]
234 public DataGridViewRow OwningRow {
235 get { return owningRow; }
239 public Size PreferredSize {
241 if (DataGridView == null)
242 return new Size (-1, -1);
244 return GetPreferredSize (Hwnd.GraphicsContext, InheritedStyle, RowIndex, Size.Empty);
249 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
250 public virtual bool ReadOnly {
252 if (DataGridView != null && DataGridView.ReadOnly)
255 if (readOnly != DataGridViewTriState.NotSet)
256 return readOnly == DataGridViewTriState.True;
258 if (OwningRow != null && !OwningRow.IsShared && OwningRow.ReadOnly)
261 if (OwningColumn != null && OwningColumn.ReadOnly)
267 readOnly = value ? DataGridViewTriState.True : DataGridViewTriState.False;
269 SetState (DataGridViewElementStates.ReadOnly | State);
271 SetState (~DataGridViewElementStates.ReadOnly & State);
277 public virtual bool Resizable {
279 if (DataGridView == null)
282 // Shared cells aren't resizable
283 if (RowIndex == -1 || columnIndex == -1)
286 return OwningRow.Resizable == DataGridViewTriState.True || OwningColumn.Resizable == DataGridViewTriState.True;
291 public int RowIndex {
293 if (owningRow == null) {
296 return owningRow.Index;
301 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
302 public virtual bool Selected {
307 if (DataGridView != null) {
308 if (RowIndex >= 0 && RowIndex < DataGridView.Rows.Count && DataGridView.Rows [RowIndex].Selected)
311 if (ColumnIndex >= 0 && ColumnIndex < DataGridView.Columns.Count && DataGridView.Columns [ColumnIndex].Selected)
318 bool changed = selected != value;
321 if (value != ((State & DataGridViewElementStates.Selected) != 0))
322 SetState(State ^ DataGridViewElementStates.Selected);
324 // If our row is selected, unselect it and select
325 // the first cell in it that isn't us
326 if (!selected && OwningRow != null && OwningRow.Selected) {
327 OwningRow.Selected = false;
329 if (columnIndex != 0 && OwningRow.Cells.Count > 0)
330 OwningRow.Cells[0].Selected = true;
331 else if (OwningRow.Cells.Count > 1)
332 OwningRow.Cells[1].Selected = true;
335 if (changed && DataGridView != null && DataGridView.IsHandleCreated)
336 DataGridView.Invalidate ();
343 if (DataGridView == null)
344 return new Size (-1, -1);
346 return GetSize (RowIndex);
351 public DataGridViewCellStyle Style {
354 style = new DataGridViewCellStyle();
355 style.StyleChanged += OnStyleChanged;
359 set { style = value; }
362 [Bindable (true, BindingDirection.OneWay)]
363 [DefaultValue (null)]
364 [Localizable (false)]
365 [TypeConverter ("System.ComponentModel.StringConverter, " + Consts.AssemblySystem)]
372 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
373 public string ToolTipText {
374 get { return toolTipText == null ? string.Empty : toolTipText; }
375 set { toolTipText = value; }
379 public object Value {
381 return GetValue (RowIndex);
384 SetValue (RowIndex, value);
389 public virtual Type ValueType {
391 if (valueType == null) {
392 if (DataProperty != null)
393 valueType = DataProperty.PropertyType;
394 else if (OwningColumn != null)
395 valueType = OwningColumn.ValueType;
400 set { valueType = value; }
404 public virtual bool Visible {
406 // This is independent from State...
407 DataGridViewColumn col = OwningColumn;
408 DataGridViewRow row = OwningRow;
410 bool rowVisible = true, colVisible = true;
412 if (row == null && col == null)
416 rowVisible = !row.IsShared && row.Visible;
420 colVisible = col.Index >= 0 && col.Visible;
423 return rowVisible && colVisible;
427 internal override void SetState (DataGridViewElementStates state) {
428 base.SetState (state);
429 if (DataGridView != null)
430 DataGridView.OnCellStateChangedInternal (new DataGridViewCellStateChangedEventArgs (this, state));
433 [EditorBrowsable (EditorBrowsableState.Advanced)]
434 public virtual DataGridViewAdvancedBorderStyle AdjustCellBorderStyle (DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStyleInput, DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceholder, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow) {
435 return dataGridViewAdvancedBorderStyleInput;
438 public virtual object Clone ()
440 DataGridViewCell result = (DataGridViewCell) Activator.CreateInstance (GetType ());
441 result.accessibilityObject = this.accessibilityObject;
442 result.columnIndex = this.columnIndex;
443 result.displayed = this.displayed;
444 result.errorText = this.errorText;
445 result.isInEditMode = this.isInEditMode;
446 result.owningRow = this.owningRow;
447 result.readOnly = this.readOnly;
448 result.selected = this.selected;
449 result.style = this.style;
450 result.tag = this.tag;
451 result.toolTipText = this.toolTipText;
452 result.valuex = this.valuex;
453 result.valueType = this.valueType;
457 [EditorBrowsable (EditorBrowsableState.Advanced)]
458 public virtual void DetachEditingControl ()
462 public void Dispose ()
466 public Rectangle GetContentBounds (int rowIndex)
468 if (DataGridView == null)
469 return Rectangle.Empty;
471 return GetContentBounds (Hwnd.GraphicsContext, InheritedStyle, rowIndex);
474 public object GetEditedFormattedValue (int rowIndex, DataGridViewDataErrorContexts context)
476 if (DataGridView == null)
479 if (rowIndex < 0 || rowIndex >= DataGridView.RowCount)
480 throw new ArgumentOutOfRangeException ("rowIndex", "Specified argument was out of the range of valid values.");
482 // If we are in edit mode, this returns the value of the editing control
483 // If we aren't in edit mode, return the cell's value
484 // Basically, return what the user is currently seeing
486 if (DataGridView.EditingControl != null)
487 return (DataGridView.EditingControl as IDataGridViewEditingControl).GetEditingControlFormattedValue (context);
489 return (this as IDataGridViewEditingCell).GetEditingCellFormattedValue (context);
492 DataGridViewCellStyle style = InheritedStyle;
494 return GetFormattedValue (GetValue (rowIndex), rowIndex, ref style, null, null, context);
497 public virtual ContextMenuStrip GetInheritedContextMenuStrip (int rowIndex)
499 if (DataGridView == null)
502 if (rowIndex < 0 || rowIndex >= DataGridView.Rows.Count)
503 throw new ArgumentOutOfRangeException ("rowIndex");
505 throw new InvalidOperationException ("cannot perform this on a column header cell");
507 if (contextMenuStrip != null)
508 return contextMenuStrip;
509 if (OwningRow.ContextMenuStrip != null)
510 return OwningRow.ContextMenuStrip;
511 if (OwningColumn.ContextMenuStrip != null)
512 return OwningColumn.ContextMenuStrip;
514 return DataGridView.ContextMenuStrip;
517 public virtual DataGridViewElementStates GetInheritedState (int rowIndex)
520 if (DataGridView == null && rowIndex != -1)
521 throw new ArgumentException ("msg?");
523 if (DataGridView != null && (rowIndex < 0 || rowIndex >= DataGridView.Rows.Count))
524 throw new ArgumentOutOfRangeException ("rowIndex", "Specified argument was out of the range of valid values.");
526 DataGridViewElementStates result;
528 result = DataGridViewElementStates.ResizableSet | State;
530 DataGridViewColumn col = OwningColumn;
531 DataGridViewRow row = OwningRow;
533 if (DataGridView == null) {
535 if (row.Resizable == DataGridViewTriState.True)
536 result |= DataGridViewElementStates.Resizable;
539 result |= DataGridViewElementStates.Visible;
542 result |= DataGridViewElementStates.ReadOnly;
545 result |= DataGridViewElementStates.Frozen;
548 result |= DataGridViewElementStates.Displayed;
551 result |= DataGridViewElementStates.Selected;
558 if (col.Resizable == DataGridViewTriState.True && row.Resizable == DataGridViewTriState.True)
559 result |= DataGridViewElementStates.Resizable;
561 if (col.Visible && row.Visible)
562 result |= DataGridViewElementStates.Visible;
564 if (col.ReadOnly || row.ReadOnly)
565 result |= DataGridViewElementStates.ReadOnly;
567 if (col.Frozen || row.Frozen)
568 result |= DataGridViewElementStates.Frozen;
570 if (col.Displayed && row.Displayed)
571 result |= DataGridViewElementStates.Displayed;
573 if (col.Selected || row.Selected)
574 result |= DataGridViewElementStates.Selected;
580 public virtual DataGridViewCellStyle GetInheritedStyle (DataGridViewCellStyle inheritedCellStyle, int rowIndex, bool includeColors) {
582 * System.InvalidOperationException :: The cell has no associated System.Windows.Forms.DataGridView, or the cell's System.Windows.Forms.DataGridViewCell.ColumnIndex is less than 0.
583 * System.ArgumentOutOfRangeException :: rowIndex is less than 0, or greater than or equal to the number of rows in the parent System.Windows.Forms.DataGridView.
586 if (DataGridView == null)
587 throw new InvalidOperationException ("Cell is not in a DataGridView. The cell cannot retrieve the inherited cell style.");
589 if (rowIndex < 0 || rowIndex >= DataGridView.Rows.Count)
590 throw new ArgumentOutOfRangeException ("rowIndex");
592 // Start with DataGridView.DefaultCellStyle
593 DataGridViewCellStyle result = new DataGridViewCellStyle (DataGridView.DefaultCellStyle);
595 // If we have a column, add OwningColumn.DefaultCellStyle
596 if (OwningColumn != null)
597 result.ApplyStyle (OwningColumn.DefaultCellStyle);
599 // Add DataGridView.RowsDefaultCellStyle
600 result.ApplyStyle (DataGridView.RowsDefaultCellStyle);
602 // If we are an odd row, add DataGridView.AlternatingRowsDefaultCellStyle
603 if (rowIndex % 2 == 1)
604 result.ApplyStyle (DataGridView.AlternatingRowsDefaultCellStyle);
606 // Add Row.DefaultCellStyle
607 result.ApplyStyle (DataGridView.Rows.SharedRow (rowIndex).DefaultCellStyle);
611 result.ApplyStyle (Style);
616 [EditorBrowsable (EditorBrowsableState.Advanced)]
617 public virtual void InitializeEditingControl (int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle) {
618 if (DataGridView == null || DataGridView.EditingControl == null) {
619 throw new InvalidOperationException("No editing control defined");
623 public virtual bool KeyEntersEditMode (KeyEventArgs e)
628 [EditorBrowsable (EditorBrowsableState.Advanced)]
629 public static int MeasureTextHeight (Graphics graphics, string text, Font font, int maxWidth, TextFormatFlags flags)
631 if (graphics == null)
632 throw new ArgumentNullException ("Graphics argument null");
634 throw new ArgumentNullException ("Font argument null");
636 throw new ArgumentOutOfRangeException ("maxWidth is less than 1.");
638 return TextRenderer.MeasureText (graphics, text, font, new Size (maxWidth, 0), flags).Height;
641 [MonoTODO ("does not use widthTruncated parameter")]
642 [EditorBrowsable (EditorBrowsableState.Advanced)]
643 public static int MeasureTextHeight (Graphics graphics, string text, Font font, int maxWidth, TextFormatFlags flags, out bool widthTruncated)
645 widthTruncated = false;
646 return TextRenderer.MeasureText (graphics, text, font, new Size (maxWidth, 0), flags).Height;
649 [EditorBrowsable (EditorBrowsableState.Advanced)]
650 public static Size MeasureTextPreferredSize (Graphics graphics, string text, Font font, float maxRatio, TextFormatFlags flags)
652 if (graphics == null)
653 throw new ArgumentNullException ("Graphics argument null");
655 throw new ArgumentNullException ("Font argument null");
657 throw new ArgumentOutOfRangeException ("maxRatio is less than or equals to 0.");
659 // I couldn't find a case where maxRatio
660 // affected anything on MS
661 return MeasureTextSize (graphics, text, font, flags);
664 [EditorBrowsable (EditorBrowsableState.Advanced)]
665 public static Size MeasureTextSize (Graphics graphics, string text, Font font, TextFormatFlags flags)
667 return TextRenderer.MeasureText (graphics, text, font, Size.Empty, flags);
670 [EditorBrowsable (EditorBrowsableState.Advanced)]
671 public static int MeasureTextWidth (Graphics graphics, string text, Font font, int maxHeight, TextFormatFlags flags)
673 if (graphics == null)
674 throw new ArgumentNullException ("Graphics argument null");
676 throw new ArgumentNullException ("Font argument null");
678 throw new ArgumentOutOfRangeException ("maxHeight is less than 1.");
680 return TextRenderer.MeasureText (graphics, text, font, new Size (0, maxHeight), flags).Width;
683 public virtual object ParseFormattedValue (object formattedValue, DataGridViewCellStyle cellStyle, TypeConverter formattedValueTypeConverter, TypeConverter valueTypeConverter)
685 if (cellStyle == null)
686 throw new ArgumentNullException ("cellStyle is null.");
687 if (FormattedValueType == null)
688 throw new FormatException ("The System.Windows.Forms.DataGridViewCell.FormattedValueType property value is null.");
689 if (formattedValue == null)
690 throw new ArgumentException ("formattedValue is null.");
691 if (ValueType == null)
692 throw new FormatException ("valuetype is null");
693 if (!FormattedValueType.IsAssignableFrom (formattedValue.GetType ()))
694 throw new ArgumentException ("formattedValue is not of formattedValueType.");
696 if (formattedValueTypeConverter == null)
697 formattedValueTypeConverter = FormattedValueTypeConverter;
698 if (valueTypeConverter == null)
699 valueTypeConverter = ValueTypeConverter;
701 if (valueTypeConverter != null && valueTypeConverter.CanConvertFrom (FormattedValueType))
702 return valueTypeConverter.ConvertFrom (formattedValue);
703 if (formattedValueTypeConverter != null && formattedValueTypeConverter.CanConvertTo (ValueType))
704 return formattedValueTypeConverter.ConvertTo (formattedValue, ValueType);
705 return Convert.ChangeType (formattedValue, ValueType);
708 [EditorBrowsable (EditorBrowsableState.Advanced)]
709 public virtual void PositionEditingControl (bool setLocation, bool setSize, Rectangle cellBounds, Rectangle cellClip, DataGridViewCellStyle cellStyle, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow)
711 if (DataGridView.EditingControl != null) {
712 if (setLocation && setSize)
713 DataGridView.EditingControl.Bounds = cellBounds;
714 else if (setLocation)
715 DataGridView.EditingControl.Location = cellBounds.Location;
717 DataGridView.EditingControl.Size = cellBounds.Size;
721 [EditorBrowsable (EditorBrowsableState.Advanced)]
722 public virtual Rectangle PositionEditingPanel (Rectangle cellBounds, Rectangle cellClip, DataGridViewCellStyle cellStyle, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow) {
723 throw new NotImplementedException();
726 public override string ToString () {
727 return String.Format("{0} {{ ColumnIndex={1}, RowIndex={2} }}", this.GetType().Name, ColumnIndex, RowIndex);
730 protected virtual Rectangle BorderWidths (DataGridViewAdvancedBorderStyle advancedBorderStyle)
732 Rectangle r = Rectangle.Empty;
734 r.X = BorderToWidth (advancedBorderStyle.Left);
735 r.Y = BorderToWidth (advancedBorderStyle.Top);
736 r.Width = BorderToWidth (advancedBorderStyle.Right);
737 r.Height = BorderToWidth (advancedBorderStyle.Bottom);
739 if (OwningColumn != null)
740 r.Width += OwningColumn.DividerWidth;
741 if (OwningRow != null)
742 r.Height += OwningRow.DividerHeight;
747 private int BorderToWidth (DataGridViewAdvancedCellBorderStyle style)
750 case DataGridViewAdvancedCellBorderStyle.None:
752 case DataGridViewAdvancedCellBorderStyle.NotSet:
753 case DataGridViewAdvancedCellBorderStyle.Single:
754 case DataGridViewAdvancedCellBorderStyle.Inset:
755 case DataGridViewAdvancedCellBorderStyle.Outset:
756 case DataGridViewAdvancedCellBorderStyle.OutsetPartial:
759 case DataGridViewAdvancedCellBorderStyle.InsetDouble:
760 case DataGridViewAdvancedCellBorderStyle.OutsetDouble:
765 protected virtual bool ClickUnsharesRow (DataGridViewCellEventArgs e)
770 protected virtual bool ContentClickUnsharesRow (DataGridViewCellEventArgs e)
775 protected virtual bool ContentDoubleClickUnsharesRow (DataGridViewCellEventArgs e)
780 protected virtual AccessibleObject CreateAccessibilityInstance () {
781 return new DataGridViewCellAccessibleObject(this);
784 protected virtual void Dispose (bool disposing) {
787 protected virtual bool DoubleClickUnsharesRow (DataGridViewCellEventArgs e)
792 protected virtual bool EnterUnsharesRow (int rowIndex, bool throughMouseClick)
797 protected virtual object GetClipboardContent (int rowIndex, bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string format) {
798 if (DataGridView == null)
801 if (rowIndex < 0 || rowIndex >= DataGridView.RowCount)
802 throw new ArgumentOutOfRangeException ("rowIndex", "Specified argument was out of the range of valid values.");
807 // DataGridViewCellStyle style = GetInheritedStyle (null, rowIndex, false);
808 value = GetEditedFormattedValue (rowIndex, DataGridViewDataErrorContexts.ClipboardContent | DataGridViewDataErrorContexts.Formatting) as string;
812 value = string.Empty;
814 string table_prefix = string.Empty, cell_prefix = string.Empty, row_prefix = string.Empty;
815 string table_suffix = string.Empty, cell_suffix = string.Empty, row_suffix = string.Empty;
817 if (format == DataFormats.UnicodeText || format == DataFormats.Text) {
818 if (lastCell && !inLastRow)
819 cell_suffix = Environment.NewLine;
822 } else if (format == DataFormats.CommaSeparatedValue) {
823 if (lastCell && !inLastRow)
824 cell_suffix = Environment.NewLine;
827 } else if (format == DataFormats.Html) {
828 if (inFirstRow && firstCell)
829 table_prefix = "<TABLE>";
830 if (inLastRow && lastCell)
831 table_suffix = "</TABLE>";
835 row_suffix = "</TR>";
836 cell_prefix = "<TD>";
837 cell_suffix = "</TD>";
846 value = table_prefix + row_prefix + cell_prefix + value + cell_suffix + row_suffix + table_suffix;
851 internal object GetClipboardContentInternal (int rowIndex, bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string format) {
852 return GetClipboardContent (rowIndex, firstCell, lastCell, inFirstRow, inLastRow, format);
855 protected virtual Rectangle GetContentBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex) {
856 return Rectangle.Empty;
859 protected virtual Rectangle GetErrorIconBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex)
861 return Rectangle.Empty;
864 protected internal virtual string GetErrorText (int rowIndex)
869 protected virtual object GetFormattedValue (object value, int rowIndex, ref DataGridViewCellStyle cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context)
871 if (DataGridView == null)
874 if (rowIndex < 0 || rowIndex >= DataGridView.RowCount)
875 throw new ArgumentOutOfRangeException ("rowIndex");
877 // Give the user a chance to custom format
878 if (!(this is DataGridViewRowHeaderCell)) {
879 DataGridViewCellFormattingEventArgs e = new DataGridViewCellFormattingEventArgs (ColumnIndex, rowIndex, value, FormattedValueType, cellStyle);
880 DataGridView.OnCellFormattingInternal (e);
882 if (e.FormattingApplied)
885 cellStyle = e.CellStyle;
889 if (value == null || (cellStyle != null && value == cellStyle.DataSourceNullValue)) {
890 if (FormattedValueType == typeof (string))
894 if (FormattedValueType == typeof(string) && value is IFormattable && !String.IsNullOrEmpty (cellStyle.Format))
895 return ((IFormattable) value).ToString (cellStyle.Format, cellStyle.FormatProvider);
896 if (value != null && FormattedValueType.IsAssignableFrom (value.GetType()))
899 if (formattedValueTypeConverter == null)
900 formattedValueTypeConverter = FormattedValueTypeConverter;
901 if (valueTypeConverter == null)
902 valueTypeConverter = ValueTypeConverter;
904 if (valueTypeConverter != null && valueTypeConverter.CanConvertTo (FormattedValueType))
905 return valueTypeConverter.ConvertTo (value, FormattedValueType);
906 if (formattedValueTypeConverter != null && formattedValueTypeConverter.CanConvertFrom (ValueType))
907 return formattedValueTypeConverter.ConvertFrom (value);
909 return Convert.ChangeType (value, FormattedValueType);
912 protected virtual Size GetPreferredSize (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize)
914 return new Size (-1, -1);
917 protected virtual Size GetSize (int rowIndex)
920 throw new InvalidOperationException ("Getting the Size property of a cell in a shared row is not a valid operation.");
922 return new Size (OwningColumn.Width, OwningRow.Height);
925 protected virtual object GetValue (int rowIndex) {
926 if (DataGridView != null && (RowIndex < 0 || RowIndex >= DataGridView.Rows.Count))
927 throw new ArgumentOutOfRangeException ("rowIndex", "Specified argument was out of the range of valid values.");
929 if (OwningRow != null && DataGridView != null && OwningRow.Index == DataGridView.NewRowIndex)
930 return DefaultNewRowValue;
932 if (DataProperty != null && OwningRow.DataBoundItem != null)
933 return DataProperty.GetValue (OwningRow.DataBoundItem);
938 DataGridViewCellValueEventArgs dgvcvea = new DataGridViewCellValueEventArgs (columnIndex, rowIndex);
939 if (DataGridView != null)
940 DataGridView.OnCellValueNeeded (dgvcvea);
941 return dgvcvea.Value;
944 private PropertyDescriptor DataProperty {
946 if (OwningColumn != null && OwningColumn.DataColumnIndex != -1 &&
947 DataGridView != null && DataGridView.DataManager != null)
948 return DataGridView.DataManager.GetItemProperties()[OwningColumn.DataColumnIndex];
953 private TypeConverter FormattedValueTypeConverter {
955 if (FormattedValueType != null)
956 return TypeDescriptor.GetConverter (FormattedValueType);
961 private TypeConverter ValueTypeConverter {
963 if (DataProperty != null && DataProperty.Converter != null)
964 return DataProperty.Converter;
966 return TypeDescriptor.GetConverter (Value);
967 if (ValueType != null)
968 return TypeDescriptor.GetConverter (ValueType);
973 protected virtual bool KeyDownUnsharesRow (KeyEventArgs e, int rowIndex)
978 protected virtual bool KeyPressUnsharesRow (KeyPressEventArgs e, int rowIndex)
983 protected virtual bool KeyUpUnsharesRow (KeyEventArgs e, int rowIndex)
988 protected virtual bool LeaveUnsharesRow (int rowIndex, bool throughMouseClick)
993 protected virtual bool MouseClickUnsharesRow (DataGridViewCellMouseEventArgs e)
998 protected virtual bool MouseDoubleClickUnsharesRow (DataGridViewCellMouseEventArgs e)
1003 protected virtual bool MouseDownUnsharesRow (DataGridViewCellMouseEventArgs e)
1008 protected virtual bool MouseEnterUnsharesRow (int rowIndex)
1013 protected virtual bool MouseLeaveUnsharesRow (int rowIndex)
1018 protected virtual bool MouseMoveUnsharesRow (DataGridViewCellMouseEventArgs e)
1023 protected virtual bool MouseUpUnsharesRow (DataGridViewCellMouseEventArgs e)
1028 protected virtual void OnClick (DataGridViewCellEventArgs e) {
1031 internal void OnClickInternal (DataGridViewCellEventArgs e) {
1035 protected virtual void OnContentClick (DataGridViewCellEventArgs e) {
1038 internal void OnContentClickInternal (DataGridViewCellEventArgs e) {
1042 protected virtual void OnContentDoubleClick (DataGridViewCellEventArgs e) {
1045 internal void OnContentDoubleClickInternal (DataGridViewCellEventArgs e) {
1046 OnContentDoubleClick (e);
1049 protected override void OnDataGridViewChanged () {
1052 internal void OnDataGridViewChangedInternal () {
1053 OnDataGridViewChanged ();
1056 protected virtual void OnDoubleClick (DataGridViewCellEventArgs e) {
1059 internal void OnDoubleClickInternal (DataGridViewCellEventArgs e) {
1063 protected virtual void OnEnter (int rowIndex, bool throughMouseClick) {
1066 internal void OnEnterInternal (int rowIndex, bool throughMouseClick) {
1067 OnEnter (rowIndex, throughMouseClick);
1070 protected virtual void OnKeyDown (KeyEventArgs e, int rowIndex) {
1073 internal void OnKeyDownInternal (KeyEventArgs e, int rowIndex) {
1074 OnKeyDown (e, rowIndex);
1077 protected virtual void OnKeyPress (KeyPressEventArgs e, int rowIndex) {
1080 internal void OnKeyPressInternal (KeyPressEventArgs e, int rowIndex) {
1081 OnKeyPress (e, rowIndex);
1084 protected virtual void OnKeyUp (KeyEventArgs e, int rowIndex) {
1087 internal void OnKeyUpInternal (KeyEventArgs e, int rowIndex) {
1088 OnKeyUp (e, rowIndex);
1091 protected virtual void OnLeave (int rowIndex, bool throughMouseClick) {
1094 internal void OnLeaveInternal (int rowIndex, bool throughMouseClick) {
1095 OnLeave (rowIndex, throughMouseClick);
1098 protected virtual void OnMouseClick (DataGridViewCellMouseEventArgs e) {
1101 internal void OnMouseClickInternal (DataGridViewCellMouseEventArgs e) {
1105 protected virtual void OnMouseDoubleClick (DataGridViewCellMouseEventArgs e) {
1108 internal void OnMouseDoubleClickInternal (DataGridViewCellMouseEventArgs e) {
1109 OnMouseDoubleClick (e);
1112 protected virtual void OnMouseDown (DataGridViewCellMouseEventArgs e) {
1115 internal void OnMouseDownInternal (DataGridViewCellMouseEventArgs e) {
1119 protected virtual void OnMouseEnter (int rowIndex) {
1122 internal void OnMouseEnterInternal (int rowIndex) {
1123 OnMouseEnter (rowIndex) ;
1126 protected virtual void OnMouseLeave (int rowIndex) {
1129 internal void OnMouseLeaveInternal (int e) {
1133 protected virtual void OnMouseMove (DataGridViewCellMouseEventArgs e) {
1136 internal void OnMouseMoveInternal (DataGridViewCellMouseEventArgs e) {
1140 protected virtual void OnMouseUp (DataGridViewCellMouseEventArgs e) {
1143 internal void OnMouseUpInternal (DataGridViewCellMouseEventArgs e) {
1147 internal void PaintInternal (Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
1149 Paint (graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
1152 protected virtual void Paint (Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
1154 if ((paintParts & DataGridViewPaintParts.Background) == DataGridViewPaintParts.Background)
1155 PaintPartBackground (graphics, cellBounds, cellStyle);
1156 if ((paintParts & DataGridViewPaintParts.SelectionBackground) == DataGridViewPaintParts.SelectionBackground)
1157 PaintPartSelectionBackground (graphics, cellBounds, cellState, cellStyle);
1158 if ((paintParts & DataGridViewPaintParts.ContentForeground) == DataGridViewPaintParts.ContentForeground)
1159 PaintPartContent (graphics, cellBounds, rowIndex, cellState, cellStyle, formattedValue);
1160 if ((paintParts & DataGridViewPaintParts.Border) == DataGridViewPaintParts.Border)
1161 PaintBorder (graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
1162 if ((paintParts & DataGridViewPaintParts.Focus) == DataGridViewPaintParts.Focus)
1163 PaintPartFocus (graphics, cellBounds);
1164 if ((paintParts & DataGridViewPaintParts.ErrorIcon) == DataGridViewPaintParts.ErrorIcon)
1165 if (!string.IsNullOrEmpty (ErrorText))
1166 PaintErrorIcon (graphics, clipBounds, cellBounds, ErrorText);
1169 protected virtual void PaintBorder (Graphics graphics, Rectangle clipBounds, Rectangle bounds, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle)
1171 Pen pen = new Pen (DataGridView.GridColor);
1173 // Paint the left border, if any
1174 switch (advancedBorderStyle.Left) {
1175 case DataGridViewAdvancedCellBorderStyle.Single:
1176 if (DataGridView.CellBorderStyle != DataGridViewCellBorderStyle.Single)
1177 graphics.DrawLine (pen, bounds.X, bounds.Y, bounds.X, bounds.Y + bounds.Height - 1);
1179 case DataGridViewAdvancedCellBorderStyle.Outset:
1180 case DataGridViewAdvancedCellBorderStyle.Inset:
1181 graphics.DrawLine(pen, bounds.X, bounds.Y, bounds.X, bounds.Y + bounds.Height - 1);
1183 case DataGridViewAdvancedCellBorderStyle.InsetDouble:
1184 case DataGridViewAdvancedCellBorderStyle.OutsetDouble:
1185 graphics.DrawLine(pen, bounds.X, bounds.Y, bounds.X, bounds.Y + bounds.Height - 1);
1186 graphics.DrawLine(pen, bounds.X + 2, bounds.Y, bounds.X + 2, bounds.Y + bounds.Height - 1);
1190 // Paint the right border, if any
1191 switch (advancedBorderStyle.Right) {
1192 case DataGridViewAdvancedCellBorderStyle.Single:
1193 graphics.DrawLine(pen, bounds.X + bounds.Width - 1, bounds.Y, bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
1195 case DataGridViewAdvancedCellBorderStyle.Outset:
1196 case DataGridViewAdvancedCellBorderStyle.Inset:
1197 case DataGridViewAdvancedCellBorderStyle.InsetDouble:
1198 case DataGridViewAdvancedCellBorderStyle.OutsetDouble:
1199 graphics.DrawLine(pen, bounds.X + bounds.Width, bounds.Y, bounds.X + bounds.Width, bounds.Y + bounds.Height - 1);
1203 // Paint the top border, if any
1204 switch (advancedBorderStyle.Top) {
1205 case DataGridViewAdvancedCellBorderStyle.Single:
1206 if (DataGridView.CellBorderStyle != DataGridViewCellBorderStyle.Single)
1207 graphics.DrawLine(pen, bounds.X, bounds.Y, bounds.X + bounds.Width - 1, bounds.Y);
1209 case DataGridViewAdvancedCellBorderStyle.Outset:
1210 case DataGridViewAdvancedCellBorderStyle.Inset:
1211 case DataGridViewAdvancedCellBorderStyle.InsetDouble:
1212 case DataGridViewAdvancedCellBorderStyle.OutsetDouble:
1213 graphics.DrawLine(pen, bounds.X, bounds.Y, bounds.X + bounds.Width - 1, bounds.Y);
1217 // Paint the bottom border, if any
1218 switch (advancedBorderStyle.Bottom) {
1219 case DataGridViewAdvancedCellBorderStyle.Outset:
1220 case DataGridViewAdvancedCellBorderStyle.Inset:
1221 case DataGridViewAdvancedCellBorderStyle.Single:
1222 case DataGridViewAdvancedCellBorderStyle.InsetDouble:
1223 case DataGridViewAdvancedCellBorderStyle.OutsetDouble:
1224 graphics.DrawLine(pen, bounds.X, bounds.Y + bounds.Height - 1, bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
1229 protected virtual void PaintErrorIcon (Graphics graphics, Rectangle clipBounds, Rectangle cellValueBounds, string errorText)
1231 Rectangle error_bounds = GetErrorIconBounds (graphics, null, RowIndex);
1233 if (error_bounds.IsEmpty)
1236 Point loc = error_bounds.Location;
1237 loc.X += cellValueBounds.Left;
1238 loc.Y += cellValueBounds.Top;
1240 graphics.FillRectangle (Brushes.Red, new Rectangle (loc.X + 1, loc.Y + 2, 10, 7));
1241 graphics.FillRectangle (Brushes.Red, new Rectangle (loc.X + 2, loc.Y + 1, 8, 9));
1242 graphics.FillRectangle (Brushes.Red, new Rectangle (loc.X + 4, loc.Y, 4, 11));
1243 graphics.FillRectangle (Brushes.Red, new Rectangle (loc.X, loc.Y + 4, 12, 3));
1245 graphics.FillRectangle (Brushes.White, new Rectangle (loc.X + 5, loc.Y + 2, 2, 4));
1246 graphics.FillRectangle (Brushes.White, new Rectangle (loc.X + 5, loc.Y + 7, 2, 2));
1249 internal virtual void PaintPartBackground (Graphics graphics, Rectangle cellBounds, DataGridViewCellStyle style)
1251 Color color = style.BackColor;
1252 graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (color), cellBounds);
1255 internal Pen GetBorderPen ()
1257 return ThemeEngine.Current.ResPool.GetPen (DataGridView.GridColor);
1260 internal virtual void PaintPartContent (Graphics graphics, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, DataGridViewCellStyle cellStyle, object formattedValue)
1265 Color color = Selected ? cellStyle.SelectionForeColor : cellStyle.ForeColor;
1267 TextFormatFlags flags = TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter | TextFormatFlags.TextBoxControl;
1268 flags |= AlignmentToFlags (style.Alignment);
1270 cellBounds.Height -= 2;
1271 cellBounds.Width -= 2;
1273 if (formattedValue != null)
1274 TextRenderer.DrawText (graphics, formattedValue.ToString (), cellStyle.Font, cellBounds, color, flags);
1277 private void PaintPartFocus (Graphics graphics, Rectangle cellBounds)
1280 cellBounds.Height--;
1282 if (DataGridView.ShowFocusCues && DataGridView.CurrentCell == this && DataGridView.Focused)
1283 ControlPaint.DrawFocusRectangle (graphics, cellBounds);
1286 internal virtual void PaintPartSelectionBackground (Graphics graphics, Rectangle cellBounds, DataGridViewElementStates cellState, DataGridViewCellStyle cellStyle)
1288 if ((cellState & DataGridViewElementStates.Selected) != DataGridViewElementStates.Selected)
1291 if (RowIndex >= 0 && IsInEditMode && EditType != null)
1294 Color color = cellStyle.SelectionBackColor;
1295 graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (color), cellBounds);
1298 internal void PaintWork (Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
1301 object formattedvalue;
1303 if (RowIndex == -1 && !(this is DataGridViewColumnHeaderCell)) {
1305 formattedvalue = null;
1306 } else if (RowIndex == -1) {
1308 formattedvalue = Value;
1311 formattedvalue = GetFormattedValue (Value, rowIndex, ref cellStyle, null, null, DataGridViewDataErrorContexts.Formatting);
1314 DataGridViewCellPaintingEventArgs pea = new DataGridViewCellPaintingEventArgs (DataGridView, graphics, clipBounds, cellBounds, rowIndex, columnIndex, cellState, value, formattedvalue, ErrorText, cellStyle, advancedBorderStyle, paintParts);
1315 DataGridView.OnCellPaintingInternal (pea);
1320 pea.Paint (pea.ClipBounds, pea.PaintParts);
1323 protected virtual bool SetValue (int rowIndex, object value)
1325 object oldValue = this.Value;
1327 if (DataProperty != null && !DataProperty.IsReadOnly) {
1328 DataProperty.SetValue (OwningRow.DataBoundItem, value);
1329 } else if (DataGridView != null && DataGridView.VirtualMode) {
1330 DataGridViewCellValueEventArgs ea = new DataGridViewCellValueEventArgs(ColumnIndex, RowIndex);
1332 DataGridView.OnCellValuePushed(ea);
1337 if (!Object.ReferenceEquals (oldValue, value) || !Object.Equals (oldValue, value)) {
1338 RaiseCellValueChanged (new DataGridViewCellEventArgs (ColumnIndex, RowIndex));
1340 // Set this dirty flag back to false
1341 if (this is IDataGridViewEditingCell)
1342 (this as IDataGridViewEditingCell).EditingCellValueChanged = false;
1344 if (DataGridView != null)
1345 DataGridView.InvalidateCell (this);
1352 private void OnStyleChanged (object sender, EventArgs args) {
1353 if (DataGridView != null) {
1354 DataGridView.RaiseCellStyleChanged(new DataGridViewCellEventArgs(ColumnIndex, RowIndex));
1358 internal virtual Rectangle InternalErrorIconsBounds {
1359 get { return GetErrorIconBounds (null, null, -1); }
1362 internal void InternalPaint (Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) {
1363 Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
1366 internal void SetOwningRow (DataGridViewRow row) {
1370 internal void SetOwningColumn (DataGridViewColumn col) {
1371 columnIndex = col.Index;
1374 internal void SetColumnIndex (int index) {
1375 columnIndex = index;
1378 internal void SetIsInEditMode (bool isInEditMode) {
1379 this.isInEditMode = isInEditMode;
1382 internal void OnErrorTextChanged (DataGridViewCellEventArgs args) {
1383 if (DataGridView != null) {
1384 DataGridView.OnCellErrorTextChanged(args);
1388 internal TextFormatFlags AlignmentToFlags (DataGridViewContentAlignment align)
1390 TextFormatFlags flags = TextFormatFlags.Default;
1393 case DataGridViewContentAlignment.BottomCenter:
1394 flags |= TextFormatFlags.Bottom;
1395 flags |= TextFormatFlags.HorizontalCenter;
1397 case DataGridViewContentAlignment.BottomLeft:
1398 flags |= TextFormatFlags.Bottom;
1400 case DataGridViewContentAlignment.BottomRight:
1401 flags |= TextFormatFlags.Bottom;
1402 flags |= TextFormatFlags.Right;
1404 case DataGridViewContentAlignment.MiddleCenter:
1405 flags |= TextFormatFlags.VerticalCenter;
1406 flags |= TextFormatFlags.HorizontalCenter;
1408 case DataGridViewContentAlignment.MiddleLeft:
1409 flags |= TextFormatFlags.VerticalCenter;
1411 case DataGridViewContentAlignment.MiddleRight:
1412 flags |= TextFormatFlags.VerticalCenter;
1413 flags |= TextFormatFlags.Right;
1415 case DataGridViewContentAlignment.TopLeft:
1416 flags |= TextFormatFlags.Top;
1418 case DataGridViewContentAlignment.TopCenter:
1419 flags |= TextFormatFlags.HorizontalCenter;
1420 flags |= TextFormatFlags.Top;
1422 case DataGridViewContentAlignment.TopRight:
1423 flags |= TextFormatFlags.Right;
1424 flags |= TextFormatFlags.Top;
1431 internal Rectangle AlignInRectangle (Rectangle outer, Size inner, DataGridViewContentAlignment align)
1436 if (align == DataGridViewContentAlignment.BottomLeft || align == DataGridViewContentAlignment.MiddleLeft || align == DataGridViewContentAlignment.TopLeft)
1438 else if (align == DataGridViewContentAlignment.BottomCenter || align == DataGridViewContentAlignment.MiddleCenter || align == DataGridViewContentAlignment.TopCenter)
1439 x = Math.Max (outer.X + ((outer.Width - inner.Width) / 2), outer.Left);
1440 else if (align == DataGridViewContentAlignment.BottomRight || align == DataGridViewContentAlignment.MiddleRight || align == DataGridViewContentAlignment.TopRight)
1441 x = Math.Max (outer.Right - inner.Width, outer.X);
1442 if (align == DataGridViewContentAlignment.TopCenter || align == DataGridViewContentAlignment.TopLeft || align == DataGridViewContentAlignment.TopRight)
1444 else if (align == DataGridViewContentAlignment.MiddleCenter || align == DataGridViewContentAlignment.MiddleLeft || align == DataGridViewContentAlignment.MiddleRight)
1445 y = Math.Max (outer.Y + (outer.Height - inner.Height) / 2, outer.Y);
1446 else if (align == DataGridViewContentAlignment.BottomCenter || align == DataGridViewContentAlignment.BottomRight || align == DataGridViewContentAlignment.BottomLeft)
1447 y = Math.Max (outer.Bottom - inner.Height, outer.Y);
1449 return new Rectangle (x, y, Math.Min (inner.Width, outer.Width), Math.Min (inner.Height, outer.Height));
1452 [ComVisibleAttribute(true)]
1453 protected class DataGridViewCellAccessibleObject : AccessibleObject {
1455 private DataGridViewCell dataGridViewCell;
1457 public DataGridViewCellAccessibleObject () {
1460 public DataGridViewCellAccessibleObject (DataGridViewCell owner) {
1461 this.dataGridViewCell = owner;
1464 public override Rectangle Bounds {
1465 get { throw new NotImplementedException(); }
1468 public override string DefaultAction {
1469 get { return "Edit"; }
1472 public override string Help {
1473 get { return base.Help; }
1476 public override string Name {
1477 get { return dataGridViewCell.OwningColumn.HeaderText + ": " + dataGridViewCell.RowIndex.ToString(); }
1480 public DataGridViewCell Owner {
1481 get { return dataGridViewCell; }
1482 set { dataGridViewCell = value; }
1485 public override AccessibleObject Parent {
1486 get { return dataGridViewCell.OwningRow.AccessibilityObject; }
1489 public override AccessibleRole Role {
1490 get { return AccessibleRole.Cell; }
1493 public override AccessibleStates State {
1495 if (dataGridViewCell.Selected) {
1496 return AccessibleStates.Selected;
1499 return AccessibleStates.Focused;
1504 public override string Value {
1506 if (dataGridViewCell.FormattedValue == null) {
1509 return dataGridViewCell.FormattedValue.ToString();
1513 throw new InvalidOperationException ("owner is null");
1515 throw new NotImplementedException ();
1519 public override void DoDefaultAction () {
1520 if (dataGridViewCell.DataGridView.EditMode != DataGridViewEditMode.EditProgrammatically) {
1521 if (dataGridViewCell.IsInEditMode) {
1530 public override AccessibleObject GetChild (int index) {
1531 throw new NotImplementedException();
1534 public override int GetChildCount () {
1535 if (dataGridViewCell.IsInEditMode) {
1541 public override AccessibleObject GetFocused () {
1545 public override AccessibleObject GetSelected () {
1549 public override AccessibleObject Navigate (AccessibleNavigation navigationDirection) {
1550 switch (navigationDirection) {
1551 case AccessibleNavigation.Right:
1553 case AccessibleNavigation.Left:
1555 case AccessibleNavigation.Next:
1557 case AccessibleNavigation.Previous:
1559 case AccessibleNavigation.Up:
1561 case AccessibleNavigation.Down:
1569 public override void Select (AccessibleSelection flags) {
1571 case AccessibleSelection.TakeFocus:
1572 dataGridViewCell.dataGridViewOwner.Focus();
1574 case AccessibleSelection.TakeSelection:
1575 //dataGridViewCell.Focus();
1577 case AccessibleSelection.AddSelection:
1578 dataGridViewCell.dataGridViewOwner.SelectedCells.InternalAdd(dataGridViewCell);
1580 case AccessibleSelection.RemoveSelection:
1581 dataGridViewCell.dataGridViewOwner.SelectedCells.InternalRemove(dataGridViewCell);
1589 internal class DataGridViewCellConverter : TypeConverter