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>
31 using System
.ComponentModel
;
32 using System
.Runtime
.InteropServices
;
34 namespace System
.Windows
.Forms
{
36 // XXX [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 Rectangle contentBounds
;
44 private ContextMenuStrip contextMenuStrip
;
45 private object defaultNewRowValue
;
46 private bool displayed
;
47 private object editedFormattedValue
;
48 private Type editType
;
49 private Rectangle errorIconBounds
;
50 private string errorText
;
51 private Type formattedValueType
;
53 private DataGridViewElementStates inheritedState
;
54 private bool isInEditMode
;
55 private DataGridViewColumn owningColumn
;
56 private DataGridViewRow owningRow
;
57 private Size preferredSize
;
58 private bool readOnly
;
59 private bool resizable
;
60 private bool selected
;
62 private DataGridViewCellStyle style
;
64 private string toolTipText
;
65 private object valuex
;
66 private Type valueType
;
69 protected DataGridViewCell ()
80 public AccessibleObject AccessibilityObject
{
82 if (accessibilityObject
== null) {
83 accessibilityObject
= CreateAccessibilityInstance();
85 return accessibilityObject
;
89 public int ColumnIndex
{
90 get { return columnIndex; }
94 public Rectangle ContentBounds
{
95 get { return contentBounds; }
99 public virtual ContextMenuStrip ContextMenuStrip
{
100 get { return contextMenuStrip; }
101 set { contextMenuStrip = value; }
105 public virtual object DefaultNewRowValue
{
106 get { return defaultNewRowValue; }
110 public virtual bool Displayed
{
111 get { return displayed; }
115 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
116 public object EditedFormattedValue
{
117 get { return editedFormattedValue; }
121 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
122 public virtual Type EditType
{
123 get { return editType; }
127 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
128 public Rectangle ErrorIconBounds
{
129 get { return errorIconBounds; }
133 public string ErrorText
{
134 get { return errorText; }
136 if (errorText
!= value) {
138 OnErrorTextChanged(new DataGridViewCellEventArgs(ColumnIndex
, RowIndex
));
144 public object FormattedValue
{
146 DataGridViewCellStyle style
= InheritedStyle
;
147 if (style
.Format
!= String
.Empty
&& FormattedValueType
== typeof(string)) {
148 return String
.Format("{0:" + style.Format + "}", Value
);
150 return Convert
.ChangeType(Value
, FormattedValueType
, style
.FormatProvider
);
155 public virtual Type FormattedValueType
{
156 get { return formattedValueType; }
160 public virtual bool Frozen
{
161 get { return frozen; }
165 public bool HasStyle
{
166 get { return style != null; }
170 public DataGridViewElementStates InheritedState
{
171 get { return inheritedState; }
175 public DataGridViewCellStyle InheritedStyle
{
177 DataGridViewCellStyle result
= new DataGridViewCellStyle();
178 if (style
!= null && style
.Alignment
!= DataGridViewContentAlignment
.NotSet
) {
179 result
.Alignment
= style
.Alignment
;
181 else if (OwningRow
!= null && OwningRow
.DefaultCellStyle
.Alignment
!= DataGridViewContentAlignment
.NotSet
) {
182 result
.Alignment
= OwningRow
.DefaultCellStyle
.Alignment
;
184 else if (DataGridView
!= null) {
185 if ((RowIndex
% 2) == 1 && DataGridView
.AlternatingRowsDefaultCellStyle
.Alignment
!= DataGridViewContentAlignment
.NotSet
) {
186 result
.Alignment
= DataGridView
.AlternatingRowsDefaultCellStyle
.Alignment
;
188 else if (DataGridView
.RowsDefaultCellStyle
.Alignment
!= DataGridViewContentAlignment
.NotSet
) {
189 result
.Alignment
= DataGridView
.RowsDefaultCellStyle
.Alignment
;
191 else if (ColumnIndex
>= 0 && DataGridView
.Columns
[ColumnIndex
].DefaultCellStyle
.Alignment
!= DataGridViewContentAlignment
.NotSet
) {
192 result
.Alignment
= DataGridView
.Columns
[ColumnIndex
].DefaultCellStyle
.Alignment
;
195 result
.Alignment
= DataGridView
.DefaultCellStyle
.Alignment
;
198 if (style
!= null && style
.BackColor
!= Color
.Empty
) {
199 result
.BackColor
= style
.BackColor
;
201 else if (OwningRow
!= null && OwningRow
.DefaultCellStyle
.BackColor
!= Color
.Empty
) {
202 result
.BackColor
= OwningRow
.DefaultCellStyle
.BackColor
;
204 else if (DataGridView
!= null) {
205 if ((RowIndex
% 2) == 1 && DataGridView
.AlternatingRowsDefaultCellStyle
.BackColor
!= Color
.Empty
) {
206 result
.BackColor
= DataGridView
.AlternatingRowsDefaultCellStyle
.BackColor
;
208 else if (DataGridView
.RowsDefaultCellStyle
.BackColor
!= Color
.Empty
) {
209 result
.BackColor
= DataGridView
.RowsDefaultCellStyle
.BackColor
;
211 else if (ColumnIndex
>= 0 && DataGridView
.Columns
[ColumnIndex
].DefaultCellStyle
.BackColor
!= Color
.Empty
) {
212 result
.BackColor
= DataGridView
.Columns
[ColumnIndex
].DefaultCellStyle
.BackColor
;
215 result
.BackColor
= DataGridView
.DefaultCellStyle
.BackColor
;
218 if (style
!= null && style
.Font
!= null) {
219 result
.Font
= style
.Font
;
221 else if (OwningRow
!= null && OwningRow
.DefaultCellStyle
.Font
!= null) {
222 result
.Font
= OwningRow
.DefaultCellStyle
.Font
;
224 else if (DataGridView
!= null) {
225 if ((RowIndex
% 2) == 1 && DataGridView
.AlternatingRowsDefaultCellStyle
.Font
!= null) {
226 result
.Font
= DataGridView
.AlternatingRowsDefaultCellStyle
.Font
;
228 else if (DataGridView
.RowsDefaultCellStyle
.Font
!= null) {
229 result
.Font
= DataGridView
.RowsDefaultCellStyle
.Font
;
231 else if (ColumnIndex
>= 0 && DataGridView
.Columns
[ColumnIndex
].DefaultCellStyle
.Font
!= null) {
232 result
.Font
= DataGridView
.Columns
[ColumnIndex
].DefaultCellStyle
.Font
;
235 result
.Font
= DataGridView
.DefaultCellStyle
.Font
;
238 if (style
!= null && style
.ForeColor
!= Color
.Empty
) {
239 result
.ForeColor
= style
.ForeColor
;
241 else if (OwningRow
!= null && OwningRow
.DefaultCellStyle
.ForeColor
!= Color
.Empty
) {
242 result
.ForeColor
= OwningRow
.DefaultCellStyle
.ForeColor
;
244 else if (DataGridView
!= null) {
245 if ((RowIndex
% 2) == 1 && DataGridView
.AlternatingRowsDefaultCellStyle
.ForeColor
!= Color
.Empty
) {
246 result
.ForeColor
= DataGridView
.AlternatingRowsDefaultCellStyle
.ForeColor
;
248 else if (DataGridView
.RowsDefaultCellStyle
.ForeColor
!= Color
.Empty
) {
249 result
.ForeColor
= DataGridView
.RowsDefaultCellStyle
.ForeColor
;
251 else if (ColumnIndex
>= 0 && DataGridView
.Columns
[ColumnIndex
].DefaultCellStyle
.ForeColor
!= Color
.Empty
) {
252 result
.ForeColor
= DataGridView
.Columns
[ColumnIndex
].DefaultCellStyle
.ForeColor
;
255 result
.ForeColor
= DataGridView
.DefaultCellStyle
.ForeColor
;
258 if (style
!= null && style
.Format
!= String
.Empty
) {
259 result
.Format
= style
.Format
;
261 else if (OwningRow
!= null && OwningRow
.DefaultCellStyle
.Format
!= String
.Empty
) {
262 result
.Format
= OwningRow
.DefaultCellStyle
.Format
;
264 else if (DataGridView
!= null) {
265 if ((RowIndex
% 2) == 1 && DataGridView
.AlternatingRowsDefaultCellStyle
.Format
!= String
.Empty
) {
266 result
.Format
= DataGridView
.AlternatingRowsDefaultCellStyle
.Format
;
268 else if (DataGridView
.RowsDefaultCellStyle
.Format
!= String
.Empty
) {
269 result
.Format
= DataGridView
.RowsDefaultCellStyle
.Format
;
271 else if (ColumnIndex
>= 0 && DataGridView
.Columns
[ColumnIndex
].DefaultCellStyle
.Format
!= String
.Empty
) {
272 result
.Format
= DataGridView
.Columns
[ColumnIndex
].DefaultCellStyle
.Format
;
275 result
.Format
= DataGridView
.DefaultCellStyle
.Format
;
278 if (style
!= null && style
.FormatProvider
!= System
.Globalization
.CultureInfo
.CurrentUICulture
) {
279 result
.FormatProvider
= style
.FormatProvider
;
281 else if (OwningRow
!= null && OwningRow
.DefaultCellStyle
.FormatProvider
!= System
.Globalization
.CultureInfo
.CurrentUICulture
) {
282 result
.FormatProvider
= OwningRow
.DefaultCellStyle
.FormatProvider
;
284 else if (DataGridView
!= null) {
285 if ((RowIndex
% 2) == 1 && DataGridView
.AlternatingRowsDefaultCellStyle
.FormatProvider
!= System
.Globalization
.CultureInfo
.CurrentUICulture
) {
286 result
.FormatProvider
= DataGridView
.AlternatingRowsDefaultCellStyle
.FormatProvider
;
288 else if (DataGridView
.RowsDefaultCellStyle
.FormatProvider
!= System
.Globalization
.CultureInfo
.CurrentUICulture
) {
289 result
.FormatProvider
= DataGridView
.RowsDefaultCellStyle
.FormatProvider
;
291 else if (ColumnIndex
>= 0 && DataGridView
.Columns
[ColumnIndex
].DefaultCellStyle
.FormatProvider
!= System
.Globalization
.CultureInfo
.CurrentUICulture
) {
292 result
.FormatProvider
= DataGridView
.Columns
[ColumnIndex
].DefaultCellStyle
.FormatProvider
;
295 result
.FormatProvider
= DataGridView
.DefaultCellStyle
.FormatProvider
;
298 if (style
!= null && (string) style
.NullValue
!= "(null)") {
299 result
.NullValue
= style
.NullValue
;
301 else if (OwningRow
!= null && (string) OwningRow
.DefaultCellStyle
.NullValue
!= "(null)") {
302 result
.NullValue
= OwningRow
.DefaultCellStyle
.NullValue
;
304 else if (DataGridView
!= null) {
305 if ((RowIndex
% 2) == 1 && (string) DataGridView
.AlternatingRowsDefaultCellStyle
.NullValue
!= "(null)") {
306 result
.NullValue
= DataGridView
.AlternatingRowsDefaultCellStyle
.NullValue
;
308 else if ((string) DataGridView
.RowsDefaultCellStyle
.NullValue
!= "(null)") {
309 result
.NullValue
= DataGridView
.RowsDefaultCellStyle
.NullValue
;
311 else if (ColumnIndex
>= 0 && (string) DataGridView
.Columns
[ColumnIndex
].DefaultCellStyle
.NullValue
!= "(null)") {
312 result
.NullValue
= DataGridView
.Columns
[ColumnIndex
].DefaultCellStyle
.NullValue
;
315 result
.NullValue
= DataGridView
.DefaultCellStyle
.NullValue
;
318 if (style
!= null && style
.Padding
!= Padding
.Empty
) {
319 result
.Padding
= style
.Padding
;
321 else if (OwningRow
!= null && OwningRow
.DefaultCellStyle
.Padding
!= Padding
.Empty
) {
322 result
.Padding
= OwningRow
.DefaultCellStyle
.Padding
;
324 else if (DataGridView
!= null) {
325 if ((RowIndex
% 2) == 1 && DataGridView
.AlternatingRowsDefaultCellStyle
.Padding
!= Padding
.Empty
) {
326 result
.Padding
= DataGridView
.AlternatingRowsDefaultCellStyle
.Padding
;
328 else if (DataGridView
.RowsDefaultCellStyle
.Padding
!= Padding
.Empty
) {
329 result
.Padding
= DataGridView
.RowsDefaultCellStyle
.Padding
;
331 else if (ColumnIndex
>= 0 && DataGridView
.Columns
[ColumnIndex
].DefaultCellStyle
.Padding
!= Padding
.Empty
) {
332 result
.Padding
= DataGridView
.Columns
[ColumnIndex
].DefaultCellStyle
.Padding
;
335 result
.Padding
= DataGridView
.DefaultCellStyle
.Padding
;
338 if (style
!= null && style
.SelectionBackColor
!= Color
.Empty
) {
339 result
.SelectionBackColor
= style
.SelectionBackColor
;
341 else if (OwningRow
!= null && OwningRow
.DefaultCellStyle
.SelectionBackColor
!= Color
.Empty
) {
342 result
.SelectionBackColor
= OwningRow
.DefaultCellStyle
.SelectionBackColor
;
344 else if (DataGridView
!= null) {
345 if ((RowIndex
% 2) == 1 && DataGridView
.AlternatingRowsDefaultCellStyle
.SelectionBackColor
!= Color
.Empty
) {
346 result
.SelectionBackColor
= DataGridView
.AlternatingRowsDefaultCellStyle
.SelectionBackColor
;
348 else if (DataGridView
.RowsDefaultCellStyle
.SelectionBackColor
!= Color
.Empty
) {
349 result
.SelectionBackColor
= DataGridView
.RowsDefaultCellStyle
.SelectionBackColor
;
351 else if (ColumnIndex
>= 0 && DataGridView
.Columns
[ColumnIndex
].DefaultCellStyle
.SelectionBackColor
!= Color
.Empty
) {
352 result
.SelectionBackColor
= DataGridView
.Columns
[ColumnIndex
].DefaultCellStyle
.SelectionBackColor
;
355 result
.SelectionBackColor
= DataGridView
.DefaultCellStyle
.SelectionBackColor
;
358 if (style
!= null && style
.SelectionForeColor
!= Color
.Empty
) {
359 result
.SelectionForeColor
= style
.SelectionForeColor
;
361 else if (OwningRow
!= null && OwningRow
.DefaultCellStyle
.SelectionForeColor
!= Color
.Empty
) {
362 result
.SelectionForeColor
= OwningRow
.DefaultCellStyle
.SelectionForeColor
;
364 else if (DataGridView
!= null) {
365 if ((RowIndex
% 2) == 1 && DataGridView
.AlternatingRowsDefaultCellStyle
.SelectionForeColor
!= Color
.Empty
) {
366 result
.SelectionForeColor
= DataGridView
.AlternatingRowsDefaultCellStyle
.SelectionForeColor
;
368 else if (DataGridView
.RowsDefaultCellStyle
.SelectionForeColor
!= Color
.Empty
) {
369 result
.SelectionForeColor
= DataGridView
.RowsDefaultCellStyle
.SelectionForeColor
;
371 else if (ColumnIndex
>= 0 && DataGridView
.Columns
[ColumnIndex
].DefaultCellStyle
.SelectionForeColor
!= Color
.Empty
) {
372 result
.SelectionForeColor
= DataGridView
.Columns
[ColumnIndex
].DefaultCellStyle
.SelectionForeColor
;
375 result
.SelectionForeColor
= DataGridView
.DefaultCellStyle
.SelectionForeColor
;
378 if (style
!= null && style
.Tag
!= null) {
379 result
.Tag
= style
.Tag
;
381 else if (OwningRow
!= null && OwningRow
.DefaultCellStyle
.Tag
!= null) {
382 result
.Tag
= OwningRow
.DefaultCellStyle
.Tag
;
384 else if (DataGridView
!= null) {
385 if ((RowIndex
% 2) == 1 && DataGridView
.AlternatingRowsDefaultCellStyle
.Tag
!= null) {
386 result
.Tag
= DataGridView
.AlternatingRowsDefaultCellStyle
.Tag
;
388 else if (DataGridView
.RowsDefaultCellStyle
.Tag
!= null) {
389 result
.Tag
= DataGridView
.RowsDefaultCellStyle
.Tag
;
391 else if (ColumnIndex
>= 0 && DataGridView
.Columns
[ColumnIndex
].DefaultCellStyle
.Tag
!= null) {
392 result
.Tag
= DataGridView
.Columns
[ColumnIndex
].DefaultCellStyle
.Tag
;
395 result
.Tag
= DataGridView
.DefaultCellStyle
.Tag
;
398 if (style
!= null && style
.WrapMode
!= DataGridViewTriState
.NotSet
) {
399 result
.WrapMode
= style
.WrapMode
;
401 else if (OwningRow
!= null && OwningRow
.DefaultCellStyle
.WrapMode
!= DataGridViewTriState
.NotSet
) {
402 result
.WrapMode
= OwningRow
.DefaultCellStyle
.WrapMode
;
404 else if (DataGridView
!= null) {
405 if ((RowIndex
% 2) == 1 && DataGridView
.AlternatingRowsDefaultCellStyle
.WrapMode
!= DataGridViewTriState
.NotSet
) {
406 result
.WrapMode
= DataGridView
.AlternatingRowsDefaultCellStyle
.WrapMode
;
408 else if (DataGridView
.RowsDefaultCellStyle
.WrapMode
!= DataGridViewTriState
.NotSet
) {
409 result
.WrapMode
= DataGridView
.RowsDefaultCellStyle
.WrapMode
;
411 else if (ColumnIndex
>= 0 && DataGridView
.Columns
[ColumnIndex
].DefaultCellStyle
.WrapMode
!= DataGridViewTriState
.NotSet
) {
412 result
.WrapMode
= DataGridView
.Columns
[ColumnIndex
].DefaultCellStyle
.WrapMode
;
415 result
.WrapMode
= DataGridView
.DefaultCellStyle
.WrapMode
;
423 public bool IsInEditMode
{
424 get { return isInEditMode; }
428 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
429 public DataGridViewColumn OwningColumn
{
430 get { return owningColumn; }
434 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
435 public DataGridViewRow OwningRow
{
436 get { return owningRow; }
440 public Size PreferredSize
{
441 get { return preferredSize; }
445 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
446 public virtual bool ReadOnly
{
447 get { return readOnly; }
448 set { readOnly = value; }
452 public virtual bool Resizable
{
453 get { return resizable; }
457 public int RowIndex
{
459 if (owningRow
== null) {
462 return owningRow
.Index
;
467 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
468 public virtual bool Selected
{
469 get { return selected; }
471 if (value != ((State
& DataGridViewElementStates
.Selected
) != 0)) {
472 SetState(State ^ DataGridViewElementStates
.Selected
);
484 public DataGridViewCellStyle Style
{
487 style
= new DataGridViewCellStyle();
488 style
.StyleChanged
+= OnStyleChanged
;
492 set { style = value; }
495 [Bindable (true, BindingDirection
.OneWay
)]
496 [DefaultValue (null)]
497 [Localizable (false)]
498 [TypeConverter ("System.ComponentModel.StringConverter, " + Consts
.AssemblySystem
)]
505 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
506 public string ToolTipText
{
507 get { return toolTipText; }
508 set { toolTipText = value; }
512 public object Value
{
513 get { return valuex; }
515 if (valuex
!= value) {
517 RaiseCellValueChanged(new DataGridViewCellEventArgs(ColumnIndex
, RowIndex
));
523 public virtual Type ValueType
{
524 get { return valueType; }
525 set { valueType = value; }
529 public virtual bool Visible
{
530 get { return visible; }
533 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
534 public virtual DataGridViewAdvancedBorderStyle
AdjustCellBorderStyle (DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStyleInput
, DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceholder
, bool singleVerticalBorderAdded
, bool singleHorizontalBorderAdded
, bool isFirstDisplayedColumn
, bool isFirstDisplayedRow
) {
535 return dataGridViewAdvancedBorderStyleInput
;
538 public virtual object Clone () {
539 return this.MemberwiseClone();
541 DataGridViewCell result = null; // = new DataGridViewCell();
542 result.accessibilityObject = this.accessibilityObject;
543 result.columnIndex = this.columnIndex;
544 result.contentBounds = this.contentBounds;
545 //result.contextMenuStrip = this.contextMenuStrip;
546 result.defaultNewRowValue = this.defaultNewRowValue;
547 result.displayed = this.displayed;
548 result.editedFormattedValue = this.editedFormattedValue;
549 result.editType = this.editType;
550 result.errorIconBounds = this.errorIconBounds;
551 result.errorText = this.errorText;
552 result.formattedValueType = this.formattedValueType;
553 result.frozen = this.frozen;
554 result.hasStyle = this.hasStyle;
555 result.inheritedState = this.inheritedState;
556 result.inheritedStyle = this.inheritedStyle;
557 result.isInEditMode = this.isInEditMode;
558 result.owningColumn = this.owningColumn;
559 result.owningRow = this.owningRow;
560 result.preferredSize = this.preferredSize;
561 result.readOnly = this.readOnly;
562 result.resizable = this.resizable;
563 result.selected = this.selected;
564 result.size = this.size;
565 result.style = this.style;
566 result.tag = this.tag;
567 result.toolTipText = this.toolTipText;
568 result.valuex = this.valuex;
569 result.valueType = this.valueType;
570 result.visible = this.visible;
575 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
576 public virtual void DetachEditingControl () {
579 //public sealed void Dispose () {
580 public void Dispose () {
583 public Rectangle
GetContentBounds (int rowIndex
) {
584 throw new NotImplementedException();
587 public object GetEditedFormattedValue (int rowIndex
, DataGridViewDataErrorContexts context
) {
588 throw new NotImplementedException();
591 public virtual ContextMenuStrip
GetInheritedContextMenuStrip (int rowIndex
)
593 throw new NotImplementedException();
596 public virtual DataGridViewElementStates
GetInheritedState (int rowIndex
) {
597 throw new NotImplementedException();
600 public virtual DataGridViewCellStyle
GetInheritedStyle (DataGridViewCellStyle inheritedCellStyle
, int rowIndex
, bool includeColors
) {
602 * System.InvalidOperationException :: The cell has no associated System.Windows.Forms.DataGridView, or the cell's System.Windows.Forms.DataGridViewCell.ColumnIndex is less than 0.
603 * System.ArgumentOutOfRangeException :: rowIndex is less than 0, or greater than or equal to the number of rows in the parent System.Windows.Forms.DataGridView.
605 throw new NotImplementedException();
608 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
609 public virtual void InitializeEditingControl (int rowIndex
, object initialFormattedValue
, DataGridViewCellStyle dataGridViewCellStyle
) {
610 if (DataGridView
== null || DataGridView
.EditingControl
== null) {
611 throw new InvalidOperationException("No editing control defined");
615 public virtual bool KeyEntersEditMode (KeyEventArgs e
) {
616 throw new NotImplementedException();
619 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
620 public static int MeasureTextHeight (Graphics graphics
, string text
, Font font
, int maxWidth
, TextFormatFlags flags
) {
621 if (graphics
== null) {
622 throw new ArgumentNullException("Graphics argument null");
625 throw new ArgumentNullException("Font argument null");
628 throw new ArgumentOutOfRangeException("maxWidth is less than 1.");
630 // if (flags ---> InvalidEnumArgumentException
631 throw new NotImplementedException();
634 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
635 public static int MeasureTextHeight (Graphics graphics
, string text
, Font font
, int maxWidth
, TextFormatFlags flags
, out bool widthTruncated
) {
636 throw new NotImplementedException();
639 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
640 public static Size
MeasureTextPreferredSize (Graphics graphics
, string text
, Font font
, float maxRatio
, TextFormatFlags flags
) {
641 if (graphics
== null) {
642 throw new ArgumentNullException("Graphics argument null");
645 throw new ArgumentNullException("Font argument null");
648 throw new ArgumentOutOfRangeException("maxRatio is less than or equals to 0.");
650 throw new NotImplementedException();
653 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
654 public static Size
MeasureTextSize (Graphics graphics
, string text
, Font font
, TextFormatFlags flags
) {
655 /////////////////////////// ¿flags?
656 return graphics
.MeasureString(text
, font
).ToSize();
659 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
660 public static int MeasureTextWidth (Graphics graphics
, string text
, Font font
, int maxHeight
, TextFormatFlags flags
) {
661 if (graphics
== null) {
662 throw new ArgumentNullException("Graphics argument null");
665 throw new ArgumentNullException("Font argument null");
668 throw new ArgumentOutOfRangeException("maxHeight is less than 1.");
670 throw new NotImplementedException();
673 public virtual object ParseFormattedValue (object formattedValue
, DataGridViewCellStyle cellStyle
, TypeConverter formattedValueTypeConverter
, TypeConverter valueTypeConverter
) {
674 if (cellStyle
== null) {
675 throw new ArgumentNullException("cellStyle is null.");
677 if (formattedValueType
== null) {
678 throw new FormatException("The System.Windows.Forms.DataGridViewCell.FormattedValueType property value is null.");
680 if (formattedValue
== null) {
681 throw new ArgumentException("formattedValue is null.");
683 if (formattedValue
.GetType() != formattedValueType
) {
688 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
689 public virtual void PositionEditingControl (bool setLocation
, bool setSize
, Rectangle cellBounds
, Rectangle cellClip
, DataGridViewCellStyle cellStyle
, bool singleVerticalBorderAdded
, bool singleHorizontalBorderAdded
, bool isFirstDisplayedColumn
, bool isFirstDisplayedRow
) {
690 throw new NotImplementedException();
693 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
694 public virtual Rectangle
PositionEditingPanel (Rectangle cellBounds
, Rectangle cellClip
, DataGridViewCellStyle cellStyle
, bool singleVerticalBorderAdded
, bool singleHorizontalBorderAdded
, bool isFirstDisplayedColumn
, bool isFirstDisplayedRow
) {
695 throw new NotImplementedException();
698 public override string ToString () {
699 return String
.Format("{0} {RowIndex = {1}, ColumnIndex = {2}}", this.GetType().FullName
, RowIndex
, columnIndex
);
702 protected virtual Rectangle
BorderWidths (DataGridViewAdvancedBorderStyle advancedBorderStyle
)
704 throw new NotImplementedException();
707 protected virtual bool ClickUnsharesRow (DataGridViewCellEventArgs e
)
709 throw new NotImplementedException();
712 protected virtual bool ContentClickUnsharesRow (DataGridViewCellEventArgs e
)
714 throw new NotImplementedException();
717 protected virtual bool ContentDoubleClickUnsharesRow (DataGridViewCellEventArgs e
)
719 throw new NotImplementedException();
722 protected virtual AccessibleObject
CreateAccessibilityInstance () {
723 return new DataGridViewCellAccessibleObject(this);
726 protected virtual void Dispose (bool disposing
) {
729 protected virtual bool DoubleClickUnsharesRow (DataGridViewCellEventArgs e
) {
730 throw new NotImplementedException();
733 protected virtual bool EnterUnsharesRow (int rowIndex
, bool throughMouseClick
) {
734 throw new NotImplementedException();
737 protected virtual object GetClipboardContent (int rowIndex
, bool firstCell
, bool lastCell
, bool inFirstRow
, bool inLastRow
, string format
) {
738 throw new NotImplementedException();
741 protected virtual Rectangle
GetContentBounds (Graphics graphics
, DataGridViewCellStyle cellStyle
, int rowIndex
) {
742 throw new NotImplementedException();
745 protected virtual Rectangle
GetErrorIconBounds (Graphics graphics
, DataGridViewCellStyle cellStyle
, int rowIndex
) {
746 throw new NotImplementedException();
749 protected internal virtual string GetErrorText (int rowIndex
) {
750 throw new NotImplementedException();
753 protected virtual object GetFormattedValue (object value, int rowIndex
, ref DataGridViewCellStyle cellStyle
, TypeConverter valueTypeConverter
, TypeConverter formattedValueTypeConverter
, DataGridViewDataErrorContexts context
)
755 throw new NotImplementedException();
758 protected virtual Size
GetPreferredSize (Graphics graphics
, DataGridViewCellStyle cellStyle
, int rowIndex
, Size constraintSize
) {
759 throw new NotImplementedException();
762 protected virtual Size
GetSize (int rowIndex
) {
763 throw new NotImplementedException();
766 protected virtual object GetValue (int rowIndex
) {
767 throw new NotImplementedException();
770 protected virtual bool KeyDownUnsharesRow (KeyEventArgs e
, int rowIndex
) {
771 throw new NotImplementedException();
774 protected virtual bool KeyPressUnsharesRow (KeyPressEventArgs e
, int rowIndex
) {
775 throw new NotImplementedException();
778 protected virtual bool KeyUpUnsharesRow (KeyEventArgs e
, int rowIndex
) {
779 throw new NotImplementedException();
782 protected virtual bool LeaveUnsharesRow (int rowIndex
, bool throughMouseClick
) {
783 throw new NotImplementedException();
786 protected virtual bool MouseClickUnsharesRow (DataGridViewCellMouseEventArgs e
) {
787 throw new NotImplementedException();
790 protected virtual bool MouseDoubleClickUnsharesRow (DataGridViewCellMouseEventArgs e
) {
791 throw new NotImplementedException();
794 protected virtual bool MouseDownUnsharesRow (DataGridViewCellMouseEventArgs e
) {
795 throw new NotImplementedException();
798 protected virtual bool MouseEnterUnsharesRow (int rowIndex
) {
799 throw new NotImplementedException();
802 protected virtual bool MouseLeaveUnsharesRow (int rowIndex
) {
803 throw new NotImplementedException();
806 protected virtual bool MouseMoveUnsharesRow (DataGridViewCellMouseEventArgs e
) {
807 throw new NotImplementedException();
810 protected virtual bool MouseUpUnsharesRow (DataGridViewCellMouseEventArgs e
) {
811 throw new NotImplementedException();
814 protected virtual void OnClick (DataGridViewCellEventArgs e
) {
817 protected virtual void OnContentClick (DataGridViewCellEventArgs e
) {
820 protected virtual void OnContentDoubleClick (DataGridViewCellEventArgs e
) {
823 protected override void OnDataGridViewChanged () {
826 protected virtual void OnDoubleClick (DataGridViewCellEventArgs e
) {
829 protected virtual void OnEnter (int rowIndex
, bool throughMouseClick
) {
832 protected virtual void OnKeyDown (KeyEventArgs e
, int rowIndex
) {
835 protected virtual void OnKeyPress (KeyPressEventArgs e
, int rowIndex
) {
838 protected virtual void OnKeyUp (KeyEventArgs e
, int rowIndex
) {
841 protected virtual void OnLeave (int rowIndex
, bool throughMouseClick
) {
844 protected virtual void OnMouseClick (DataGridViewCellMouseEventArgs e
) {
847 protected virtual void OnMouseDoubleClick (DataGridViewCellMouseEventArgs e
) {
850 protected virtual void OnMouseDown (DataGridViewCellMouseEventArgs e
) {
853 protected virtual void OnMouseEnter (int rowIndex
) {
856 protected virtual void OnMouseLeave (int rowIndex
) {
859 protected virtual void OnMouseMove (DataGridViewCellMouseEventArgs e
) {
862 protected virtual void OnMouseUp (DataGridViewCellMouseEventArgs e
) {
865 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
) {
866 throw new NotImplementedException();
869 protected virtual void PaintBorder (Graphics graphics
, Rectangle clipBounds
, Rectangle bounds
, DataGridViewCellStyle cellStyle
, DataGridViewAdvancedBorderStyle advancedBorderStyle
) {
870 Pen pen
= new Pen(DataGridView
.GridColor
);
872 switch (advancedBorderStyle.All) {
873 case DataGridViewAdvancedCellBorderStyle.None:
875 case DataGridViewAdvancedCellBorderStyle.Single:
876 graphics.DrawRectangle(pen, bounds);
878 case DataGridViewAdvancedCellBorderStyle.Inset:
883 graphics.DrawRectangle(pen, bounds);
885 case DataGridViewAdvancedCellBorderStyle.InsetDouble:
886 case DataGridViewAdvancedCellBorderStyle.Outset:
887 case DataGridViewAdvancedCellBorderStyle.OutsetDouble:
888 case DataGridViewAdvancedCellBorderStyle.OutsetPartial:
890 case DataGridViewAdvancedCellBorderStyle.NotSet:
892 switch (advancedBorderStyle
.Left
) {
893 case DataGridViewAdvancedCellBorderStyle
.None
:
895 case DataGridViewAdvancedCellBorderStyle
.Single
:
896 graphics
.DrawLine(pen
, bounds
.X
, bounds
.Y
, bounds
.X
, bounds
.Y
+ bounds
.Height
- 1);
898 case DataGridViewAdvancedCellBorderStyle
.Inset
:
899 graphics
.DrawLine(pen
, bounds
.X
+ 2, bounds
.Y
, bounds
.X
+ 2, bounds
.Y
+ bounds
.Height
- 1);
901 case DataGridViewAdvancedCellBorderStyle
.InsetDouble
:
902 case DataGridViewAdvancedCellBorderStyle
.Outset
:
903 case DataGridViewAdvancedCellBorderStyle
.OutsetDouble
:
904 graphics
.DrawLine(pen
, bounds
.X
, bounds
.Y
, bounds
.X
, bounds
.Y
+ bounds
.Height
- 1);
905 graphics
.DrawLine(pen
, bounds
.X
+ 2, bounds
.Y
, bounds
.X
+ 2, bounds
.Y
+ bounds
.Height
- 1);
907 case DataGridViewAdvancedCellBorderStyle
.OutsetPartial
:
910 switch (advancedBorderStyle
.Right
) {
911 case DataGridViewAdvancedCellBorderStyle
.None
:
913 case DataGridViewAdvancedCellBorderStyle
.Single
:
914 graphics
.DrawLine(pen
, bounds
.X
+ bounds
.Width
- 1, bounds
.Y
, bounds
.X
+ bounds
.Width
- 1, bounds
.Y
+ bounds
.Height
- 1);
916 case DataGridViewAdvancedCellBorderStyle
.Inset
:
917 graphics
.DrawLine(pen
, bounds
.X
+ bounds
.Width
+ 1, bounds
.Y
, bounds
.X
+ bounds
.Width
- 3, bounds
.Y
+ bounds
.Height
- 1);
919 case DataGridViewAdvancedCellBorderStyle
.InsetDouble
:
920 case DataGridViewAdvancedCellBorderStyle
.Outset
:
921 case DataGridViewAdvancedCellBorderStyle
.OutsetDouble
:
922 case DataGridViewAdvancedCellBorderStyle
.OutsetPartial
:
925 switch (advancedBorderStyle
.Top
) {
926 case DataGridViewAdvancedCellBorderStyle
.None
:
928 case DataGridViewAdvancedCellBorderStyle
.Single
:
929 graphics
.DrawLine(pen
, bounds
.X
, bounds
.Y
, bounds
.X
+ bounds
.Width
- 1, bounds
.Y
);
931 case DataGridViewAdvancedCellBorderStyle
.Inset
:
932 graphics
.DrawLine(pen
, bounds
.X
, bounds
.Y
+ 2, bounds
.X
+ bounds
.Width
- 1, bounds
.Y
+ bounds
.Height
+ 1);
934 case DataGridViewAdvancedCellBorderStyle
.InsetDouble
:
935 case DataGridViewAdvancedCellBorderStyle
.Outset
:
936 case DataGridViewAdvancedCellBorderStyle
.OutsetDouble
:
937 case DataGridViewAdvancedCellBorderStyle
.OutsetPartial
:
940 switch (advancedBorderStyle
.Bottom
) {
941 case DataGridViewAdvancedCellBorderStyle
.None
:
943 case DataGridViewAdvancedCellBorderStyle
.Single
:
944 graphics
.DrawLine(pen
, bounds
.X
, bounds
.Y
+ bounds
.Height
- 1, bounds
.X
+ bounds
.Width
- 1, bounds
.Y
+ bounds
.Height
- 1);
946 case DataGridViewAdvancedCellBorderStyle
.Inset
:
947 case DataGridViewAdvancedCellBorderStyle
.InsetDouble
:
948 case DataGridViewAdvancedCellBorderStyle
.Outset
:
949 case DataGridViewAdvancedCellBorderStyle
.OutsetDouble
:
950 case DataGridViewAdvancedCellBorderStyle
.OutsetPartial
:
957 protected virtual void PaintErrorIcon (Graphics graphics
, Rectangle clipBounds
, Rectangle cellValueBounds
, string errorText
) {
958 throw new NotImplementedException();
961 protected virtual bool SetValue (int rowIndex
, object value) {
962 throw new NotImplementedException();
965 private void OnStyleChanged (object sender
, EventArgs args
) {
966 if (DataGridView
!= null) {
967 DataGridView
.RaiseCellStyleChanged(new DataGridViewCellEventArgs(ColumnIndex
, RowIndex
));
971 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
) {
972 Paint(graphics
, clipBounds
, cellBounds
, rowIndex
, cellState
, value, formattedValue
, errorText
, cellStyle
, advancedBorderStyle
, paintParts
);
975 internal void SetOwningRow (DataGridViewRow row
) {
979 internal void SetColumnIndex (int index
) {
983 internal void SetContentBounds (Rectangle bounds
) {
984 contentBounds
= bounds
;
987 internal void SetIsInEditMode (bool isInEditMode
) {
988 this.isInEditMode
= isInEditMode
;
991 internal void SetSize (Size size
) {
995 internal void OnErrorTextChanged (DataGridViewCellEventArgs args
) {
996 if (DataGridView
!= null) {
997 DataGridView
.OnCellErrorTextChanged(args
);
1001 [ComVisibleAttribute(true)]
1002 protected class DataGridViewCellAccessibleObject
: AccessibleObject
{
1004 private DataGridViewCell dataGridViewCell
;
1006 public DataGridViewCellAccessibleObject () {
1009 public DataGridViewCellAccessibleObject (DataGridViewCell cell
) {
1010 this.dataGridViewCell
= cell
;
1013 public override Rectangle Bounds
{
1014 get { throw new NotImplementedException(); }
1017 public override string DefaultAction
{
1018 get { return "Edit"; }
1021 public override string Name
{
1022 get { return dataGridViewCell.OwningColumn.HeaderText + ": " + dataGridViewCell.RowIndex.ToString(); }
1025 public DataGridViewCell Owner
{
1026 get { return dataGridViewCell; }
1027 set { dataGridViewCell = value; }
1030 public override AccessibleObject Parent
{
1031 get { return dataGridViewCell.OwningRow.AccessibilityObject; }
1034 public override AccessibleRole Role
{
1035 get { return AccessibleRole.Cell; }
1038 public override AccessibleStates State
{
1040 if (dataGridViewCell
.Selected
) {
1041 return AccessibleStates
.Selected
;
1044 return AccessibleStates
.Focused
;
1049 public override string Value
{
1051 if (dataGridViewCell
.FormattedValue
== null) {
1054 return dataGridViewCell
.FormattedValue
.ToString();
1058 public override void DoDefaultAction () {
1059 if (dataGridViewCell
.DataGridView
.EditMode
!= DataGridViewEditMode
.EditProgrammatically
) {
1060 if (dataGridViewCell
.IsInEditMode
) {
1069 public override AccessibleObject
GetChild (int index
) {
1070 throw new NotImplementedException();
1073 public override int GetChildCount () {
1074 if (dataGridViewCell
.IsInEditMode
) {
1080 public override AccessibleObject
GetFocused () {
1084 public override AccessibleObject
GetSelected () {
1088 public override AccessibleObject
Navigate (AccessibleNavigation navigationDirection
) {
1089 switch (navigationDirection
) {
1090 case AccessibleNavigation
.Right
:
1092 case AccessibleNavigation
.Left
:
1094 case AccessibleNavigation
.Next
:
1096 case AccessibleNavigation
.Previous
:
1098 case AccessibleNavigation
.Up
:
1100 case AccessibleNavigation
.Down
:
1108 public override void Select (AccessibleSelection flags
) {
1110 case AccessibleSelection
.TakeFocus
:
1111 dataGridViewCell
.dataGridViewOwner
.Focus();
1113 case AccessibleSelection
.TakeSelection
:
1114 //dataGridViewCell.Focus();
1116 case AccessibleSelection
.AddSelection
:
1117 dataGridViewCell
.dataGridViewOwner
.SelectedCells
.InternalAdd(dataGridViewCell
);
1119 case AccessibleSelection
.RemoveSelection
:
1120 dataGridViewCell
.dataGridViewOwner
.SelectedCells
.InternalRemove(dataGridViewCell
);