* DataGridViewElement.cs: Initialize state.
authorRolf Bjarne Kvinge <RKvinge@novell.com>
Thu, 26 Jul 2007 08:54:29 +0000 (08:54 -0000)
committerRolf Bjarne Kvinge <RKvinge@novell.com>
Thu, 26 Jul 2007 08:54:29 +0000 (08:54 -0000)
* DataGridView.cs: Forward a few Mouse events to cells. Add
  GetRowInternal and GetCellInternal that doesn't unshare rows.
  Implement GetCellDisplayRectangle. HitTest: if the row is shared,
  don't use the index, but look it up. Add
  DataGridViewControlCollection.RemoveInternal to remove controls
  that Remove won't remove (scrollbars, edit control).
* DataGridViewColumn.cs: Initialize State correctly.
* DataGridViewColumnHeaderCell.cs, DataGridViewComboBoxCell.cs,
  DataGridViewHeaderCell.cs, DataGridViewRowHeaderCell.cs: Started
  implementing this.
* DataGridViewRowCollection.cs: Implemented shared rows.
* DataGridViewRow.cs: Throw exceptions as MS do.
* DataGridViewCell.cs: A few properties are implemented by a
  Get<Property> method, so move implementation there and remove the
  NIEX in the method. Add a bunch of OnXInternal that DataGridView
  calls when necessary.
* DataGridViewComboBoxEditingControl.cs: Remove a few NIEX'es that just
  complicates matters.
* DataGridViewCellCollection.cs: Add a GetCellInternal that doesn't
  unshare any rows.

svn path=/trunk/mcs/; revision=82743

14 files changed:
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridView.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewCell.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewCellCollection.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewColumn.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewColumnHeaderCell.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewComboBoxCell.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewComboBoxEditingControl.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewElement.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewHeaderCell.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewRow.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewRowCollection.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewRowHeaderCell.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/NativeWindow.cs

index d787ac9fe95b76f302cf0ad948347069f7469f4d..5255ad8df740f8705b215dfea6b389a39079b6aa 100644 (file)
@@ -1,3 +1,27 @@
+2007-07-26  Rolf Bjarne Kvinge <RKvinge@novell.com> 
+
+       * DataGridViewElement.cs: Initialize state.
+       * DataGridView.cs: Forward a few Mouse events to cells. Add
+         GetRowInternal and GetCellInternal that doesn't unshare rows.
+         Implement GetCellDisplayRectangle. HitTest: if the row is shared,
+         don't use the index, but look it up. Add
+         DataGridViewControlCollection.RemoveInternal to remove controls
+         that Remove won't remove (scrollbars, edit control).
+       * DataGridViewColumn.cs: Initialize State correctly.
+       * DataGridViewColumnHeaderCell.cs, DataGridViewComboBoxCell.cs,
+         DataGridViewHeaderCell.cs, DataGridViewRowHeaderCell.cs: Started
+         implementing this.
+       * DataGridViewRowCollection.cs: Implemented shared rows.
+       * DataGridViewRow.cs: Throw exceptions as MS do.
+       * DataGridViewCell.cs: A few properties are implemented by a
+         Get<Property> method, so move implementation there and remove the
+         NIEX in the method. Add a bunch of OnXInternal that DataGridView
+         calls when necessary.
+       * DataGridViewComboBoxEditingControl.cs: Remove a few NIEX'es that just
+         complicates matters.
+       * DataGridViewCellCollection.cs: Add a GetCellInternal that doesn't
+         unshare any rows.
+
 2007-07-25  Jonathan Pobst  <monkey@jpobst.com>
 
        * UpDownBase.cs: We cannot override SetBoundsCore for 2.0, which was relayout-ing
index 248626a874891b6b835f37094f942a3a3d19ebe8..7be15efd937fe4132595e6ac5a59bcf0fadb8799 100644 (file)
@@ -648,10 +648,7 @@ namespace System.Windows.Forms {
                [EditorBrowsable (EditorBrowsableState.Advanced)]
                public Control EditingControl {
                        get {
-                               if (currentCell == null || !currentCell.IsInEditMode) {
-                                       return null;
-                               }
-                               return (Control) Activator.CreateInstance(currentCell.EditType);
+                               return editingControl;
                        }
                }
 
@@ -1149,13 +1146,20 @@ namespace System.Windows.Forms {
                                        return;
 
                                if (editingControl != null) {
-                                       // Can't use Controls.RemoveAt (editingControls), because that method
+                                       // Can't use Controls.Remove (editingControls), because that method
                                        // is overriden to not remove the editing control.
-                                       Controls.RemoveAt (Controls.IndexOf (editingControl));
+                                       DataGridView.DataGridViewControlCollection ctrls = Controls as DataGridView.DataGridViewControlCollection;
+                                       if (ctrls != null) {
+                                               ctrls.RemoveInternal (editingControl);
+                                       } else {
+                                               Controls.Remove (editingControl);
+                                       }
                                }
                                
                                if (value != null)
-                                       Controls.Add (editingControl);
+                                       Controls.Add (value);
+
+                               editingControl = value;
                        }
                }
 
@@ -2080,11 +2084,48 @@ namespace System.Windows.Forms {
                        return result;
                }
 
+               internal DataGridViewRow GetRowInternal (int rowIndex)
+               {
+                       return Rows.SharedRow (rowIndex);
+               }
+
+               internal DataGridViewCell GetCellInternal (int colIndex, int rowIndex)
+               {
+                       return GetRowInternal (rowIndex).Cells.GetCellInternal (colIndex);
+               }
+
                public Rectangle GetCellDisplayRectangle (int columnIndex, int rowIndex, bool cutOverflow) {
                        if (columnIndex < 0 || columnIndex >= columns.Count) {
                                throw new ArgumentOutOfRangeException("Column index is out of range.");
                        }
-                       throw new NotImplementedException();
+                       
+                       int x = 0, y = 0, w = 0, h = 0;
+                       
+                       if (ColumnHeadersVisible)
+                               y = ColumnHeadersHeight;
+                       
+                       if (RowHeadersVisible)
+                               x = RowHeadersWidth;
+                               
+                       for (int i = 0; i < Columns.Count; i++) {
+                               if (i == columnIndex) {
+                                       w = columns [i].Width;
+                                       break;
+                               }
+                                       
+                               x += columns [i].Width;
+                       }
+                       
+                       for (int i = 0; i < Rows.Count; i++) {
+                               if (i == rowIndex) {
+                                       h = rows [i].Height;
+                                       break;
+                               }
+                               
+                               y += rows [i].Height;
+                       }
+                       
+                       return new Rectangle (x, y, w, h);
                }
 
                public virtual DataObject GetClipboardContent () {
@@ -2101,6 +2142,7 @@ namespace System.Windows.Forms {
 
                public HitTestInfo HitTest (int x, int y) {
                        ///////////////////////////////////////////////////////
+                       //Console.WriteLine ("HitTest ({0}, {1})", x, y);
                        x += horizontalScrollingOffset;
                        y += verticalScrollingOffset;
                        int rowIndex = -1;
@@ -2113,6 +2155,9 @@ namespace System.Windows.Forms {
                                        totalHeight += row.Height;
                                        if (y <= totalHeight) {
                                                rowIndex = row.Index;
+                                               if (rowIndex == -1) {
+                                                       rowIndex = rows.SharedRowIndexOf (row);
+                                               }
                                                break;
                                        }
                                        totalHeight++; // sumar el ancho de las lineas...
@@ -2503,6 +2548,10 @@ namespace System.Windows.Forms {
 
                protected virtual void OnCellClick (DataGridViewCellEventArgs e)
                {
+                       DataGridViewCell cell = GetCellInternal (e.ColumnIndex, e.RowIndex);
+
+                       cell.OnClickInternal (e);
+       
                        DataGridViewCellEventHandler eh = (DataGridViewCellEventHandler)(Events [CellClickEvent]);
                        if (eh != null)
                                eh (this, e);
@@ -2510,6 +2559,10 @@ namespace System.Windows.Forms {
 
                protected virtual void OnCellContentClick (DataGridViewCellEventArgs e)
                {
+                       DataGridViewCell cell = GetCellInternal (e.ColumnIndex, e.RowIndex);
+
+                       cell.OnContentClickInternal (e);
+                       
                        DataGridViewCellEventHandler eh = (DataGridViewCellEventHandler)(Events [CellContentClickEvent]);
                        if (eh != null)
                                eh (this, e);
@@ -2517,6 +2570,10 @@ namespace System.Windows.Forms {
 
                protected virtual void OnCellContentDoubleClick (DataGridViewCellEventArgs e)
                {
+                       DataGridViewCell cell = GetCellInternal (e.ColumnIndex, e.RowIndex);
+
+                       cell.OnContentDoubleClickInternal (e);
+                       
                        DataGridViewCellEventHandler eh = (DataGridViewCellEventHandler)(Events [CellContentDoubleClickEvent]);
                        if (eh != null)
                                eh (this, e);
@@ -2538,6 +2595,9 @@ namespace System.Windows.Forms {
 
                protected virtual void OnCellDoubleClick (DataGridViewCellEventArgs e)
                {
+                       DataGridViewCell cell = GetCellInternal (e.ColumnIndex, e.RowIndex);
+
+                       cell.OnDoubleClickInternal (e);
                        DataGridViewCellEventHandler eh = (DataGridViewCellEventHandler)(Events [CellDoubleClickEvent]);
                        if (eh != null)
                                eh (this, e);
@@ -2587,6 +2647,10 @@ namespace System.Windows.Forms {
 
                protected virtual void OnCellMouseClick (DataGridViewCellMouseEventArgs e)
                {
+                       DataGridViewCell cell = GetCellInternal (e.ColumnIndex, e.RowIndex);
+
+                       cell.OnMouseClickInternal (e);
+                       
                        DataGridViewCellMouseEventHandler eh = (DataGridViewCellMouseEventHandler)(Events [CellMouseClickEvent]);
                        if (eh != null)
                                eh (this, e);
@@ -2594,6 +2658,10 @@ namespace System.Windows.Forms {
 
                protected virtual void OnCellMouseDoubleClick (DataGridViewCellMouseEventArgs e)
                {
+                       DataGridViewCell cell = GetCellInternal (e.ColumnIndex, e.RowIndex);
+
+                       cell.OnMouseDoubleClickInternal (e);
+                       
                        DataGridViewCellMouseEventHandler eh = (DataGridViewCellMouseEventHandler)(Events [CellMouseDoubleClickEvent]);
                        if (eh != null)
                                eh (this, e);
@@ -2601,6 +2669,11 @@ namespace System.Windows.Forms {
 
                protected virtual void OnCellMouseDown (DataGridViewCellMouseEventArgs e)
                {
+
+                       DataGridViewCell cell = GetCellInternal (e.ColumnIndex, e.RowIndex);
+
+                       cell.OnMouseDownInternal (e);
+                       
                        DataGridViewCellMouseEventHandler eh = (DataGridViewCellMouseEventHandler)(Events [CellMouseDownEvent]);
                        if (eh != null)
                                eh (this, e);
@@ -2608,6 +2681,10 @@ namespace System.Windows.Forms {
 
                protected virtual void OnCellMouseEnter (DataGridViewCellEventArgs e)
                {
+                       DataGridViewCell cell = GetCellInternal (e.ColumnIndex, e.RowIndex);
+
+                       cell.OnMouseEnterInternal (e.RowIndex);
+                       
                        DataGridViewCellEventHandler eh = (DataGridViewCellEventHandler)(Events [CellMouseEnterEvent]);
                        if (eh != null)
                                eh (this, e);
@@ -2615,6 +2692,10 @@ namespace System.Windows.Forms {
 
                protected virtual void OnCellMouseLeave (DataGridViewCellEventArgs e)
                {
+                       DataGridViewCell cell = GetCellInternal (e.ColumnIndex, e.RowIndex);
+
+                       cell.OnMouseLeaveInternal (e.RowIndex);
+                       
                        DataGridViewCellEventHandler eh = (DataGridViewCellEventHandler)(Events [CellMouseLeaveEvent]);
                        if (eh != null)
                                eh (this, e);
@@ -2622,6 +2703,10 @@ namespace System.Windows.Forms {
 
                protected virtual void OnCellMouseMove (DataGridViewCellMouseEventArgs e)
                {
+                       DataGridViewCell cell = GetCellInternal (e.ColumnIndex, e.RowIndex);
+                       
+                       cell.OnMouseMoveInternal (e);
+               
                        DataGridViewCellMouseEventHandler eh = (DataGridViewCellMouseEventHandler)(Events [CellMouseMoveEvent]);
                        if (eh != null)
                                eh (this, e);
@@ -2629,6 +2714,10 @@ namespace System.Windows.Forms {
 
                protected virtual void OnCellMouseUp (DataGridViewCellMouseEventArgs e)
                {
+                       DataGridViewCell cell = GetCellInternal (e.ColumnIndex, e.RowIndex);
+
+                       cell.OnMouseUpInternal (e);
+                       
                        DataGridViewCellMouseEventHandler eh = (DataGridViewCellMouseEventHandler)(Events [CellMouseUpEvent]);
                        if (eh != null)
                                eh (this, e);
@@ -3020,6 +3109,16 @@ namespace System.Windows.Forms {
                {
                        base.OnMouseClick(e);
                        //Console.WriteLine("Mouse: Clicks: {0}; Delta: {1}; X: {2}; Y: {3};", e.Clicks, e.Delta, e.X, e.Y);
+                       HitTestInfo hit = HitTest (e.X, e.Y);
+
+                       switch (hit.Type) 
+                       {
+                       case DataGridViewHitTestType.Cell:
+                               Rectangle display = GetCellDisplayRectangle (hit.ColumnIndex, hit.RowIndex, false);
+                               OnCellMouseClick (new DataGridViewCellMouseEventArgs (hit.ColumnIndex, hit.RowIndex, e.X - display.X, e.Y - display.Y, e));
+                               break;
+                       
+                       }
                }
 
                protected override void OnMouseDoubleClick (MouseEventArgs e)
@@ -3036,6 +3135,8 @@ namespace System.Windows.Forms {
                        if (hitTest.RowIndex < 0 || hitTest.ColumnIndex < 0) {
                                return;
                        }
+                       Rectangle cellBounds = GetCellDisplayRectangle (hitTest.ColumnIndex, hitTest.RowIndex, false);
+                       OnCellMouseDown (new DataGridViewCellMouseEventArgs (hitTest.ColumnIndex, hitTest.RowIndex, e.X - cellBounds.X, e.Y - cellBounds.Y, e));
                        OnCellClick(new DataGridViewCellEventArgs(hitTest.ColumnIndex, hitTest.RowIndex));
                        DataGridViewRow row = rows[hitTest.RowIndex];
                        DataGridViewCell cell = row.Cells[hitTest.ColumnIndex];
@@ -3089,6 +3190,25 @@ namespace System.Windows.Forms {
                protected override void OnMouseMove (MouseEventArgs e)
                {
                        base.OnMouseMove(e);
+                       HitTestInfo hit = this.HitTest (e.X, e.Y);
+                       
+                       switch (hit.Type)
+                       {
+                       case DataGridViewHitTestType.Cell:
+                               Rectangle display = GetCellDisplayRectangle (hit.ColumnIndex, hit.RowIndex, false);
+                               OnCellMouseMove (new DataGridViewCellMouseEventArgs (hit.ColumnIndex, hit.RowIndex, e.X - display.X, e.Y - display.Y, e));
+                               break;
+                       case DataGridViewHitTestType.ColumnHeader:
+                       case DataGridViewHitTestType.RowHeader:
+                       case DataGridViewHitTestType.TopLeftHeader:
+                       
+                       case DataGridViewHitTestType.HorizontalScrollBar:
+                       case DataGridViewHitTestType.VerticalScrollBar:
+                       
+                       
+                       case DataGridViewHitTestType.None:
+                               break;
+                       }
                }
 
                protected override void OnMouseUp (MouseEventArgs e)
@@ -3168,19 +3288,40 @@ namespace System.Windows.Forms {
                                                if (cell.ColumnIndex == col.Index) {
                                                        bounds.Width = col.Width;
                                                        cell.SetSize(new Size(bounds.Width, bounds.Height));
-                                                       DataGridViewCellStyle style = cell.InheritedStyle;
-                                                       if (cell == currentCell && cell.IsInEditMode) {
-                                                               cell.InitializeEditingControl(cell.RowIndex, cell.FormattedValue, style);
-                                                               cell.PositionEditingControl(true, true, bounds, e.ClipRectangle, style, false, false, (columns[currentCell.ColumnIndex].DisplayIndex == 0), (currentCell.RowIndex == 0));
+                                                       DataGridViewCellStyle style;
+                                                       if (cell.RowIndex == -1) {
+                                                               style = DefaultCellStyle;
+                                                       } else {
+                                                               style = cell.InheritedStyle;
                                                        }
-                                                       else {
+                                                       if (cell == currentCell && cell.IsInEditMode) {
+                                                               Type editType = cell.EditType;
+                                                               if (editType != null) {
+                                                                       bool isCorrectType = EditingControlInternal != null && EditingControlInternal.GetType () == editType;
+                                                                       if (EditingControlInternal != null && !isCorrectType) {
+                                                                               EditingControlInternal = null;
+                                                                       }
+                                                                       if (EditingControlInternal == null)
+                                                                               EditingControlInternal = (Control) Activator.CreateInstance (editType);
+                                                                       cell.InitializeEditingControl(cell.RowIndex, cell.FormattedValue, style);
+                                                                       cell.PositionEditingControl(true, true, bounds, e.ClipRectangle, style, false, false, (columns[currentCell.ColumnIndex].DisplayIndex == 0), (currentCell.RowIndex == 0));
+                                                                       EditingControl.Visible = true;
+                                                               }
+                                                       } else {
+                                                               object value, formattedValue; string errorText;
+                                                               if (cell.RowIndex == -1) {
+                                                                       // TODO: Look up value if databound.
+                                                                       value = null; formattedValue = null; errorText = null;
+                                                               } else {
+                                                                       value = cell.Value; formattedValue = cell.FormattedValue; errorText = cell.ErrorText;
+                                                               }
                                                                DataGridViewAdvancedBorderStyle intermediateBorderStyle = (DataGridViewAdvancedBorderStyle) ((ICloneable)this.AdvancedCellBorderStyle).Clone();
                                                                DataGridViewAdvancedBorderStyle borderStyle = cell.AdjustCellBorderStyle(this.AdvancedCellBorderStyle, intermediateBorderStyle, true, true, j == 0, cell.RowIndex == 0);
-                                                               OnCellFormatting(new DataGridViewCellFormattingEventArgs(cell.ColumnIndex, cell.RowIndex, cell.Value, cell.FormattedValueType, style));
-                                                               DataGridViewCellPaintingEventArgs args = new DataGridViewCellPaintingEventArgs (this, e.Graphics, e.ClipRectangle, bounds, cell.RowIndex, cell.ColumnIndex, cell.State, cell.Value, cell.FormattedValue, cell.ErrorText, style, borderStyle, DataGridViewPaintParts.All);
+                                                               OnCellFormatting(new DataGridViewCellFormattingEventArgs(cell.ColumnIndex, cell.RowIndex, value, cell.FormattedValueType, style));
+                                                               DataGridViewCellPaintingEventArgs args = new DataGridViewCellPaintingEventArgs (this, e.Graphics, e.ClipRectangle, bounds, cell.RowIndex, cell.ColumnIndex, cell.State, value, formattedValue, errorText, style, borderStyle, DataGridViewPaintParts.All);
                                                                OnCellPainting(args);
                                                                if (!args.Handled) {
-                                                                       cell.InternalPaint(e.Graphics, e.ClipRectangle, bounds, cell.RowIndex, cell.State, cell.Value, cell.FormattedValue, cell.ErrorText, style, borderStyle, DataGridViewPaintParts.All);
+                                                                       cell.InternalPaint(e.Graphics, e.ClipRectangle, bounds, cell.RowIndex, cell.State, value, formattedValue, errorText, style, borderStyle, DataGridViewPaintParts.All);
                                                                }
                                                        }
                                                        bounds.X += bounds.Width;
@@ -3852,6 +3993,11 @@ namespace System.Windows.Forms {
                                base.Remove (value);
                        }
                        
+                       internal void RemoveInternal (Control value)
+                       {
+                               base.Remove (value);
+                       }
+                       
                        
                }
 
index 6dcd7b9aac8e2e44626218d60eb69f10c3719fc5..85e593e0b9589491feb55de78716d5e1d4f9dc87 100644 (file)
@@ -87,12 +87,18 @@ 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)]
@@ -114,7 +120,9 @@ namespace System.Windows.Forms {
                [Browsable (false)]
                [EditorBrowsable (EditorBrowsableState.Advanced)]
                public object EditedFormattedValue {
-                       get { return editedFormattedValue; }
+                       get { 
+                               return GetEditedFormattedValue (RowIndex, DataGridViewDataErrorContexts.Formatting);
+                       }
                }
 
                [Browsable (false)]
@@ -126,12 +134,20 @@ namespace System.Windows.Forms {
                [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;
@@ -143,6 +159,9 @@ 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);
@@ -168,260 +187,29 @@ namespace System.Windows.Forms {
 
                [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)]
@@ -438,7 +226,12 @@ namespace System.Windows.Forms {
 
                [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)]
@@ -450,7 +243,9 @@ namespace System.Windows.Forms {
 
                [Browsable (false)]
                public virtual bool Resizable {
-                       get { return resizable; }
+                       get {
+                               return resizable; 
+                       }
                }
 
                [Browsable (false)]
@@ -477,13 +272,21 @@ 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;
                                }
@@ -504,18 +307,17 @@ namespace System.Windows.Forms {
                [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);
                        }
                }
 
@@ -527,7 +329,26 @@ namespace System.Windows.Forms {
 
                [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)]
@@ -536,9 +357,7 @@ namespace System.Windows.Forms {
                }
 
                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;
@@ -551,9 +370,7 @@ namespace System.Windows.Forms {
                        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;
@@ -569,7 +386,6 @@ namespace System.Windows.Forms {
                        result.valueType = this.valueType;
                        result.visible = this.visible;
                        return result;
-                       */
                }
 
                [EditorBrowsable (EditorBrowsableState.Advanced)]
@@ -581,11 +397,19 @@ 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;
+                               
+                       DataGridViewCellStyle style = InheritedStyle;
+                       
+                       return editedFormattedValue;
                }
 
                public virtual ContextMenuStrip GetInheritedContextMenuStrip (int rowIndex)
@@ -594,7 +418,63 @@ namespace System.Windows.Forms {
                }
 
                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;
+                       
+                       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.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) {
@@ -602,7 +482,195 @@ 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)]
@@ -687,7 +755,12 @@ namespace System.Windows.Forms {
 
                [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)]
@@ -739,7 +812,7 @@ namespace System.Windows.Forms {
                }
 
                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) {
@@ -760,11 +833,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) {
@@ -814,54 +892,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();
                }
@@ -959,7 +1105,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) {
@@ -975,6 +1126,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;
index 62b6c696efc28e81e1f7f181c3b79d5909017e2f..227d45fffc0ef9bba1e6f9b41859ded6a0d10325 100644 (file)
@@ -54,6 +54,11 @@ namespace System.Windows.Forms {
                        set { Insert(index, value); }
                }
 
+               internal DataGridViewCell GetCellInternal (int colIndex)
+               {
+                       return (DataGridViewCell) base.List [colIndex];
+               }
+               
                public DataGridViewCell this [string columnName] {
                        get {
                                foreach (DataGridViewCell cell in base.List) {
index 8d12d1a7881fa9d7c103505692343f0bbe910dd8..39828220c029fcab31d108032e16c87ccec37313 100644 (file)
@@ -71,6 +71,7 @@ namespace System.Windows.Forms {
                        dataPropertyName = string.Empty;
                        fillWeight = 100.0F;
                        sortMode = DataGridViewColumnSortMode.NotSortable;
+                       SetState (DataGridViewElementStates.Visible);
                }
 
                public DataGridViewColumn (DataGridViewCell cellTemplate) : this () {
@@ -212,7 +213,9 @@ Example */
                [Browsable (false)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public DataGridViewColumnHeaderCell HeaderCell {
-                       get { return headerCell; }
+                       get {
+                               return headerCell;
+                       }
                        set {
                                if (headerCell != value) {
                                        headerCell = value;
index 814ba56829a8f474a45148463e3f1c7db7824fa5..ae301720df93173932b02d0a1bd437b7cd156f1e 100644 (file)
@@ -35,7 +35,8 @@ namespace System.Windows.Forms {
        public class DataGridViewColumnHeaderCell : DataGridViewHeaderCell {
 
                private SortOrder sortGlyphDirection = SortOrder.None;
-
+               private object header_text;
+               
                public DataGridViewColumnHeaderCell () {
                }
 
@@ -60,7 +61,16 @@ namespace System.Windows.Forms {
                }
 
                public override DataGridViewCellStyle GetInheritedStyle (DataGridViewCellStyle inheritedCellStyle, int rowIndex, bool includeColors) {
-                       throw new NotImplementedException();
+                       
+                       DataGridViewCellStyle result;
+                       
+                       if (HasStyle) {
+                               result = Style;
+                       } else {
+                               result = DataGridView.ColumnHeadersDefaultCellStyle;
+                       }
+                       
+                       return result;                  
                }
 
                public override string ToString () {
@@ -85,7 +95,13 @@ namespace System.Windows.Forms {
                }
 
                protected override object GetValue (int rowIndex) {
-                       throw new NotImplementedException();
+                       if (header_text != null)
+                               return header_text;
+                               
+                       if (OwningColumn != null)
+                               return OwningColumn.Name;
+                       
+                       return null;
                }
 
                protected override void Paint (Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) {
@@ -95,7 +111,8 @@ namespace System.Windows.Forms {
                }
 
                protected override bool SetValue (int rowIndex, object value) {
-                       throw new NotImplementedException();
+                       header_text = value;
+                       return true;
                }
 
                protected class DataGridViewColumnHeaderCellAccessibleObject : DataGridViewCellAccessibleObject {
index c7a7b04af7207fe2fd85ffa87a7ff1d1bcc02212..12b93c1489fd28bb464d838ae9b1eadc087e0a4e 100644 (file)
@@ -46,7 +46,7 @@ namespace System.Windows.Forms {
                private bool sorted;
                private string valueMember;
 
-               private ComboBox editingControl;
+               private DataGridViewComboBoxEditingControl editingControl;
 
                public DataGridViewComboBoxCell () : base() {
                        autoComplete = true;
@@ -183,11 +183,28 @@ namespace System.Windows.Forms {
                }
 
                public override void InitializeEditingControl (int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle) {
-                       if (editingControl == null) {
-                               editingControl = new ComboBox ();
-                               editingControl.Text = initialFormattedValue == null ? string.Empty : initialFormattedValue.ToString ();
-                       }
-                       this.DataGridView.EditingControlInternal = editingControl;                      
+                       base.InitializeEditingControl (rowIndex, initialFormattedValue, dataGridViewCellStyle);
+                       
+                       editingControl = DataGridView.EditingControl as DataGridViewComboBoxEditingControl;
+                       
+                       if (editingControl == null)
+                               return;
+                       
+                       // A simple way to check if the control has
+                       // been initialized already.
+                       if (editingControl.Items.Count > 0)
+                               return;
+                       
+                       editingControl.DropDownStyle = ComboBoxStyle.DropDownList;
+                       editingControl.Text = initialFormattedValue == null ? string.Empty : initialFormattedValue.ToString ();
+                       editingControl.SelectedIndexChanged += new EventHandler (editingControl_SelectedIndexChanged);
+                       editingControl.Items.Clear ();
+                       editingControl.Items.AddRange (this.Items);             
+               }
+
+               void editingControl_SelectedIndexChanged (object sender, EventArgs e)
+               {
+                       Value = editingControl.SelectedItem;
                }
 
                public override bool KeyEntersEditMode (KeyEventArgs e) {
@@ -244,11 +261,48 @@ namespace System.Windows.Forms {
                }
 
                protected override void OnMouseMove (DataGridViewCellMouseEventArgs e) {
+                       //Console.WriteLine ("MouseMove (Location: {0}", e.Location);
                        base.OnMouseMove (e);
                }
 
-               protected override void Paint (Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementeState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) {
-                       throw new NotImplementedException();
+               protected override void Paint (Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, 
+                               int rowIndex, DataGridViewElementStates elementeState, object value, 
+                               object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, 
+                               DataGridViewPaintParts paintParts) {
+                       
+                       
+                       Rectangle button_area, text_area;
+                       text_area = cellBounds;
+                       button_area = CalculateButtonArea (cellBounds);
+                       
+                       graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (cellStyle.BackColor), cellBounds);
+                       ThemeEngine.Current.CPDrawComboButton (graphics, button_area, ButtonState.Normal);
+                       
+                       string text;
+                       if (formattedValue == null)
+                               text = string.Empty;
+                       else {
+                               text = formattedValue.ToString ();
+                       }
+                       
+                       graphics.DrawString (text, cellStyle.Font, ThemeEngine.Current.ResPool.GetSolidBrush (cellStyle.ForeColor), text_area, StringFormat.GenericTypographic);
+               }
+
+               private Rectangle CalculateButtonArea (Rectangle cellBounds)
+               {
+                       Rectangle button_area, text_area;
+                       int border = ThemeEngine.Current.Border3DSize.Width;
+                       const int button_width = 16;
+
+                       text_area = cellBounds;
+
+                       button_area = cellBounds;
+                       button_area.X = text_area.Right - button_width - border;
+                       button_area.Y = text_area.Y + border;
+                       button_area.Width = button_width;
+                       button_area.Height = text_area.Height - 2 * border;
+                       
+                       return button_area;
                }
 
                [ListBindable (false)]
index ee9cf5cda8e769341e86c3237ffa15d1c4d6805f..99555eea7db80d3b1632fbafb5c90062f3ebb03d 100644 (file)
@@ -75,24 +75,24 @@ namespace System.Windows.Forms {
                }
 
                public virtual void ApplyCellStyleToEditingControl (DataGridViewCellStyle dataGridViewCellStyle) {
-                       throw new NotImplementedException();
+                       
                }
 
                public virtual bool EditingControlWantsInputKey (Keys keyData, bool dataGridViewWantsInputKey) {
                        // true if the specified key is a regular key that should be handled by the editing control; otherwise, false
-                       throw new NotImplementedException();
+                       return base.IsInputKey (keyData);
                }
 
                public virtual object GetEditingControlFormattedValue (DataGridViewDataErrorContexts context) {
-                       throw new NotImplementedException();
+                       return Text;
                }
 
                public virtual void PrepareEditingControlForEdit (bool selectAll) {
-                       throw new NotImplementedException();
+                       
                }
 
                protected override void OnSelectedIndexChanged (EventArgs e) {
-                       throw new NotImplementedException();
+                       base.OnSelectedIndexChanged (e);
                }
 
        }
index 642ed2b73c397558a03e55e63dc953288e9bf4ed..f9019c490bcb1f342ea7d7e369c1d95e0357cfcc 100644 (file)
@@ -38,7 +38,6 @@ namespace System.Windows.Forms {
 
                public DataGridViewElement () {
                        dataGridView = null;
-                       state = DataGridViewElementStates.Visible;
                }
 
                [Browsable (false)]
index 51ada563206af014333c2361035514cda76be80d..2ef29fab93df2a697d505445ce5dde8bf02c0eec 100644 (file)
@@ -112,7 +112,7 @@ namespace System.Windows.Forms {
 
                protected override object GetValue (int rowIndex)
                {
-                       throw new NotImplementedException();
+                       return base.GetValue (rowIndex);
                }
 
                protected override bool MouseDownUnsharesRow (DataGridViewCellMouseEventArgs e)
index 3c95929a931ebd6233952cfa0fceb618e725b50b..b0b2afbf3de8f4577aec0d49640fdbdbbc6883d0 100644 (file)
@@ -51,6 +51,8 @@ namespace System.Windows.Forms {
                        minimumHeight = 3;
                        height = -1;
                        headerCell = new DataGridViewRowHeaderCell();
+                       accessibilityObject = new AccessibleObject ();
+                       SetState (DataGridViewElementStates.Visible);
                }
 
                [Browsable (false)]
@@ -66,7 +68,12 @@ namespace System.Windows.Forms {
 
                [DefaultValue (null)]
                public override ContextMenuStrip ContextMenuStrip {
-                       get { return contextMenuStrip; }
+                       get {
+                               if (IsShared)
+                                       throw new InvalidOperationException ("Operation cannot be performed on a shared row.");
+                                       
+                               return contextMenuStrip;
+                       }
                        set {
                                if (contextMenuStrip != value) {
                                        contextMenuStrip = value;
@@ -100,7 +107,12 @@ namespace System.Windows.Forms {
 
                [Browsable (false)]
                public override bool Displayed {
-                       get { return base.Displayed; }
+                       get {
+                               if (IsShared)
+                                       throw new InvalidOperationException ("Getting the Displayed property of a shared row is not a valid operation.");
+                                       
+                               return base.Displayed;
+                       }
                }
 
                [DefaultValue (0)]
@@ -113,7 +125,12 @@ namespace System.Windows.Forms {
                [DefaultValue ("")]
                [NotifyParentProperty (true)]
                public string ErrorText {
-                       get { return errorText; }
+                       get {
+                               if (IsShared)
+                                       throw new InvalidOperationException ("Operation cannot be performed on a shared row.");
+                                       
+                               return errorText == null ? string.Empty : errorText;
+                       }
                        set {
                                if (errorText != value) {
                                        errorText = value;
@@ -126,7 +143,12 @@ namespace System.Windows.Forms {
 
                [Browsable (false)]
                public override bool Frozen {
-                       get { return base.Frozen; }
+                       get {
+                               if (IsShared)
+                                       throw new InvalidOperationException ("Getting the Frozen property of a shared row is not a valid operation.");
+                                       
+                               return base.Frozen;
+                       }
                        set { base.Frozen = value; }
                }
 
@@ -152,7 +174,7 @@ namespace System.Windows.Forms {
                                        if (DefaultCellStyle != null && DefaultCellStyle.Font != null) {
                                                return DefaultCellStyle.Font.Height + 9;
                                        }
-                                       if (InheritedStyle != null && InheritedStyle.Font != null) {
+                                       if (Index >= 0 && InheritedStyle != null && InheritedStyle.Font != null) {
                                                return InheritedStyle.Font.Height + 9;
                                        }
                                        return System.Windows.Forms.Control.DefaultFont.Height + 9;
@@ -174,6 +196,9 @@ namespace System.Windows.Forms {
 
                public override DataGridViewCellStyle InheritedStyle {
                        get {
+                               if (Index == -1)
+                                       throw new InvalidOperationException ("Getting the InheritedStyle property of a shared row is not a valid operation.");
+                                       
                                if (DataGridView == null) {
                                        return DefaultCellStyle;
                                }
@@ -194,13 +219,19 @@ namespace System.Windows.Forms {
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public bool IsNewRow {
                        get {
-                               if (DataGridView != null && DataGridView.Rows[DataGridView.Rows.Count - 1] == this) {
+                               if (DataGridView != null && DataGridView.Rows[DataGridView.Rows.Count - 1] == this && DataGridView.NewRowIndex == Index) {
                                        return true;
                                }
                                return false;
                        }
                }
 
+               internal bool IsShared {
+                       get {
+                               return Index == -1 && DataGridView != null;
+                       }
+               }
+
                [Browsable (false)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public int MinimumHeight {
@@ -222,24 +253,31 @@ namespace System.Windows.Forms {
                [DefaultValue (false)]
                [NotifyParentProperty (true)]
                public override bool ReadOnly {
-                       get { return base.ReadOnly; }
+                       get {
+                               if (IsShared)
+                                       throw new InvalidOperationException ("Getting the ReadOnly property of a shared row is not a valid operation.");
+                                       
+                               return base.ReadOnly;
+                       }
                        set { base.ReadOnly = value; }
                }
 
                [NotifyParentProperty (true)]
                public override DataGridViewTriState Resizable {
-                       get { return base.Resizable; }
+                       get {
+                               if (IsShared)
+                                       throw new InvalidOperationException ("Getting the Resizable property of a shared row is not a valid operation.");
+                                       
+                               return base.Resizable;
+                       }
                        set { base.Resizable = value; }
                }
 
                public override bool Selected {
                        get {
-                               if (Index == -1) {
-                                       throw new InvalidOperationException("The row is a shared row.");
-                               }
-                               if (DataGridView == null) {
-                                       throw new InvalidOperationException("The row has not been added to a DataGridView control.");
-                               }
+                               if (IsShared)
+                                       throw new InvalidOperationException ("Getting the Selected property of a shared row is not a valid operation.");
+                                       
                                return base.Selected;
                        }
                        set {
@@ -257,12 +295,22 @@ namespace System.Windows.Forms {
                }
 
                public override DataGridViewElementStates State {
-                       get { return base.State; }
+                       get {
+                               if (IsShared)
+                                       throw new InvalidOperationException ("Getting the State property of a shared row is not a valid operation.");
+                                       
+                               return base.State;
+                       }
                }
 
                [Browsable (false)]
                public override bool Visible {
-                       get { return base.Visible; }
+                       get {
+                               if (IsShared)
+                                       throw new InvalidOperationException ("Getting the Visible property of a shared row is not a valid operation.");
+                                       
+                               return base.Visible;
+                       }
                        set {
                                if (IsNewRow && value == false) {
                                        throw new InvalidOperationException("Cant make invisible a new row.");
@@ -403,6 +451,8 @@ namespace System.Windows.Forms {
                {
                        base.SetDataGridView(dataGridView);
                        headerCell.SetDataGridView(dataGridView);
+                       foreach (DataGridViewCell cell in cells)
+                               cell.SetDataGridView (dataGridView);
                }
 
                internal override void SetState (DataGridViewElementStates state)
index c64df125f56f157f79546400625a90ee013235b8..ade6af3310b04042252bd55094448805922b102d 100644 (file)
@@ -48,7 +48,7 @@ namespace System.Windows.Forms {
                                throw new ArgumentException("DataGridView is null.");
                        }
                        this.dataGridView = dataGridView;
-                       list = new ArrayList();
+                       list = new ArrayList ();
                }
 
                public int Count {
@@ -81,8 +81,16 @@ namespace System.Windows.Forms {
 
                public DataGridViewRow this [int index] {
                        get {
-                               // Accessing a System.Windows.Forms.DataGridViewRow with this indexer causes the row to become unshared. To keep the row shared, use the System.Windows.Forms.DataGridViewRowCollection.SharedRow method. For more information, see Best Practices for Scaling the Windows Forms DataGridView Control.
-                               return (DataGridViewRow) list[index];
+                               // Accessing a System.Windows.Forms.DataGridViewRow with this indexer causes the row to become unshared. 
+                               // To keep the row shared, use the System.Windows.Forms.DataGridViewRowCollection.SharedRow method. 
+                               // For more information, see Best Practices for Scaling the Windows Forms DataGridView Control.
+                               DataGridViewRow row = (DataGridViewRow) list [index];
+                               if (row.Index == -1) {
+                                       row = (DataGridViewRow) row.Clone ();
+                                       row.SetIndex (index);
+                                       list [index] = row;
+                               }
+                               return row;
                        }
                }
 
@@ -103,24 +111,55 @@ namespace System.Windows.Forms {
                        return Add(o as DataGridViewRow);
                }
 
-               public virtual int Add (DataGridViewRow dataGridViewRow)
+               internal int AddInternal (DataGridViewRow dataGridViewRow, bool sharable)
                {
                        if (dataGridView.DataSource != null) {
-                               throw new InvalidOperationException("DataSource of DataGridView is not null.");
+                               throw new InvalidOperationException ("DataSource of DataGridView is not null.");
                        }
                        if (dataGridView.Columns.Count == 0) {
-                               throw new InvalidOperationException("DataGridView has no columns.");
+                               throw new InvalidOperationException ("DataGridView has no columns.");
                        }
-                       dataGridViewRow.SetIndex(list.Count);
-                       dataGridViewRow.SetDataGridView(dataGridView);
-                       int result = list.Add(dataGridViewRow);
-                       OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Add, dataGridViewRow));
+                       int result = list.Add (dataGridViewRow);
+                       if (sharable && CanBeShared (dataGridViewRow)) {
+                               dataGridViewRow.SetIndex (-1);
+                       } else {
+                               dataGridViewRow.SetIndex (list.Count);
+                       }
+                       dataGridViewRow.SetDataGridView (dataGridView);
+
+                       for (int i = 0; i < dataGridViewRow.Cells.Count; i++) {
+                               dataGridViewRow.Cells [i].SetOwningColumn (dataGridView.Columns [i]);
+                       }
+
+                       OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, dataGridViewRow));
                        if (raiseEvent) {
-                               DataGridView.OnRowsAdded(new DataGridViewRowsAddedEventArgs(result, 1));
+                               DataGridView.OnRowsAdded (new DataGridViewRowsAddedEventArgs (result, 1));
                        }
                        return result;
                }
 
+               public virtual int Add (DataGridViewRow dataGridViewRow)
+               {
+                       return AddInternal (dataGridViewRow, true);
+               }
+               
+               private bool CanBeShared (DataGridViewRow row)
+               {
+                       foreach (DataGridViewCell cell in row.Cells) {
+                               if (cell.Value != null)
+                                       return false;
+                               
+                               if (cell.ToolTipText != string.Empty)
+                                       return false;
+                                       
+                               if (cell.ContextMenuStrip != null)
+                                       return false;
+                       }       
+                       
+                       return true;
+               }
+               
+
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public virtual int Add (int count)
                {
@@ -154,7 +193,7 @@ namespace System.Windows.Forms {
                        }
                        DataGridViewRow row = (DataGridViewRow)dataGridView.RowTemplateFull;
                        
-                       int result = Add(row);
+                       int result = AddInternal (row, false);
                        row.SetValues(values);
                        return result;
                }
@@ -428,6 +467,11 @@ namespace System.Windows.Forms {
                        return (DataGridViewRow) list[rowIndex];
                }
 
+               internal int SharedRowIndexOf (DataGridViewRow row)
+               {
+                       return list.IndexOf (row);
+               }
+
                protected DataGridView DataGridView {
                        get { return dataGridView; }
                }
index 0501056e31f451f3f6d23c277f5b4da01b5bcb69..f69e30395b29008d64d4dc72cf3a9858a8184b2e 100644 (file)
@@ -32,6 +32,8 @@ namespace System.Windows.Forms {
 
        public class DataGridViewRowHeaderCell : DataGridViewHeaderCell {
 
+               private string headerText;
+               
                public DataGridViewRowHeaderCell ()
                {
                }
@@ -48,7 +50,15 @@ namespace System.Windows.Forms {
 
                public override DataGridViewCellStyle GetInheritedStyle (DataGridViewCellStyle inheritedCellStyle, int rowIndex, bool includeColors)
                {
-                       throw new NotImplementedException();
+                       DataGridViewCellStyle result;
+
+                       if (HasStyle) {
+                               result = Style;
+                       } else {
+                               result = DataGridView.RowHeadersDefaultCellStyle;
+                       }
+
+                       return result;
                }
 
                public override string ToString ()
@@ -88,7 +98,10 @@ namespace System.Windows.Forms {
 
                protected override object GetValue (int rowIndex)
                {
-                       throw new NotImplementedException();
+                       if (headerText != null)
+                               return headerText;
+                               
+                       return null;
                }
 
                protected override void Paint (Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
@@ -102,7 +115,8 @@ namespace System.Windows.Forms {
 
                protected override bool SetValue (int rowIndex, object value)
                {
-                       throw new NotImplementedException();
+                       headerText = (string) value;
+                       return true;
                }
 
                protected class DataGridViewRowHeaderCellAccessibleObject : DataGridViewCellAccessibleObject {
index 7f6af98d19b032a3400843eaa2363db7dd5b7def..5c023edc5de4ca76e9dd872742e20c2754e7b885 100644 (file)
@@ -168,6 +168,11 @@ namespace System.Windows.Forms
                {
                        Message         m = new Message();
                        NativeWindow    window = null;
+                                       
+#if debug
+                       Console.WriteLine("NativeWindow.cs ({0}, {1}, {2}, {3}): result {4}", hWnd, msg, wParam, lParam, m.Result);
+#endif
+
 
                        //try {
                                lock (window_collection) {