2007-08-28 Jonathan Pobst <monkey@jpobst.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / DataGridViewCell.cs
index 013702430dba796b73e86bb9c1636b42d3fdfbd3..064cd698cfc18d2e3fce6e2cd238451fb6e81536 100644 (file)
@@ -33,18 +33,18 @@ using System.Runtime.InteropServices;
 
 namespace System.Windows.Forms {
 
-       public abstract class DataGridViewCell : DataGridViewElement, ICloneable, IDisposable {
-
+       // XXX [TypeConverter (typeof (DataGridViewCellConverter))]
+       public abstract class DataGridViewCell : DataGridViewElement, ICloneable, IDisposable
+       {
                private DataGridView dataGridViewOwner;
 
                private AccessibleObject accessibilityObject;
                private int columnIndex;
                private Rectangle contentBounds;
-               // private ContextMenuStrip contextMenuStrip;
+               private ContextMenuStrip contextMenuStrip;
                private object defaultNewRowValue;
                private bool displayed;
                private object editedFormattedValue;
-               private Type editType;
                private Rectangle errorIconBounds;
                private string errorText;
                private Type formattedValueType;
@@ -54,7 +54,7 @@ namespace System.Windows.Forms {
                private DataGridViewColumn owningColumn;
                private DataGridViewRow owningRow;
                private Size preferredSize;
-               private bool readOnly;
+               private DataGridViewTriState readOnly;
                private bool resizable;
                private bool selected;
                private Size size;
@@ -65,14 +65,17 @@ namespace System.Windows.Forms {
                private Type valueType;
                private bool visible;
 
-               protected DataGridViewCell () {
+               protected DataGridViewCell ()
+               {
                        columnIndex = -1;
                }
 
-               ~DataGridViewCell () {
+               ~DataGridViewCell ()
+               {
                        Dispose(false);
                }
 
+               [Browsable (false)]
                public AccessibleObject AccessibilityObject {
                        get {
                                if (accessibilityObject == null) {
@@ -83,42 +86,69 @@ namespace System.Windows.Forms {
                }
 
                public int ColumnIndex {
-                       get { return columnIndex; }
+                       get { 
+                               if (DataGridView == null)
+                                       return -1;
+                               return columnIndex; 
+                       }
                }
 
+               [Browsable (false)]
                public Rectangle ContentBounds {
-                       get { return contentBounds; }
+                       get { 
+                               return GetContentBounds (RowIndex);
+                       }
                }
 
-               /*
+               [DefaultValue (null)]
                public virtual ContextMenuStrip ContextMenuStrip {
                        get { return contextMenuStrip; }
                        set { contextMenuStrip = value; }
                }
-               */
 
+               [Browsable (false)]
                public virtual object DefaultNewRowValue {
                        get { return defaultNewRowValue; }
                }
 
+               [Browsable (false)]
                public virtual bool Displayed {
                        get { return displayed; }
                }
 
+               [Browsable (false)]
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
                public object EditedFormattedValue {
-                       get { return editedFormattedValue; }
+                       get { 
+                               return GetEditedFormattedValue (RowIndex, DataGridViewDataErrorContexts.Formatting);
+                       }
                }
 
+               [Browsable (false)]
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
                public virtual Type EditType {
-                       get { return editType; }
+                       get {
+                               return typeof (DataGridViewTextBoxEditingControl);
+                       }
                }
 
+               [Browsable (false)]
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
                public Rectangle ErrorIconBounds {
-                       get { return errorIconBounds; }
+                       get {
+                               DataGridViewCellStyle style = InheritedStyle;
+                               return errorIconBounds; 
+                       }
                }
 
+               [Browsable (false)]
                public string ErrorText {
-                       get { return errorText; }
+                       get { 
+                               if (errorText == null)
+                                       return string.Empty;
+                                       
+                               return errorText; 
+                       }
                        set {
                                if (errorText != value) {
                                        errorText = value;
@@ -127,8 +157,12 @@ namespace System.Windows.Forms {
                        }
                }
 
+               [Browsable (false)]
                public object FormattedValue {
                        get {
+                               if (DataGridView == null)
+                                       return null;
+                                       
                                DataGridViewCellStyle style = InheritedStyle;
                                if (style.Format != String.Empty && FormattedValueType == typeof(string)) {
                                        return String.Format("{0:" + style.Format + "}", Value);
@@ -137,294 +171,106 @@ namespace System.Windows.Forms {
                        }
                }
 
+               [Browsable (false)]
                public virtual Type FormattedValueType {
                        get { return formattedValueType; }
                }
 
+               [Browsable (false)]
                public virtual bool Frozen {
                        get { return frozen; }
                }
 
+               [Browsable (false)]
                public bool HasStyle {
                        get { return style != null; }
                }
 
+               [Browsable (false)]
                public DataGridViewElementStates InheritedState {
-                       get { return inheritedState; }
+                       get { 
+                               return GetInheritedState (RowIndex);
+                       }
                }
 
+               [Browsable (false)]
                public DataGridViewCellStyle InheritedStyle {
                        get {
-                               DataGridViewCellStyle result = new DataGridViewCellStyle();
-                               if (style != null && style.Alignment != DataGridViewContentAlignment.NotSet) {
-                                       result.Alignment = style.Alignment;
-                               }
-                               else if (OwningRow != null && OwningRow.DefaultCellStyle.Alignment != DataGridViewContentAlignment.NotSet) {
-                                       result.Alignment = OwningRow.DefaultCellStyle.Alignment;
-                               }
-                               else if (DataGridView != null) {
-                                       if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.Alignment != DataGridViewContentAlignment.NotSet) {
-                                               result.Alignment = DataGridView.AlternatingRowsDefaultCellStyle.Alignment;
-                                       }
-                                       else if (DataGridView.RowsDefaultCellStyle.Alignment != DataGridViewContentAlignment.NotSet) {
-                                               result.Alignment = DataGridView.RowsDefaultCellStyle.Alignment;
-                                       }
-                                       else if (ColumnIndex >= 0 && DataGridView.Columns[ColumnIndex].DefaultCellStyle.Alignment != DataGridViewContentAlignment.NotSet) {
-                                               result.Alignment = DataGridView.Columns[ColumnIndex].DefaultCellStyle.Alignment;
-                                       }
-                                       else {
-                                               result.Alignment = DataGridView.DefaultCellStyle.Alignment;
-                                       }
-                               }
-                               if (style != null && style.BackColor != Color.Empty) {
-                                       result.BackColor = style.BackColor;
-                               }
-                               else if (OwningRow != null && OwningRow.DefaultCellStyle.BackColor != Color.Empty) {
-                                       result.BackColor = OwningRow.DefaultCellStyle.BackColor;
-                               }
-                               else if (DataGridView != null) {
-                                       if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.BackColor != Color.Empty) {
-                                               result.BackColor = DataGridView.AlternatingRowsDefaultCellStyle.BackColor;
-                                       }
-                                       else if (DataGridView.RowsDefaultCellStyle.BackColor != Color.Empty) {
-                                               result.BackColor = DataGridView.RowsDefaultCellStyle.BackColor;
-                                       }
-                                       else if (ColumnIndex >= 0 && DataGridView.Columns[ColumnIndex].DefaultCellStyle.BackColor != Color.Empty) {
-                                               result.BackColor = DataGridView.Columns[ColumnIndex].DefaultCellStyle.BackColor;
-                                       }
-                                       else {
-                                               result.BackColor = DataGridView.DefaultCellStyle.BackColor;
-                                       }
-                               }
-                               if (style != null && style.Font != null) {
-                                       result.Font = style.Font;
-                               }
-                               else if (OwningRow != null && OwningRow.DefaultCellStyle.Font != null) {
-                                       result.Font = OwningRow.DefaultCellStyle.Font;
-                               }
-                               else if (DataGridView != null) {
-                                       if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.Font != null) {
-                                               result.Font = DataGridView.AlternatingRowsDefaultCellStyle.Font;
-                                       }
-                                       else if (DataGridView.RowsDefaultCellStyle.Font != null) {
-                                               result.Font = DataGridView.RowsDefaultCellStyle.Font;
-                                       }
-                                       else if (ColumnIndex >= 0 && DataGridView.Columns[ColumnIndex].DefaultCellStyle.Font != null) {
-                                               result.Font = DataGridView.Columns[ColumnIndex].DefaultCellStyle.Font;
-                                       }
-                                       else {
-                                               result.Font = DataGridView.DefaultCellStyle.Font;
-                                       }
-                               }
-                               if (style != null && style.ForeColor != Color.Empty) {
-                                       result.ForeColor = style.ForeColor;
-                               }
-                               else if (OwningRow != null && OwningRow.DefaultCellStyle.ForeColor != Color.Empty) {
-                                       result.ForeColor = OwningRow.DefaultCellStyle.ForeColor;
-                               }
-                               else if (DataGridView != null) {
-                                       if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.ForeColor != Color.Empty) {
-                                               result.ForeColor = DataGridView.AlternatingRowsDefaultCellStyle.ForeColor;
-                                       }
-                                       else if (DataGridView.RowsDefaultCellStyle.ForeColor != Color.Empty) {
-                                               result.ForeColor = DataGridView.RowsDefaultCellStyle.ForeColor;
-                                       }
-                                       else if (ColumnIndex >= 0 && DataGridView.Columns[ColumnIndex].DefaultCellStyle.ForeColor != Color.Empty) {
-                                               result.ForeColor = DataGridView.Columns[ColumnIndex].DefaultCellStyle.ForeColor;
-                                       }
-                                       else {
-                                               result.ForeColor = DataGridView.DefaultCellStyle.ForeColor;
-                                       }
-                               }
-                               if (style != null && style.Format != String.Empty) {
-                                       result.Format = style.Format;
-                               }
-                               else if (OwningRow != null && OwningRow.DefaultCellStyle.Format != String.Empty) {
-                                       result.Format = OwningRow.DefaultCellStyle.Format;
-                               }
-                               else if (DataGridView != null) {
-                                       if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.Format != String.Empty) {
-                                               result.Format = DataGridView.AlternatingRowsDefaultCellStyle.Format;
-                                       }
-                                       else if (DataGridView.RowsDefaultCellStyle.Format != String.Empty) {
-                                               result.Format = DataGridView.RowsDefaultCellStyle.Format;
-                                       }
-                                       else if (ColumnIndex >= 0 && DataGridView.Columns[ColumnIndex].DefaultCellStyle.Format != String.Empty) {
-                                               result.Format = DataGridView.Columns[ColumnIndex].DefaultCellStyle.Format;
-                                       }
-                                       else {
-                                               result.Format = DataGridView.DefaultCellStyle.Format;
-                                       }
-                               }
-                               if (style != null && style.FormatProvider != System.Globalization.CultureInfo.CurrentUICulture) {
-                                       result.FormatProvider = style.FormatProvider;
-                               }
-                               else if (OwningRow != null && OwningRow.DefaultCellStyle.FormatProvider != System.Globalization.CultureInfo.CurrentUICulture) {
-                                       result.FormatProvider = OwningRow.DefaultCellStyle.FormatProvider;
-                               }
-                               else if (DataGridView != null) {
-                                       if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.FormatProvider != System.Globalization.CultureInfo.CurrentUICulture) {
-                                               result.FormatProvider = DataGridView.AlternatingRowsDefaultCellStyle.FormatProvider;
-                                       }
-                                       else if (DataGridView.RowsDefaultCellStyle.FormatProvider != System.Globalization.CultureInfo.CurrentUICulture) {
-                                               result.FormatProvider = DataGridView.RowsDefaultCellStyle.FormatProvider;
-                                       }
-                                       else if (ColumnIndex >= 0 && DataGridView.Columns[ColumnIndex].DefaultCellStyle.FormatProvider != System.Globalization.CultureInfo.CurrentUICulture) {
-                                               result.FormatProvider = DataGridView.Columns[ColumnIndex].DefaultCellStyle.FormatProvider;
-                                       }
-                                       else {
-                                               result.FormatProvider = DataGridView.DefaultCellStyle.FormatProvider;
-                                       }
-                               }
-                               if (style != null && (string) style.NullValue != "(null)") {
-                                       result.NullValue = style.NullValue;
-                               }
-                               else if (OwningRow != null && (string) OwningRow.DefaultCellStyle.NullValue != "(null)") {
-                                       result.NullValue = OwningRow.DefaultCellStyle.NullValue;
-                               }
-                               else if (DataGridView != null) {
-                                       if ((RowIndex % 2) == 1 && (string) DataGridView.AlternatingRowsDefaultCellStyle.NullValue != "(null)") {
-                                               result.NullValue = DataGridView.AlternatingRowsDefaultCellStyle.NullValue;
-                                       }
-                                       else if ((string) DataGridView.RowsDefaultCellStyle.NullValue != "(null)") {
-                                               result.NullValue = DataGridView.RowsDefaultCellStyle.NullValue;
-                                       }
-                                       else if (ColumnIndex >= 0 && (string) DataGridView.Columns[ColumnIndex].DefaultCellStyle.NullValue != "(null)") {
-                                               result.NullValue = DataGridView.Columns[ColumnIndex].DefaultCellStyle.NullValue;
-                                       }
-                                       else {
-                                               result.NullValue = DataGridView.DefaultCellStyle.NullValue;
-                                       }
-                               }
-                               if (style != null && style.Padding != Padding.Empty) {
-                                       result.Padding = style.Padding;
-                               }
-                               else if (OwningRow != null && OwningRow.DefaultCellStyle.Padding != Padding.Empty) {
-                                       result.Padding = OwningRow.DefaultCellStyle.Padding;
-                               }
-                               else if (DataGridView != null) {
-                                       if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.Padding != Padding.Empty) {
-                                               result.Padding = DataGridView.AlternatingRowsDefaultCellStyle.Padding;
-                                       }
-                                       else if (DataGridView.RowsDefaultCellStyle.Padding != Padding.Empty) {
-                                               result.Padding = DataGridView.RowsDefaultCellStyle.Padding;
-                                       }
-                                       else if (ColumnIndex >= 0 && DataGridView.Columns[ColumnIndex].DefaultCellStyle.Padding != Padding.Empty) {
-                                               result.Padding = DataGridView.Columns[ColumnIndex].DefaultCellStyle.Padding;
-                                       }
-                                       else {
-                                               result.Padding = DataGridView.DefaultCellStyle.Padding;
-                                       }
-                               }
-                               if (style != null && style.SelectionBackColor != Color.Empty) {
-                                       result.SelectionBackColor = style.SelectionBackColor;
-                               }
-                               else if (OwningRow != null && OwningRow.DefaultCellStyle.SelectionBackColor != Color.Empty) {
-                                       result.SelectionBackColor = OwningRow.DefaultCellStyle.SelectionBackColor;
-                               }
-                               else if (DataGridView != null) {
-                                       if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.SelectionBackColor != Color.Empty) {
-                                               result.SelectionBackColor = DataGridView.AlternatingRowsDefaultCellStyle.SelectionBackColor;
-                                       }
-                                       else if (DataGridView.RowsDefaultCellStyle.SelectionBackColor != Color.Empty) {
-                                               result.SelectionBackColor = DataGridView.RowsDefaultCellStyle.SelectionBackColor;
-                                       }
-                                       else if (ColumnIndex >= 0 && DataGridView.Columns[ColumnIndex].DefaultCellStyle.SelectionBackColor != Color.Empty) {
-                                               result.SelectionBackColor = DataGridView.Columns[ColumnIndex].DefaultCellStyle.SelectionBackColor;
-                                       }
-                                       else {
-                                               result.SelectionBackColor = DataGridView.DefaultCellStyle.SelectionBackColor;
-                                       }
-                               }
-                               if (style != null && style.SelectionForeColor != Color.Empty) {
-                                       result.SelectionForeColor = style.SelectionForeColor;
-                               }
-                               else if (OwningRow != null && OwningRow.DefaultCellStyle.SelectionForeColor != Color.Empty) {
-                                       result.SelectionForeColor = OwningRow.DefaultCellStyle.SelectionForeColor;
-                               }
-                               else if (DataGridView != null) {
-                                       if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.SelectionForeColor != Color.Empty) {
-                                               result.SelectionForeColor = DataGridView.AlternatingRowsDefaultCellStyle.SelectionForeColor;
-                                       }
-                                       else if (DataGridView.RowsDefaultCellStyle.SelectionForeColor != Color.Empty) {
-                                               result.SelectionForeColor = DataGridView.RowsDefaultCellStyle.SelectionForeColor;
-                                       }
-                                       else if (ColumnIndex >= 0 && DataGridView.Columns[ColumnIndex].DefaultCellStyle.SelectionForeColor != Color.Empty) {
-                                               result.SelectionForeColor = DataGridView.Columns[ColumnIndex].DefaultCellStyle.SelectionForeColor;
-                                       }
-                                       else {
-                                               result.SelectionForeColor = DataGridView.DefaultCellStyle.SelectionForeColor;
-                                       }
-                               }
-                               if (style != null && style.Tag != null) {
-                                       result.Tag = style.Tag;
-                               }
-                               else if (OwningRow != null && OwningRow.DefaultCellStyle.Tag != null) {
-                                       result.Tag = OwningRow.DefaultCellStyle.Tag;
-                               }
-                               else if (DataGridView != null) {
-                                       if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.Tag != null) {
-                                               result.Tag = DataGridView.AlternatingRowsDefaultCellStyle.Tag;
-                                       }
-                                       else if (DataGridView.RowsDefaultCellStyle.Tag != null) {
-                                               result.Tag = DataGridView.RowsDefaultCellStyle.Tag;
-                                       }
-                                       else if (ColumnIndex >= 0 && DataGridView.Columns[ColumnIndex].DefaultCellStyle.Tag != null) {
-                                               result.Tag = DataGridView.Columns[ColumnIndex].DefaultCellStyle.Tag;
-                                       }
-                                       else {
-                                               result.Tag = DataGridView.DefaultCellStyle.Tag;
-                                       }
-                               }
-                               if (style != null && style.WrapMode != DataGridViewTriState.NotSet) {
-                                       result.WrapMode = style.WrapMode;
-                               }
-                               else if (OwningRow != null && OwningRow.DefaultCellStyle.WrapMode != DataGridViewTriState.NotSet) {
-                                       result.WrapMode = OwningRow.DefaultCellStyle.WrapMode;
-                               }
-                               else if (DataGridView != null) {
-                                       if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.WrapMode != DataGridViewTriState.NotSet) {
-                                               result.WrapMode = DataGridView.AlternatingRowsDefaultCellStyle.WrapMode;
-                                       }
-                                       else if (DataGridView.RowsDefaultCellStyle.WrapMode != DataGridViewTriState.NotSet) {
-                                               result.WrapMode = DataGridView.RowsDefaultCellStyle.WrapMode;
-                                       }
-                                       else if (ColumnIndex >= 0 && DataGridView.Columns[ColumnIndex].DefaultCellStyle.WrapMode != DataGridViewTriState.NotSet) {
-                                               result.WrapMode = DataGridView.Columns[ColumnIndex].DefaultCellStyle.WrapMode;
-                                       }
-                                       else {
-                                               result.WrapMode = DataGridView.DefaultCellStyle.WrapMode;
-                                       }
-                               }
-                               return result;
+                               return GetInheritedStyle (null, RowIndex, true);
                        }
                }
 
+               [Browsable (false)]
                public bool IsInEditMode {
-                       get { return isInEditMode; }
+                       get {
+                               if (DataGridView == null)
+                                       return false;
+                                       
+                               if (RowIndex == -1)
+                                       throw new InvalidOperationException ("Operation cannot be performed on a cell of a shared row.");
+                                       
+                               return isInEditMode;
+                       }
                }
 
+               [Browsable (false)]
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
                public DataGridViewColumn OwningColumn {
                        get { return owningColumn; }
                }
 
+               [Browsable (false)]
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
                public DataGridViewRow OwningRow {
                        get { return owningRow; }
                }
 
+               [Browsable (false)]
                public Size PreferredSize {
-                       get { return preferredSize; }
+                       get { 
+                               if (DataGridView == null)
+                                       return Size.Empty;
+                                       
+                               return GetPreferredSize (Hwnd.bmp_g, InheritedStyle, RowIndex, Size.Empty); 
+                       }
                }
 
+               [Browsable (false)]
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public virtual bool ReadOnly {
-                       get { return readOnly; }
-                       set { readOnly = value; }
+                       get {
+                               if (DataGridView != null && DataGridView.ReadOnly)
+                                       return true;
+                               
+                               if (readOnly != DataGridViewTriState.NotSet)
+                                       return readOnly == DataGridViewTriState.True;
+                                       
+                               if (OwningRow != null && !OwningRow.IsShared && OwningRow.ReadOnly)
+                                       return true;
+                               
+                               if (OwningColumn != null && OwningColumn.ReadOnly)
+                                       return true;
+                                       
+                               return false;
+                       }
+                       set {
+                               readOnly = value ? DataGridViewTriState.True : DataGridViewTriState.False;
+                               if (value) {
+                                       SetState (DataGridViewElementStates.ReadOnly | State);
+                               } else {
+                                       SetState (~DataGridViewElementStates.ReadOnly & State);
+                               }
+                       }
                }
 
+               [Browsable (false)]
                public virtual bool Resizable {
-                       get { return resizable; }
+                       get {
+                               return resizable; 
+                       }
                }
 
+               [Browsable (false)]
                public int RowIndex {
                        get {
                                if (owningRow == null) {
@@ -434,8 +280,23 @@ namespace System.Windows.Forms {
                        }
                }
 
+               [Browsable (false)]
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public virtual bool Selected {
-                       get { return selected; }
+                       get {
+                               if (selected)
+                                       return true;
+                               
+                               if (DataGridView != null) {
+                                       if (RowIndex >= 0 && DataGridView.Rows [RowIndex].Selected)
+                                               return true;
+                                               
+                                       if (ColumnIndex >= 0 && DataGridView.Columns [ColumnIndex].Selected)
+                                               return true;
+                               }
+                               
+                               return false;
+                       }
                        set {
                                if (value != ((State & DataGridViewElementStates.Selected) != 0)) {
                                        SetState(State ^ DataGridViewElementStates.Selected);
@@ -444,13 +305,23 @@ namespace System.Windows.Forms {
                        }
                }
 
+               [Browsable (false)]
                public Size Size {
-                       get { return size; }
+                       get {
+                               if (DataGridView == null)
+                                       return Size.Empty;
+                                       
+                               if (RowIndex == -1)
+                                       throw new InvalidOperationException ("Getting the Size property of a cell in a shared row is not a valid operation.");
+                                       
+                               return GetSize (RowIndex);
+                       }
                }
 
+               [Browsable (true)]
                public DataGridViewCellStyle Style {
                        get {
-                               if (style != null) {
+                               if (style == null) {
                                        style = new DataGridViewCellStyle();
                                        style.StyleChanged += OnStyleChanged;
                                }
@@ -459,43 +330,69 @@ namespace System.Windows.Forms {
                        set { style = value; }
                }
 
+               [Bindable (true, BindingDirection.OneWay)]
+               [DefaultValue (null)]
+               [Localizable (false)]
+               [TypeConverter ("System.ComponentModel.StringConverter, " + Consts.AssemblySystem)]
                public object Tag {
                        get { return tag; }
                        set { tag = value; }
                }
 
+               [Browsable (false)]
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public string ToolTipText {
-                       get { return toolTipText; }
+                       get { return toolTipText == null ? string.Empty : toolTipText; }
                        set { toolTipText = value; }
                }
 
+               [Browsable (false)]
                public object Value {
-                       get { return valuex; }
+                       get {
+                               return GetValue (RowIndex);
+                       }
                        set {
-                               if (valuex != value) {
-                                       valuex = value;
-                                       RaiseCellValueChanged(new DataGridViewCellEventArgs(ColumnIndex, RowIndex));
-                               }
+                               SetValue (RowIndex, value);
                        }
                }
 
+               [Browsable (false)]
                public virtual Type ValueType {
                        get { return valueType; }
                        set { valueType = value; }
                }
 
+               [Browsable (false)]
                public virtual bool Visible {
-                       get { return visible; }
+                       get {
+                               // This is independent from State...
+                               DataGridViewColumn col = OwningColumn;
+                               DataGridViewRow row = OwningRow;
+                               
+                               bool rowVisible = true, colVisible = true;
+                               
+                               if (row == null && col == null)
+                                       return false;
+                               
+                               if (row != null) {
+                                       rowVisible = !row.IsShared && row.Visible;
+                               }
+                               
+                               if (col != null) {
+                                       colVisible = col.Index >= 0 && col.Visible;
+                               }
+                               
+                               return rowVisible && colVisible;
+                       }
                }
 
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
                public virtual DataGridViewAdvancedBorderStyle AdjustCellBorderStyle (DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStyleInput,     DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceholder, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow) {
                        return dataGridViewAdvancedBorderStyleInput;
                }
 
                public virtual object Clone () {
-                       return this.MemberwiseClone();
-                       /*
-                       DataGridViewCell result = null; // = new DataGridViewCell();
+                       DataGridViewCell result = (DataGridViewCell) Activator.CreateInstance (GetType ());
                        result.accessibilityObject = this.accessibilityObject;
                        result.columnIndex = this.columnIndex;
                        result.contentBounds = this.contentBounds;
@@ -503,14 +400,11 @@ namespace System.Windows.Forms {
                        result.defaultNewRowValue = this.defaultNewRowValue;
                        result.displayed = this.displayed;
                        result.editedFormattedValue = this.editedFormattedValue;
-                       result.editType = this.editType;
                        result.errorIconBounds = this.errorIconBounds;
                        result.errorText = this.errorText;
                        result.formattedValueType = this.formattedValueType;
                        result.frozen = this.frozen;
-                       result.hasStyle = this.hasStyle;
                        result.inheritedState = this.inheritedState;
-                       result.inheritedStyle = this.inheritedStyle;
                        result.isInEditMode = this.isInEditMode;
                        result.owningColumn = this.owningColumn;
                        result.owningRow = this.owningRow;
@@ -526,9 +420,9 @@ namespace System.Windows.Forms {
                        result.valueType = this.valueType;
                        result.visible = this.visible;
                        return result;
-                       */
                }
 
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
                public virtual void DetachEditingControl () {
                }
 
@@ -537,20 +431,94 @@ namespace System.Windows.Forms {
                }
 
                public Rectangle GetContentBounds (int rowIndex) {
-                       throw new NotImplementedException();
+                       if (DataGridView == null)
+                               return Rectangle.Empty;
+                       
+                       return GetContentBounds (Hwnd.bmp_g, InheritedStyle, rowIndex);
                }
 
                public object GetEditedFormattedValue (int rowIndex, DataGridViewDataErrorContexts context) {
-                       throw new NotImplementedException();
+                       if (DataGridView == null)
+                               return null;
+                       
+                       if (rowIndex < 0 || rowIndex >= DataGridView.RowCount)
+                               throw new ArgumentOutOfRangeException ("rowIndex", "Specified argument was out of the range of valid values.");
+                       
+                       if (IsInEditMode) {
+                               IDataGridViewEditingControl ctrl = DataGridView.EditingControl as IDataGridViewEditingControl;
+                               return ctrl.GetEditingControlFormattedValue (context);
+                       }
+                       
+                       DataGridViewCellStyle style = InheritedStyle;
+                       
+                       return GetFormattedValue (GetValue (rowIndex), rowIndex, ref style, null, null, context);
                }
 
-               /*
-               public virtual ContextMenuStrip GetInheritedContextMenuStrip (int rowIndex) {
+               public virtual ContextMenuStrip GetInheritedContextMenuStrip (int rowIndex)
+               {
+                       throw new NotImplementedException();
                }
-               */
 
                public virtual DataGridViewElementStates GetInheritedState (int rowIndex) {
-                       throw new NotImplementedException();
+               
+                       if (DataGridView == null && rowIndex != -1)
+                               throw new ArgumentException ("msg?");
+                       
+                       if (DataGridView != null && (rowIndex < 0 || rowIndex >= DataGridView.Rows.Count))
+                               throw new ArgumentOutOfRangeException ("rowIndex", "Specified argument was out of the range of valid values.");
+               
+                       DataGridViewElementStates result;
+                       
+                       result = DataGridViewElementStates.ResizableSet | State;
+                       
+                       DataGridViewColumn col = OwningColumn;
+                       DataGridViewRow row = OwningRow;
+
+                       if (DataGridView == null) {
+                               if (row != null) {
+                                       if (row.Resizable == DataGridViewTriState.True)
+                                               result |= DataGridViewElementStates.Resizable;
+                                               
+                                       if (row.Visible)
+                                               result |= DataGridViewElementStates.Visible;
+                                               
+                                       if (row.ReadOnly)
+                                               result |= DataGridViewElementStates.ReadOnly;
+                                               
+                                       if (row.Frozen)
+                                               result |= DataGridViewElementStates.Frozen;
+                                               
+                                       if (row.Displayed)
+                                               result |= DataGridViewElementStates.Displayed;
+                                               
+                                       /*if (row.Selected)
+                                               result |= DataGridViewElementStates.Selected;*/
+                               }
+                               
+                               return result;
+                       }
+                       
+                       if (col != null) {
+                               if (col.Resizable == DataGridViewTriState.True && row.Resizable == DataGridViewTriState.True)
+                                       result |= DataGridViewElementStates.Resizable;
+                               
+                               if (col.Visible && row.Visible)
+                                       result |= DataGridViewElementStates.Visible;
+
+                               if (col.ReadOnly || row.ReadOnly)
+                                       result |= DataGridViewElementStates.ReadOnly;
+
+                               if (col.Frozen || row.Frozen)
+                                       result |= DataGridViewElementStates.Frozen;
+
+                               if (col.Displayed && row.Displayed)
+                                       result |= DataGridViewElementStates.Displayed;
+
+                               if (col.Selected || row.Selected)
+                                       result |= DataGridViewElementStates.Selected;
+                       }
+                       
+                       return result;
                }
 
                public virtual DataGridViewCellStyle GetInheritedStyle (DataGridViewCellStyle inheritedCellStyle, int rowIndex, bool includeColors) {
@@ -558,9 +526,198 @@ namespace System.Windows.Forms {
                         * System.InvalidOperationException :: The cell has no associated System.Windows.Forms.DataGridView, or the cell's System.Windows.Forms.DataGridViewCell.ColumnIndex is less than 0.
                         * System.ArgumentOutOfRangeException :: rowIndex is less than 0, or greater than or equal to the number of rows in the parent System.Windows.Forms.DataGridView.
                         * */
-                       throw new NotImplementedException();
+       
+                       if (DataGridView == null)
+                               throw new InvalidOperationException ("Cell is not in a DataGridView. The cell cannot retrieve the inherited cell style.");
+
+                       if (rowIndex < 0 || rowIndex >= DataGridView.Rows.Count)
+                               throw new ArgumentOutOfRangeException ("rowIndex", "Specified argument was out of the range of valid values.");
+
+                       DataGridViewCellStyle result = new DataGridViewCellStyle ();
+                       if (style != null && style.Alignment != DataGridViewContentAlignment.NotSet) {
+                               result.Alignment = style.Alignment;
+                       } else if (OwningRow != null && OwningRow.DefaultCellStyle.Alignment != DataGridViewContentAlignment.NotSet) {
+                               result.Alignment = OwningRow.DefaultCellStyle.Alignment;
+                       } else if (DataGridView != null) {
+                               if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.Alignment != DataGridViewContentAlignment.NotSet) {
+                                       result.Alignment = DataGridView.AlternatingRowsDefaultCellStyle.Alignment;
+                               } else if (DataGridView.RowsDefaultCellStyle.Alignment != DataGridViewContentAlignment.NotSet) {
+                                       result.Alignment = DataGridView.RowsDefaultCellStyle.Alignment;
+                               } else if (ColumnIndex >= 0 && DataGridView.Columns [ColumnIndex].DefaultCellStyle.Alignment != DataGridViewContentAlignment.NotSet) {
+                                       result.Alignment = DataGridView.Columns [ColumnIndex].DefaultCellStyle.Alignment;
+                               } else {
+                                       result.Alignment = DataGridView.DefaultCellStyle.Alignment;
+                               }
+                       }
+                       if (style != null && style.BackColor != Color.Empty) {
+                               result.BackColor = style.BackColor;
+                       } else if (OwningRow != null && OwningRow.DefaultCellStyle.BackColor != Color.Empty) {
+                               result.BackColor = OwningRow.DefaultCellStyle.BackColor;
+                       } else if (DataGridView != null) {
+                               if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.BackColor != Color.Empty) {
+                                       result.BackColor = DataGridView.AlternatingRowsDefaultCellStyle.BackColor;
+                               } else if (DataGridView.RowsDefaultCellStyle.BackColor != Color.Empty) {
+                                       result.BackColor = DataGridView.RowsDefaultCellStyle.BackColor;
+                               } else if (ColumnIndex >= 0 && DataGridView.Columns [ColumnIndex].DefaultCellStyle.BackColor != Color.Empty) {
+                                       result.BackColor = DataGridView.Columns [ColumnIndex].DefaultCellStyle.BackColor;
+                               } else {
+                                       result.BackColor = DataGridView.DefaultCellStyle.BackColor;
+                               }
+                       }
+                       if (style != null && style.Font != null) {
+                               result.Font = style.Font;
+                       } else if (OwningRow != null && OwningRow.DefaultCellStyle.Font != null) {
+                               result.Font = OwningRow.DefaultCellStyle.Font;
+                       } else if (DataGridView != null) {
+                               if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.Font != null) {
+                                       result.Font = DataGridView.AlternatingRowsDefaultCellStyle.Font;
+                               } else if (DataGridView.RowsDefaultCellStyle.Font != null) {
+                                       result.Font = DataGridView.RowsDefaultCellStyle.Font;
+                               } else if (ColumnIndex >= 0 && DataGridView.Columns [ColumnIndex].DefaultCellStyle.Font != null) {
+                                       result.Font = DataGridView.Columns [ColumnIndex].DefaultCellStyle.Font;
+                               } else {
+                                       result.Font = DataGridView.DefaultCellStyle.Font;
+                               }
+                       }
+                       if (style != null && style.ForeColor != Color.Empty) {
+                               result.ForeColor = style.ForeColor;
+                       } else if (OwningRow != null && OwningRow.DefaultCellStyle.ForeColor != Color.Empty) {
+                               result.ForeColor = OwningRow.DefaultCellStyle.ForeColor;
+                       } else if (DataGridView != null) {
+                               if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.ForeColor != Color.Empty) {
+                                       result.ForeColor = DataGridView.AlternatingRowsDefaultCellStyle.ForeColor;
+                               } else if (DataGridView.RowsDefaultCellStyle.ForeColor != Color.Empty) {
+                                       result.ForeColor = DataGridView.RowsDefaultCellStyle.ForeColor;
+                               } else if (ColumnIndex >= 0 && DataGridView.Columns [ColumnIndex].DefaultCellStyle.ForeColor != Color.Empty) {
+                                       result.ForeColor = DataGridView.Columns [ColumnIndex].DefaultCellStyle.ForeColor;
+                               } else {
+                                       result.ForeColor = DataGridView.DefaultCellStyle.ForeColor;
+                               }
+                       }
+                       if (style != null && style.Format != String.Empty) {
+                               result.Format = style.Format;
+                       } else if (OwningRow != null && OwningRow.DefaultCellStyle.Format != String.Empty) {
+                               result.Format = OwningRow.DefaultCellStyle.Format;
+                       } else if (DataGridView != null) {
+                               if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.Format != String.Empty) {
+                                       result.Format = DataGridView.AlternatingRowsDefaultCellStyle.Format;
+                               } else if (DataGridView.RowsDefaultCellStyle.Format != String.Empty) {
+                                       result.Format = DataGridView.RowsDefaultCellStyle.Format;
+                               } else if (ColumnIndex >= 0 && DataGridView.Columns [ColumnIndex].DefaultCellStyle.Format != String.Empty) {
+                                       result.Format = DataGridView.Columns [ColumnIndex].DefaultCellStyle.Format;
+                               } else {
+                                       result.Format = DataGridView.DefaultCellStyle.Format;
+                               }
+                       }
+                       if (style != null && style.FormatProvider != System.Globalization.CultureInfo.CurrentUICulture) {
+                               result.FormatProvider = style.FormatProvider;
+                       } else if (OwningRow != null && OwningRow.DefaultCellStyle.FormatProvider != System.Globalization.CultureInfo.CurrentUICulture) {
+                               result.FormatProvider = OwningRow.DefaultCellStyle.FormatProvider;
+                       } else if (DataGridView != null) {
+                               if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.FormatProvider != System.Globalization.CultureInfo.CurrentUICulture) {
+                                       result.FormatProvider = DataGridView.AlternatingRowsDefaultCellStyle.FormatProvider;
+                               } else if (DataGridView.RowsDefaultCellStyle.FormatProvider != System.Globalization.CultureInfo.CurrentUICulture) {
+                                       result.FormatProvider = DataGridView.RowsDefaultCellStyle.FormatProvider;
+                               } else if (ColumnIndex >= 0 && DataGridView.Columns [ColumnIndex].DefaultCellStyle.FormatProvider != System.Globalization.CultureInfo.CurrentUICulture) {
+                                       result.FormatProvider = DataGridView.Columns [ColumnIndex].DefaultCellStyle.FormatProvider;
+                               } else {
+                                       result.FormatProvider = DataGridView.DefaultCellStyle.FormatProvider;
+                               }
+                       }
+                       if (style != null && (string)style.NullValue != "(null)") {
+                               result.NullValue = style.NullValue;
+                       } else if (OwningRow != null && (string)OwningRow.DefaultCellStyle.NullValue != "(null)") {
+                               result.NullValue = OwningRow.DefaultCellStyle.NullValue;
+                       } else if (DataGridView != null) {
+                               if ((RowIndex % 2) == 1 && (string)DataGridView.AlternatingRowsDefaultCellStyle.NullValue != "(null)") {
+                                       result.NullValue = DataGridView.AlternatingRowsDefaultCellStyle.NullValue;
+                               } else if ((string)DataGridView.RowsDefaultCellStyle.NullValue != "(null)") {
+                                       result.NullValue = DataGridView.RowsDefaultCellStyle.NullValue;
+                               } else if (ColumnIndex >= 0 && (string)DataGridView.Columns [ColumnIndex].DefaultCellStyle.NullValue != "(null)") {
+                                       result.NullValue = DataGridView.Columns [ColumnIndex].DefaultCellStyle.NullValue;
+                               } else {
+                                       result.NullValue = DataGridView.DefaultCellStyle.NullValue;
+                               }
+                       }
+                       if (style != null && style.Padding != Padding.Empty) {
+                               result.Padding = style.Padding;
+                       } else if (OwningRow != null && OwningRow.DefaultCellStyle.Padding != Padding.Empty) {
+                               result.Padding = OwningRow.DefaultCellStyle.Padding;
+                       } else if (DataGridView != null) {
+                               if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.Padding != Padding.Empty) {
+                                       result.Padding = DataGridView.AlternatingRowsDefaultCellStyle.Padding;
+                               } else if (DataGridView.RowsDefaultCellStyle.Padding != Padding.Empty) {
+                                       result.Padding = DataGridView.RowsDefaultCellStyle.Padding;
+                               } else if (ColumnIndex >= 0 && DataGridView.Columns [ColumnIndex].DefaultCellStyle.Padding != Padding.Empty) {
+                                       result.Padding = DataGridView.Columns [ColumnIndex].DefaultCellStyle.Padding;
+                               } else {
+                                       result.Padding = DataGridView.DefaultCellStyle.Padding;
+                               }
+                       }
+                       if (style != null && style.SelectionBackColor != Color.Empty) {
+                               result.SelectionBackColor = style.SelectionBackColor;
+                       } else if (OwningRow != null && OwningRow.DefaultCellStyle.SelectionBackColor != Color.Empty) {
+                               result.SelectionBackColor = OwningRow.DefaultCellStyle.SelectionBackColor;
+                       } else if (DataGridView != null) {
+                               if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.SelectionBackColor != Color.Empty) {
+                                       result.SelectionBackColor = DataGridView.AlternatingRowsDefaultCellStyle.SelectionBackColor;
+                               } else if (DataGridView.RowsDefaultCellStyle.SelectionBackColor != Color.Empty) {
+                                       result.SelectionBackColor = DataGridView.RowsDefaultCellStyle.SelectionBackColor;
+                               } else if (ColumnIndex >= 0 && DataGridView.Columns [ColumnIndex].DefaultCellStyle.SelectionBackColor != Color.Empty) {
+                                       result.SelectionBackColor = DataGridView.Columns [ColumnIndex].DefaultCellStyle.SelectionBackColor;
+                               } else {
+                                       result.SelectionBackColor = DataGridView.DefaultCellStyle.SelectionBackColor;
+                               }
+                       }
+                       if (style != null && style.SelectionForeColor != Color.Empty) {
+                               result.SelectionForeColor = style.SelectionForeColor;
+                       } else if (OwningRow != null && OwningRow.DefaultCellStyle.SelectionForeColor != Color.Empty) {
+                               result.SelectionForeColor = OwningRow.DefaultCellStyle.SelectionForeColor;
+                       } else if (DataGridView != null) {
+                               if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.SelectionForeColor != Color.Empty) {
+                                       result.SelectionForeColor = DataGridView.AlternatingRowsDefaultCellStyle.SelectionForeColor;
+                               } else if (DataGridView.RowsDefaultCellStyle.SelectionForeColor != Color.Empty) {
+                                       result.SelectionForeColor = DataGridView.RowsDefaultCellStyle.SelectionForeColor;
+                               } else if (ColumnIndex >= 0 && DataGridView.Columns [ColumnIndex].DefaultCellStyle.SelectionForeColor != Color.Empty) {
+                                       result.SelectionForeColor = DataGridView.Columns [ColumnIndex].DefaultCellStyle.SelectionForeColor;
+                               } else {
+                                       result.SelectionForeColor = DataGridView.DefaultCellStyle.SelectionForeColor;
+                               }
+                       }
+                       if (style != null && style.Tag != null) {
+                               result.Tag = style.Tag;
+                       } else if (OwningRow != null && OwningRow.DefaultCellStyle.Tag != null) {
+                               result.Tag = OwningRow.DefaultCellStyle.Tag;
+                       } else if (DataGridView != null) {
+                               if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.Tag != null) {
+                                       result.Tag = DataGridView.AlternatingRowsDefaultCellStyle.Tag;
+                               } else if (DataGridView.RowsDefaultCellStyle.Tag != null) {
+                                       result.Tag = DataGridView.RowsDefaultCellStyle.Tag;
+                               } else if (ColumnIndex >= 0 && DataGridView.Columns [ColumnIndex].DefaultCellStyle.Tag != null) {
+                                       result.Tag = DataGridView.Columns [ColumnIndex].DefaultCellStyle.Tag;
+                               } else {
+                                       result.Tag = DataGridView.DefaultCellStyle.Tag;
+                               }
+                       }
+                       if (style != null && style.WrapMode != DataGridViewTriState.NotSet) {
+                               result.WrapMode = style.WrapMode;
+                       } else if (OwningRow != null && OwningRow.DefaultCellStyle.WrapMode != DataGridViewTriState.NotSet) {
+                               result.WrapMode = OwningRow.DefaultCellStyle.WrapMode;
+                       } else if (DataGridView != null) {
+                               if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.WrapMode != DataGridViewTriState.NotSet) {
+                                       result.WrapMode = DataGridView.AlternatingRowsDefaultCellStyle.WrapMode;
+                               } else if (DataGridView.RowsDefaultCellStyle.WrapMode != DataGridViewTriState.NotSet) {
+                                       result.WrapMode = DataGridView.RowsDefaultCellStyle.WrapMode;
+                               } else if (ColumnIndex >= 0 && DataGridView.Columns [ColumnIndex].DefaultCellStyle.WrapMode != DataGridViewTriState.NotSet) {
+                                       result.WrapMode = DataGridView.Columns [ColumnIndex].DefaultCellStyle.WrapMode;
+                               } else {
+                                       result.WrapMode = DataGridView.DefaultCellStyle.WrapMode;
+                               }
+                       }
+                       return result;
                }
 
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
                public virtual void InitializeEditingControl (int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle) {
                        if (DataGridView == null || DataGridView.EditingControl == null) {
                                throw new InvalidOperationException("No editing control defined");
@@ -571,6 +728,7 @@ namespace System.Windows.Forms {
                        throw new NotImplementedException();
                }
 
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
                public static int MeasureTextHeight (Graphics graphics, string text, Font font, int maxWidth, TextFormatFlags flags) {
                        if (graphics == null) {
                                throw new ArgumentNullException("Graphics argument null");
@@ -585,10 +743,12 @@ namespace System.Windows.Forms {
                        throw new NotImplementedException();
                }
 
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
                public static int MeasureTextHeight (Graphics graphics, string text, Font font, int maxWidth, TextFormatFlags flags, out bool widthTruncated) {
                        throw new NotImplementedException();
                }
 
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
                public static Size MeasureTextPreferredSize (Graphics graphics, string text, Font font, float maxRatio, TextFormatFlags flags) {
                        if (graphics == null) {
                                throw new ArgumentNullException("Graphics argument null");
@@ -602,11 +762,13 @@ namespace System.Windows.Forms {
                        throw new NotImplementedException();
                }
 
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
                public static Size MeasureTextSize (Graphics graphics, string text, Font font, TextFormatFlags flags) {
                        /////////////////////////// Â¿flags?
                        return graphics.MeasureString(text, font).ToSize();
                }
 
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
                public static int MeasureTextWidth (Graphics graphics, string text, Font font, int maxHeight, TextFormatFlags flags) {
                        if (graphics == null) {
                                throw new ArgumentNullException("Graphics argument null");
@@ -635,10 +797,17 @@ namespace System.Windows.Forms {
                        return null;
                }
 
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
                public virtual void PositionEditingControl (bool setLocation, bool setSize, Rectangle cellBounds, Rectangle cellClip, DataGridViewCellStyle cellStyle, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow) {
-                       throw new NotImplementedException();
+                       //throw new NotImplementedException();
+                       if (setLocation)
+                               DataGridView.EditingControl.Location = cellBounds.Location;
+                               
+                       if (setSize)
+                               DataGridView.EditingControl.Size = cellBounds.Size;
                }
 
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
                public virtual Rectangle PositionEditingPanel (Rectangle cellBounds, Rectangle cellClip, DataGridViewCellStyle cellStyle, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow) {
                        throw new NotImplementedException();
                }
@@ -647,19 +816,23 @@ namespace System.Windows.Forms {
                        return String.Format("{0} {RowIndex = {1}, ColumnIndex = {2}}", this.GetType().FullName, RowIndex, columnIndex);
                }
 
-               protected virtual Rectangle BorderWidths (DataGridViewAdvancedBorderStyle advancedBorderStyle) {
-                       throw new NotImplementedException();
+               protected virtual Rectangle BorderWidths (DataGridViewAdvancedBorderStyle advancedBorderStyle)
+               {
+                       return new Rectangle (2, 2, 2, 2);
                }
 
-               protected virtual bool ClickUnsharesRow (DataGridViewCellEventArgs e) {
+               protected virtual bool ClickUnsharesRow (DataGridViewCellEventArgs e)
+               {
                        throw new NotImplementedException();
                }
 
-               protected virtual bool ContentClickUnsharesRow (DataGridViewCellEventArgs e) {
+               protected virtual bool ContentClickUnsharesRow (DataGridViewCellEventArgs e)
+               {
                        throw new NotImplementedException();
                }
 
-               protected virtual bool ContentDoubleClickUnsharesRow (DataGridViewCellEventArgs e) {
+               protected virtual bool ContentDoubleClickUnsharesRow (DataGridViewCellEventArgs e)
+               {
                        throw new NotImplementedException();
                }
 
@@ -674,16 +847,70 @@ namespace System.Windows.Forms {
                        throw new NotImplementedException();
                }
 
-               protected virtual bool EnterUnsharesRow (int rowIndex) {
+               protected virtual bool EnterUnsharesRow (int rowIndex, bool throughMouseClick) {
                        throw new NotImplementedException();
                }
 
                protected virtual object GetClipboardContent (int rowIndex, bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string format) {
-                       throw new NotImplementedException();
+                       if (DataGridView == null)
+                               return null;
+                               
+                       if (rowIndex < 0 || rowIndex >= DataGridView.RowCount)
+                               throw new ArgumentOutOfRangeException ("rowIndex", "Specified argument was out of the range of valid values.");
+                       
+                       string value = null;
+                       
+                       if (Selected) {
+                               DataGridViewCellStyle style = GetInheritedStyle (null, rowIndex, false);
+                               value = GetEditedFormattedValue (rowIndex, DataGridViewDataErrorContexts.ClipboardContent | DataGridViewDataErrorContexts.Formatting) as string;
+                       }
+
+                       if (value == null)
+                               value = string.Empty;
+                               
+                       string table_prefix = string.Empty, cell_prefix = string.Empty, row_prefix = string.Empty;
+                       string table_suffix = string.Empty, cell_suffix = string.Empty, row_suffix = string.Empty;
+                       
+                       if (format == DataFormats.UnicodeText || format == DataFormats.Text) {
+                               if (lastCell && !inLastRow)
+                                       cell_suffix = Environment.NewLine;
+                               else if (!lastCell)
+                                       cell_suffix = "\t";
+                       } else if (format == DataFormats.CommaSeparatedValue) {
+                               if (lastCell && !inLastRow)
+                                       cell_suffix = Environment.NewLine;
+                               else if (!lastCell)
+                                       cell_suffix = ",";
+                       } else if (format == DataFormats.Html) {
+                               if (inFirstRow && firstCell)
+                                       table_prefix = "<TABLE>";
+                               if (inLastRow && lastCell)
+                                       table_suffix = "</TABLE>";
+                               if (firstCell)
+                                       row_prefix = "<TR>";
+                               if (lastCell)
+                                       row_suffix = "</TR>";
+                               cell_prefix = "<TD>";
+                               cell_suffix = "</TD>";
+                               
+                               if (!Selected) {
+                                       value = "&nbsp;";
+                               }
+                       } else {
+                               return value;
+                       }
+                                               
+                       value = table_prefix + row_prefix + cell_prefix + value + cell_suffix + row_suffix + table_suffix;
+                       
+                       return value;
+               }
+               
+               internal object GetClipboardContentInternal (int rowIndex, bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string format) {
+                       return GetClipboardContent (rowIndex, firstCell, lastCell, inFirstRow, inLastRow, format);
                }
 
                protected virtual Rectangle GetContentBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex) {
-                       throw new NotImplementedException();
+                       return Rectangle.Empty;
                }
 
                protected virtual Rectangle GetErrorIconBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex) {
@@ -694,8 +921,38 @@ namespace System.Windows.Forms {
                        throw new NotImplementedException();
                }
 
-               protected virtual object GetFormattedValue (object value, int rowIndex, ref DataGridViewCellStyle cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context) {
-                       throw new NotImplementedException();
+               protected virtual object GetFormattedValue (object value, int rowIndex, ref DataGridViewCellStyle cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context)
+               {
+                       if (DataGridView == null)
+                               return null;
+                               
+                       if (rowIndex < 0 || rowIndex >= DataGridView.RowCount)
+                               throw new ArgumentOutOfRangeException ("rowIndex");
+                               
+                       DataGridViewCellFormattingEventArgs e = new DataGridViewCellFormattingEventArgs (ColumnIndex, rowIndex, value, FormattedValueType, cellStyle);
+                       
+                       DataGridView.OnCellFormattingInternal (e);
+                       
+                       if (e.FormattingApplied) {
+                               return e.Value;
+                       }
+                       
+                       if (valueTypeConverter != null) {
+                               return valueTypeConverter.ConvertTo (value, FormattedValueType);
+                       }
+                       
+                       if (formattedValueTypeConverter != null) {
+                               return formattedValueTypeConverter.ConvertFrom (value);
+                       }
+                       
+                       IFormattable formattable = value as IFormattable;
+                       if (formattable != null) {
+                               formattable.ToString (style.Format, style.FormatProvider);
+                       }
+                       
+                       // Now what?
+                       
+                       return value;
                }
 
                protected virtual Size GetPreferredSize (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize) {
@@ -703,11 +960,16 @@ namespace System.Windows.Forms {
                }
 
                protected virtual Size GetSize (int rowIndex) {
+                       DataGridViewCellStyle style = InheritedStyle;
                        throw new NotImplementedException();
                }
 
                protected virtual object GetValue (int rowIndex) {
-                       throw new NotImplementedException();
+                       
+                       if (DataGridView != null && (RowIndex < 0 || RowIndex >= DataGridView.Rows.Count))
+                               throw new ArgumentOutOfRangeException ("rowIndex", "Specified argument was out of the range of valid values.");
+                               
+                       return valuex;
                }
 
                protected virtual bool KeyDownUnsharesRow (KeyEventArgs e, int rowIndex) {
@@ -722,7 +984,7 @@ namespace System.Windows.Forms {
                        throw new NotImplementedException();
                }
 
-               protected virtual bool LeaveUnsharesRow ( int rowIndex) {
+               protected virtual bool LeaveUnsharesRow (int rowIndex, bool throughMouseClick) {
                        throw new NotImplementedException();
                }
 
@@ -757,54 +1019,122 @@ namespace System.Windows.Forms {
                protected virtual void OnClick (DataGridViewCellEventArgs e) {
                }
 
+               internal void OnClickInternal (DataGridViewCellEventArgs e) {
+                       OnClick (e);
+               }
+
                protected virtual void OnContentClick (DataGridViewCellEventArgs e) {
                }
+               
+               internal void OnContentClickInternal (DataGridViewCellEventArgs e) {
+                       OnContentClick (e);
+               }
 
                protected virtual void OnContentDoubleClick (DataGridViewCellEventArgs e) {
                }
+               
+               internal void OnContentDoubleClickInternal (DataGridViewCellEventArgs e) {
+                       OnContentDoubleClick (e);
+               }
 
                protected override void OnDataGridViewChanged () {
                }
+               
+               internal void OnDataGridViewChangedInternal () {
+                       OnDataGridViewChanged ();
+               }
 
                protected virtual void OnDoubleClick (DataGridViewCellEventArgs e) {
                }
 
+               internal void OnDoubleClickInternal (DataGridViewCellEventArgs e) {
+                       OnDoubleClick (e);
+               }
+               
                protected virtual void OnEnter (int rowIndex, bool throughMouseClick) {
                }
 
+               internal void OnEnterInternal (int rowIndex, bool throughMouseClick) {
+                       OnEnter (rowIndex, throughMouseClick);
+               }
+
                protected virtual void OnKeyDown (KeyEventArgs e, int rowIndex) {
                }
 
+               internal void OnKeyDownInternal (KeyEventArgs e, int rowIndex) {
+                       OnKeyDown (e, rowIndex);
+               }
+
                protected virtual void OnKeyPress (KeyPressEventArgs e, int rowIndex) {
                }
 
+               internal void OnKeyPressInternal (KeyPressEventArgs e, int rowIndex) {
+                       OnKeyPress (e, rowIndex);
+               }
+
                protected virtual void OnKeyUp (KeyEventArgs e, int rowIndex) {
                }
+               
+               internal void OnKeyUpInternal (KeyEventArgs e, int rowIndex) {
+                       OnKeyUp (e, rowIndex);
+               }
 
                protected virtual void OnLeave (int rowIndex, bool throughMouseClick) {
                }
+               
+               internal void OnLeaveInternal (int rowIndex, bool throughMouseClick) {
+                       OnLeave (rowIndex, throughMouseClick);
+               }
 
                protected virtual void OnMouseClick (DataGridViewCellMouseEventArgs e) {
                }
 
+               internal void OnMouseClickInternal (DataGridViewCellMouseEventArgs e) {
+                       OnMouseClick (e);
+               }
+
                protected virtual void OnMouseDoubleClick (DataGridViewCellMouseEventArgs e) {
                }
+               
+               internal void OnMouseDoubleClickInternal (DataGridViewCellMouseEventArgs e) {
+                       OnMouseDoubleClick (e);
+               }
 
                protected virtual void OnMouseDown (DataGridViewCellMouseEventArgs e) {
                }
 
+               internal void OnMouseDownInternal (DataGridViewCellMouseEventArgs e) {
+                       OnMouseDown (e);
+               }
+
                protected virtual void OnMouseEnter (int rowIndex) {
                }
+               
+               internal void OnMouseEnterInternal (int rowIndex) {
+                       OnMouseEnter (rowIndex) ;
+               }
 
                protected virtual void OnMouseLeave (int rowIndex) {
                }
 
+               internal void OnMouseLeaveInternal (int e) {
+                       OnMouseLeave (e);
+               }
+               
                protected virtual void OnMouseMove (DataGridViewCellMouseEventArgs e) {
                }
+               
+               internal void OnMouseMoveInternal (DataGridViewCellMouseEventArgs e) {
+                       OnMouseMove (e);
+               }
 
                protected virtual void OnMouseUp (DataGridViewCellMouseEventArgs e) {
                }
 
+               internal void OnMouseUpInternal (DataGridViewCellMouseEventArgs e) {
+                       OnMouseUp (e);
+               }
+               
                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) {
                        throw new NotImplementedException();
                }
@@ -902,7 +1232,12 @@ namespace System.Windows.Forms {
                }
 
                protected virtual bool SetValue (int rowIndex, object value) {
-                       throw new NotImplementedException();
+                       if (valuex != value) {
+                               valuex = value;
+                               RaiseCellValueChanged (new DataGridViewCellEventArgs (ColumnIndex, RowIndex));
+                               return true;
+                       }
+                       return false;
                }
 
                private void OnStyleChanged (object sender, EventArgs args) {
@@ -918,6 +1253,10 @@ namespace System.Windows.Forms {
                internal void SetOwningRow (DataGridViewRow row) {
                        owningRow = row;
                }
+               
+               internal void SetOwningColumn (DataGridViewColumn col) {
+                       owningColumn = col;
+               }
 
                internal void SetColumnIndex (int index) {
                        columnIndex = index;