- Same goes for setting the image size. Just resize them all
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / DataGrid.cs
index b3b578e5b9e6f4214941956f0ed74ab5197aa7df..932e81686d4577a3a178d8d2e5dde466f9e9bbc2 100644 (file)
@@ -35,7 +35,10 @@ using System.Collections;
 
 namespace System.Windows.Forms
 {
-       public class DataGrid : Control
+       [DefaultEvent("Navigate")]
+       [DefaultProperty("DataSource")]
+       [Designer("System.Windows.Forms.Design.DataGridDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
+       public class DataGrid : Control, ISupportInitialize, IDataGridEditingService
        {
                [Flags]
                [Serializable]
@@ -56,16 +59,16 @@ namespace System.Windows.Forms
                        public static readonly HitTestInfo Nowhere = null;
 
                        #region Local Variables
-                       private int column;
-                       private int row;
-                       private HitTestType type;
+                       internal int column;
+                       internal int row;
+                       internal HitTestType type;
                        #endregion // Local Variables
 
                        #region Private Constructors
                        internal HitTestInfo ()
                        {
-                               column = 0;
-                               row = 0;
+                               column = -1;
+                               row = -1;
                                type =  HitTestType.None;
                        }
                        #endregion
@@ -75,6 +78,7 @@ namespace System.Windows.Forms
                        public int Column {
                                get { return column; }
                        }
+
                        public int Row {
                                get { return row; }
                        }
@@ -99,39 +103,41 @@ namespace System.Windows.Forms
 
                        public override string ToString ()
                        {
-                               return base.ToString ();
+                               return "{ " + type + "," + row + "," + column + "}";
                        }
 
                }
 
                #region Local Variables
-               private static readonly Color   def_alternating_backcolor = SystemColors.Window;
-               private static readonly Color   def_background_color = SystemColors.Window;
-               private static readonly Color   def_caption_backcolor = SystemColors.ActiveCaption;
-               private static readonly Color   def_caption_forecolor = SystemColors.ActiveCaptionText;
-               private static readonly Color   def_gridline_color = SystemColors.Control;
-               private static readonly Color   def_header_backcolor = SystemColors.Control;
+               private static readonly Color   def_alternating_backcolor = ThemeEngine.Current.DataGridAlternatingBackColor;
+               private static readonly Color   def_background_color = ThemeEngine.Current.DataGridBackgroundColor;
+               private static readonly Color   def_caption_backcolor = ThemeEngine.Current.DataGridCaptionBackColor;
+               private static readonly Color   def_caption_forecolor = ThemeEngine.Current.DataGridCaptionForeColor;
+               private static readonly Color   def_gridline_color = ThemeEngine.Current.DataGridGridLineColor;
+               private static readonly Color   def_header_backcolor = ThemeEngine.Current.DataGridHeaderBackColor;
                private static readonly Font    def_header_font = ThemeEngine.Current.DefaultFont;
-               private static readonly Color   def_header_forecolor = SystemColors.ControlText;
-               private static readonly Color   def_link_hovercolor = SystemColors.HotTrack;
-               private static readonly Color   def_parentrowsback_color = SystemColors.Control;
-               private static readonly Color   def_parentrowsfore_color = SystemColors.WindowText;
-               private static readonly Color   def_selection_backcolor = SystemColors.ActiveCaption;
-               private static readonly Color   def_selection_forecolor = SystemColors.ActiveCaptionText;
-               private static readonly Color   def_link_color = SystemColors.HotTrack;
+               private static readonly Color   def_header_forecolor = ThemeEngine.Current.DataGridHeaderForeColor;
+               private static readonly Color   def_link_hovercolor = ThemeEngine.Current.DataGridLinkHoverColor;
+               private static readonly Color   def_parentrowsback_color = ThemeEngine.Current.DataGridParentRowsBackColor;
+               private static readonly Color   def_parentrowsfore_color = ThemeEngine.Current.DataGridParentRowsForeColor;
+               private static readonly Color   def_selection_backcolor = ThemeEngine.Current.DataGridSelectionBackColor;
+               private static readonly Color   def_selection_forecolor = ThemeEngine.Current.DataGridSelectionForeColor;
+               private static readonly Color   def_link_color = ThemeEngine.Current.DataGridLinkColor;
+               internal readonly int def_preferredrow_height;
 
                private bool allow_navigation;
                private bool allow_sorting;
                private Color alternating_backcolor;
+               private Color backColor;
                private Color background_color;
-               private BorderStyle border_style;
                private Color caption_backcolor;
                private Font caption_font;
                private Color caption_forecolor;
                private string caption_text;
-               private bool caption_visible;
-               private bool columnheaders_visible;
+               internal bool caption_visible;
+               internal bool columnheaders_visible;
                private object datasource;
+               private object real_datasource;
                private string datamember;
                private int firstvisible_column;
                private bool flatmode;
@@ -141,45 +147,61 @@ namespace System.Windows.Forms
                private Color header_forecolor;
                private Font header_font;
                private Color link_color;
-               private Color link_hovercolor;          
+               private Color link_hovercolor;
                private Color parentrowsback_color;
                private Color parentrowsfore_color;
                private bool parentrows_visible;
                private int preferredcolumn_width;
                private int preferredrow_height;
                private bool _readonly;
-               private bool rowheaders_visible;
+               internal bool rowheaders_visible;
                private Color selection_backcolor;
                private Color selection_forecolor;
                private int rowheaders_width;
-               private int visiblecolumn_count;
-               private int visiblerow_count;
-               private int currentrow_index;
+               internal int visiblecolumn_count;
+               internal int visiblerow_count;
+               internal int first_visiblecolumn;
                private GridTableStylesCollection styles_collection;
                private DataGridParentRowsLabelStyle parentrowslabel_style;
-               private DataGridCell current_cell;
-               private Color forecolor;
-               private Color backcolor;
+               internal DataGridCell current_cell;
                private DataGridTableStyle default_style;
                private DataGridTableStyle current_style;
+               internal HScrollBar horiz_scrollbar;
+               internal VScrollBar vert_scrollbar;
+               internal DataGridDrawing grid_drawing;
+               internal int first_visiblerow;
+               internal int horz_pixeloffset;
+               internal bool is_editing;       // Current cell is edit mode
+               internal bool is_changing;      // Indicates if current cell is been changed (in edit mode)
+               internal bool is_adding;        // Indicates when we are adding a row
+               private Hashtable selected_rows;
+               private bool ctrl_pressed;
+               private bool shift_pressed;
+               private bool begininit;
+               private CurrencyManager cached_currencymgr;
+               private CurrencyManager cached_currencymgr_events;
+               private bool accept_listmgrevents;
                #endregion // Local Variables
 
                #region Public Constructors
                public DataGrid ()
                {
-                       
+                       grid_drawing = new DataGridDrawing (this);
                        allow_navigation = true;
                        allow_sorting = true;
+                       begininit = false;
+                       backColor = ThemeEngine.Current.DataGridBackColor;
                        alternating_backcolor = def_alternating_backcolor;
                        background_color = def_background_color;
                        border_style = BorderStyle.Fixed3D;
                        caption_backcolor = def_caption_backcolor;
-                       caption_font = ThemeEngine.Current.DefaultFont;
+                       caption_font = null;
                        caption_forecolor = def_caption_forecolor;
                        caption_text = string.Empty;
                        caption_visible = true;
                        columnheaders_visible = true;
                        datasource = null;
+                       real_datasource = null;
                        datamember = string.Empty;
                        firstvisible_column = 0;
                        flatmode = false;
@@ -189,13 +211,12 @@ namespace System.Windows.Forms
                        header_forecolor = def_header_forecolor;
                        header_font = def_header_font;
                        link_color = def_link_color;
-                       link_hovercolor = def_link_hovercolor;                  
+                       link_hovercolor = def_link_hovercolor;
                        parentrowsback_color = def_parentrowsback_color;
                        parentrowsfore_color = def_parentrowsfore_color;
                        parentrows_visible = true;
-                       preferredcolumn_width = 75;
-                       preferredrow_height = 16;
-                       _readonly = false ;
+                       preferredcolumn_width = ThemeEngine.Current.DataGridPreferredColumnWidth;
+                       _readonly = false;
                        rowheaders_visible = true;
                        selection_backcolor = def_selection_backcolor;
                        selection_forecolor = def_selection_forecolor;
@@ -203,23 +224,41 @@ namespace System.Windows.Forms
                        visiblecolumn_count = 0;
                        visiblerow_count = 0;
                        current_cell = new DataGridCell ();
-                       currentrow_index = -1;
-                       forecolor = SystemColors.WindowText;
+                       first_visiblerow = 0;
+                       first_visiblecolumn = 0;
+                       horz_pixeloffset = 0;
+                       is_editing = false;
+                       is_changing = false;
+                       is_adding = false;
                        parentrowslabel_style = DataGridParentRowsLabelStyle.Both;
-                       backcolor = SystemColors.Window;
-                       
+                       selected_rows = new Hashtable ();
+                       ctrl_pressed = false;
+                       shift_pressed = false;
+                       preferredrow_height = def_preferredrow_height = FontHeight + 3;
+                       cached_currencymgr_events = cached_currencymgr = null;
+                       accept_listmgrevents = true;
+
                        default_style = new DataGridTableStyle (true);
                        styles_collection = new GridTableStylesCollection (this);
                        styles_collection.CollectionChanged += new CollectionChangeEventHandler (OnTableStylesCollectionChanged);
-                       
-                       SetCurrentStyle (default_style);
-                       
-               }               
-               
+
+                       CurrentTableStyle = default_style;
+
+                       horiz_scrollbar = new HScrollBar ();
+                       horiz_scrollbar.Scroll += new ScrollEventHandler  (GridHScrolled);
+                       vert_scrollbar = new VScrollBar ();
+                       vert_scrollbar.Scroll += new ScrollEventHandler (GridVScrolled);                        
+                       KeyUp += new KeyEventHandler (OnKeyUpDG);                       
+
+                       SetStyle (ControlStyles.UserMouse, true);
+
+               }
+
                #endregion      // Public Constructor
 
                #region Public Instance Properties
 
+               [DefaultValue(true)]
                public bool AllowNavigation {
                        get {
                                return allow_navigation;
@@ -233,6 +272,7 @@ namespace System.Windows.Forms
                        }
                }
 
+               [DefaultValue(true)]
                public bool AllowSorting {
                        get {
                                return allow_sorting;
@@ -260,13 +300,10 @@ namespace System.Windows.Forms
 
                public Color BackColor {
                        get {
-                               return backcolor;
+                               return backColor;
                        }
                        set {
-                               if (backcolor != value) {
-                                       backcolor = value;
-                                       Refresh ();
-                               }
+                               backColor = value;
                        }
                }
 
@@ -283,6 +320,8 @@ namespace System.Windows.Forms
                        }
                }
 
+               [Browsable(false)]
+               [EditorBrowsable(EditorBrowsableState.Never)]
                public Image BackgroundImage {
                        get {
                                return base.BackgroundImage;
@@ -293,17 +332,14 @@ namespace System.Windows.Forms
                        }
                }
 
+               [DispId(-504)]
+               [DefaultValue(BorderStyle.Fixed3D)]
                public BorderStyle BorderStyle {
-                       get {
-                               return border_style;
-                       }
-
-                       set {
-                                if (border_style != value) {
-                                       border_style = value;
-                                       OnBorderStyleChanged (EventArgs.Empty);
-                                       Refresh ();
-                               }
+                       get { return InternalBorderStyle; }
+                       set { 
+                               InternalBorderStyle = value; 
+                               CalcAreasAndInvalidate ();
+                               OnBorderStyleChanged (EventArgs.Empty);
                        }
                }
 
@@ -315,28 +351,29 @@ namespace System.Windows.Forms
                        set {
                                if (caption_backcolor != value) {
                                        caption_backcolor = value;
-
-                                       if (caption_visible) {
-                                               //TODO: Invalidate caption rect
-                                       }
+                                       grid_drawing.InvalidateCaption ();
                                }
                        }
                }
 
-
+               [Localizable(true)]
+               [AmbientValue(null)]
                public Font CaptionFont {
                        get {
+                               if (caption_font == null) {
+                                       return Font;
+                               }
+
                                return caption_font;
                        }
 
                        set {
-                               if (caption_font!= null && !caption_font.Equals (value)) {
-                                       caption_font = value;
-
-                                       if (caption_visible) {
-                                               //TODO: Invalidate caption rect
-                                       }
+                               if (caption_font != null && caption_font.Equals (value)) {
+                                       return;
                                }
+
+                               caption_font = value;
+                               CalcAreasAndInvalidate ();
                        }
                }
 
@@ -348,14 +385,13 @@ namespace System.Windows.Forms
                        set {
                                if (caption_forecolor != value) {
                                        caption_forecolor = value;
-
-                                       if (caption_visible) {
-                                               //TODO: Invalidate caption rect
-                                       }
+                                       grid_drawing.InvalidateCaption ();
                                }
                        }
                }
 
+               [Localizable(true)]
+               [DefaultValue("")]
                public string CaptionText {
                        get {
                                return caption_text;
@@ -364,14 +400,12 @@ namespace System.Windows.Forms
                        set {
                                if (caption_text != value) {
                                        caption_text = value;
-
-                                       if (caption_visible) {
-                                               //TODO: Invalidate caption rect
-                                       }
+                                       grid_drawing.InvalidateCaption ();
                                }
                        }
                }
 
+               [DefaultValue(true)]
                public bool CaptionVisible {
                        get {
                                return caption_visible;
@@ -380,12 +414,13 @@ namespace System.Windows.Forms
                        set {
                                if (caption_visible != value) {
                                        caption_visible = value;
+                                       CalcAreasAndInvalidate ();
                                        OnCaptionVisibleChanged (EventArgs.Empty);
-                                       Refresh ();
                                }
                        }
                }
 
+               [DefaultValue(true)]
                public bool ColumnHeadersVisible {
                        get {
                                return columnheaders_visible;
@@ -394,11 +429,13 @@ namespace System.Windows.Forms
                        set {
                                if (columnheaders_visible != value) {
                                        columnheaders_visible = value;
-                                       Refresh ();
+                                       CalcAreasAndInvalidate ();
                                }
                        }
                }
 
+               [Browsable(false)]
+               [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                public DataGridCell CurrentCell {
                        get {
                                return current_cell;
@@ -406,25 +443,57 @@ namespace System.Windows.Forms
 
                        set {
                                if (!current_cell.Equals (value)) {
-                                       current_cell = value;
-                                       Refresh ();
+                                       CancelEditing ();
+                                       
+                                       int old_row = current_cell.RowNumber;
+                                       
+                                       if (value.RowNumber >= RowsCount) {
+                                               value.RowNumber = RowsCount == 0 ? 0 : RowsCount - 1;
+                                       }
+                                       
+                                       if (value.ColumnNumber >= CurrentTableStyle.GridColumnStyles.Count) {
+                                               value.ColumnNumber = CurrentTableStyle.GridColumnStyles.Count == 0 ? 0: CurrentTableStyle.GridColumnStyles.Count - 1;
+                                       }
+                                       
+                                       EnsureCellVisilibility (value);
+                                       current_cell = value;                                   
+                                       
+                                       if (current_cell.RowNumber != old_row) {
+                                               grid_drawing.InvalidateRowHeader (old_row);
+                                       }
+                                       
+                                       accept_listmgrevents = false;
+
+                                       if (cached_currencymgr_events !=  null) {
+                                               cached_currencymgr_events.Position = current_cell.RowNumber;
+                                       }
+                                       accept_listmgrevents = true;
+                                       InvalidateCurrentRowHeader ();
+                                       OnCurrentCellChanged (EventArgs.Empty);
                                }
                        }
                }
 
+               [Browsable(false)]
+               [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                public int CurrentRowIndex {
                        get {
-                               return currentrow_index;
+                               if (ListManager == null) {
+                                       return -1;
+                               }
+                               
+                               return current_cell.RowNumber;
                        }
 
                        set {
-                               if (currentrow_index != value) {
-                                       currentrow_index = value;
-                                       Refresh ();
+                               if (current_cell.RowNumber != value) {
+                                       CurrentCell = new DataGridCell (value, current_cell.ColumnNumber);
                                }
                        }
                }
 
+               [Browsable(false)]
+               [EditorBrowsable(EditorBrowsableState.Never)]
                public override Cursor Cursor {
                        get {
                                return base.Cursor;
@@ -434,16 +503,28 @@ namespace System.Windows.Forms
                        }
                }
 
+               [DefaultValue(null)]
+               [Editor ("System.Windows.Forms.Design.DataMemberListEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
                public string DataMember {
                        get { return datamember; }
                        set {
-                               if (SetDataMember (datamember)) {
-                                       SetNewDataSource ();
-                                       Refresh ();
+                               if (SetDataMember (value)) {                                    
+                                       SetDataSource (datasource);
+                                       if (styles_collection.Contains (value) == true) {
+                                               CurrentTableStyle = styles_collection[value];
+                                               current_style.CreateColumnsForTable (true);
+                                       } else {
+                                               CurrentTableStyle = default_style;
+                                               current_style.GridColumnStyles.Clear ();
+                                               current_style.CreateColumnsForTable (false);
+                                       }                                       
                                }
                        }
                }
 
+               [DefaultValue(null)]
+               [RefreshProperties(RefreshProperties.Repaint)]
+               [TypeConverter("System.Windows.Forms.Design.DataSourceConverter, " + Consts.AssemblySystem_Design)]
                public object DataSource {
                        get {
                                return datasource;
@@ -451,8 +532,7 @@ namespace System.Windows.Forms
 
                        set {
                                if (SetDataSource (value)) {
-                                       SetNewDataSource ();
-                                       Refresh ();
+                                       SetNewDataSource ();                                    
                                }
                        }
                }
@@ -463,12 +543,14 @@ namespace System.Windows.Forms
                        }
                }
 
+               [Browsable(false)]
                public int FirstVisibleColumn {
                        get {
                                return firstvisible_column;
                        }
                }
 
+               [DefaultValue(false)]
                public bool FlatMode {
                        get {
                                return flatmode;
@@ -485,15 +567,11 @@ namespace System.Windows.Forms
 
                public Color ForeColor {
                        get {
-                               return forecolor;
+                               return base.ForeColor;
                        }
 
                        set {
-                               if (forecolor != value) {
-                                       forecolor = value;
-                                       OnForeColorChanged (EventArgs.Empty);
-                                       Refresh ();
-                               }
+                               base.ForeColor = value;
                        }
                }
 
@@ -503,6 +581,10 @@ namespace System.Windows.Forms
                        }
 
                        set {
+                               if (value == Color.Empty) {
+                                       throw new ArgumentException ("Color.Empty value is invalid.");
+                               }
+
                                if (gridline_color != value) {
                                        gridline_color = value;
                                        Refresh ();
@@ -510,6 +592,7 @@ namespace System.Windows.Forms
                        }
                }
 
+               [DefaultValue(DataGridLineStyle.Solid)]
                public DataGridLineStyle GridLineStyle {
                        get {
                                return gridline_style;
@@ -529,6 +612,10 @@ namespace System.Windows.Forms
                        }
 
                        set {
+                               if (value == Color.Empty) {
+                                       throw new ArgumentException ("Color.Empty value is invalid.");
+                               }
+
                                if (header_backcolor != value) {
                                        header_backcolor = value;
                                        Refresh ();
@@ -544,7 +631,7 @@ namespace System.Windows.Forms
                        set {
                                if (header_font != null && !header_font.Equals (value)) {
                                        header_font = value;
-                                       Refresh ();
+                                       CalcAreasAndInvalidate ();
                                }
                        }
                }
@@ -564,27 +651,29 @@ namespace System.Windows.Forms
 
                protected ScrollBar HorizScrollBar {
                        get {
-                               throw new NotImplementedException ();
+                               return horiz_scrollbar;
                        }
                }
 
                public object this [DataGridCell cell] {
                        get  {
-                               throw new NotImplementedException ();
+                               return this [cell.RowNumber, cell.ColumnNumber];
                        }
 
                        set {
-                               throw new NotImplementedException ();
+                               this [cell.RowNumber, cell.ColumnNumber] = value;
                        }
                }
 
                public object this [int rowIndex, int columnIndex] {
                        get  {
-                               throw new NotImplementedException ();
+                               return CurrentTableStyle.GridColumnStyles[columnIndex].GetColumnValueAtRow (ListManager,
+                                       rowIndex);
                        }
 
                        set {
-                               throw new NotImplementedException ();
+                               CurrentTableStyle.GridColumnStyles[columnIndex].SetColumnValueAtRow (ListManager,
+                                       rowIndex, value);
                        }
                }
 
@@ -601,6 +690,8 @@ namespace System.Windows.Forms
                }
 
                [ComVisible(false)]
+               [Browsable(false)]
+               [EditorBrowsable(EditorBrowsableState.Never)]
                public Color LinkHoverColor {
                        get {
                                return link_hovercolor;
@@ -614,13 +705,24 @@ namespace System.Windows.Forms
                        }
                }
 
+               [Browsable(false)]
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected internal CurrencyManager ListManager {
                        get {
-                               if (BindingContext == null) {
+                               if (BindingContext == null || DataSource  == null) {
                                        return null;
                                }
-                               
-                               return (CurrencyManager) BindingContext [DataSource, DataMember];
+
+                               if (cached_currencymgr != null) {
+                                       return cached_currencymgr;
+                               }
+
+                               // If we bind real_datasource object we do not get the events from ListManger
+                               // since the object is not the datasource and does not match
+                               cached_currencymgr = (CurrencyManager) BindingContext [real_datasource, DataMember];
+                               cached_currencymgr_events = (CurrencyManager) BindingContext [datasource, DataMember];
+                               ConnectListManagerEvents ();
+                               return cached_currencymgr;
                        }
 
                        set {
@@ -658,6 +760,8 @@ namespace System.Windows.Forms
                        }
                }
 
+               [DefaultValue(DataGridParentRowsLabelStyle.Both)]
+               [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                public DataGridParentRowsLabelStyle ParentRowsLabelStyle {
                        get {
                                return parentrowslabel_style;
@@ -669,10 +773,13 @@ namespace System.Windows.Forms
                                        if (parentrows_visible) {
                                                Refresh ();
                                        }
+
+                                       OnParentRowsLabelStyleChanged (EventArgs.Empty);
                                }
                        }
                }
 
+               [DefaultValue(true)]
                public bool ParentRowsVisible {
                        get {
                                return parentrows_visible;
@@ -681,18 +788,25 @@ namespace System.Windows.Forms
                        set {
                                if (parentrows_visible != value) {
                                        parentrows_visible = value;
+                                       CalcAreasAndInvalidate ();
                                        OnParentRowsVisibleChanged (EventArgs.Empty);
-                                       Refresh ();
                                }
                        }
                }
 
+               // Settting this property seems to have no effect.
+               [DefaultValue(75)]
+               [TypeConverter(typeof(DataGridPreferredColumnWidthTypeConverter))]
                public int PreferredColumnWidth {
                        get {
                                return preferredcolumn_width;
                        }
 
                        set {
+                               if (value < 0) {
+                                       throw new ArgumentException ("PreferredColumnWidth is less than 0");
+                               }
+
                                if (preferredcolumn_width != value) {
                                        preferredcolumn_width = value;
                                        Refresh ();
@@ -708,11 +822,12 @@ namespace System.Windows.Forms
                        set {
                                if (preferredrow_height != value) {
                                        preferredrow_height = value;
-                                       Refresh ();
+                                       CalcAreasAndInvalidate ();
                                }
                        }
                }
 
+               [DefaultValue(false)]
                public bool ReadOnly {
                        get {
                                return _readonly;
@@ -722,11 +837,12 @@ namespace System.Windows.Forms
                                if (_readonly != value) {
                                        _readonly = value;
                                        OnReadOnlyChanged (EventArgs.Empty);
-                                       Refresh ();
+                                       CalcAreasAndInvalidate ();
                                }
                        }
                }
 
+               [DefaultValue(true)]
                public bool RowHeadersVisible {
                        get {
                                return rowheaders_visible;
@@ -735,11 +851,12 @@ namespace System.Windows.Forms
                        set {
                                if (rowheaders_visible != value) {
                                        rowheaders_visible = value;
-                                       Refresh ();
+                                       CalcAreasAndInvalidate ();
                                }
                        }
                }
 
+               [DefaultValue(35)]
                public int RowHeaderWidth {
                        get {
                                return rowheaders_width;
@@ -748,7 +865,7 @@ namespace System.Windows.Forms
                        set {
                                if (rowheaders_width != value) {
                                        rowheaders_width = value;
-                                       Refresh ();
+                                       CalcAreasAndInvalidate ();
                                }
                        }
                }
@@ -788,10 +905,16 @@ namespace System.Windows.Forms
                        }
                }
 
+               [Localizable(true)]
+               [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                public GridTableStylesCollection TableStyles {
                        get { return styles_collection; }
                }
 
+               [Bindable(false)]
+               [Browsable(false)]
+               [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+               [EditorBrowsable(EditorBrowsableState.Never)]
                public override string Text {
                        get {
                                return base.Text;
@@ -801,19 +924,23 @@ namespace System.Windows.Forms
                        }
                }
 
+               [Browsable(false)]
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected ScrollBar VertScrollBar {
                        get {
-                               throw new NotImplementedException ();
+                               return vert_scrollbar;
                        }
                }
 
+               [Browsable(false)]
                public int VisibleColumnCount {
                        get {
                                return visiblecolumn_count;
                        }
-
                }
 
+               // Calculated at DataGridDrawing.CalcRowsHeaders
+               [Browsable(false)]
                public int VisibleRowCount {
                        get {
                                return visiblerow_count;
@@ -822,24 +949,95 @@ namespace System.Windows.Forms
 
                #endregion      // Public Instance Properties
 
+               #region Private Instance Properties
+               internal DataGridTableStyle CurrentTableStyle {
+                       get {
+                               return current_style;
+                       }
+                       set {
+                               current_style = value;
+                               current_style.DataGrid = this;
+                               CalcAreasAndInvalidate ();
+                       }
+               }
+
+               internal int FirstVisibleRow {
+                       get { return first_visiblerow; }
+                       set { first_visiblerow = value;}
+               }
+               
+               internal int RowsCount {
+                       get {                           
+                               if (ListManager != null) {
+                                       return ListManager.Count;                                       
+                               }
+
+                               return 0;
+                       }
+               }
+
+               internal int RowHeight {
+                       get {
+                               if (CurrentTableStyle.CurrentPreferredRowHeight > Font.Height + 3 + 1 /* line */) {
+                                       return CurrentTableStyle.CurrentPreferredRowHeight;
+
+                               } else {
+                                       return Font.Height + 3 + 1 /* line */;
+                               }
+                       }
+               }
+               
+               internal bool ShowEditRow {
+                       get {
+                               if (ListManager != null && ListManager.CanAddRows == false) {
+                                       return false;
+                               }
+                                                               
+                               return _readonly == false;
+                       }
+               }
+               
+               // It should only be shown if there are relations that
+               // we do not support right now
+               internal bool ShowParentRowsVisible {
+                       get {
+                               //See parentrows_visible;
+                               return false;
+                       }
+               }
+               
+               #endregion Private Instance Properties
+
                #region Public Instance Methods
 
+               [MonoTODO]
                public virtual bool BeginEdit (DataGridColumnStyle gridColumn, int rowNumber)
                {
-                       throw new NotImplementedException ();
+                       return false;
                }
 
                public virtual void BeginInit ()
                {
-
+                       begininit = true;
                }
 
-
                protected virtual void CancelEditing ()
-               {
-
+               {                       
+                       if (current_cell.ColumnNumber < CurrentTableStyle.GridColumnStyles.Count) {
+                               CurrentTableStyle.GridColumnStyles[current_cell.ColumnNumber].Abort (current_cell.RowNumber);
+                       }
+                       
+                       if (is_adding == true) {
+                               ListManager.RemoveAt (RowsCount - 1);
+                               is_adding = false;
+                       }
+                       
+                       is_editing = false;
+                       is_changing = false;
+                       InvalidateCurrentRowHeader ();
                }
 
+               [MonoTODO]
                public void Collapse (int row)
                {
 
@@ -863,12 +1061,12 @@ namespace System.Windows.Forms
                protected virtual DataGridColumnStyle CreateGridColumn (PropertyDescriptor prop)
                {
                        return CreateGridColumn (prop, false);
-               }               
+               }
 
                protected virtual DataGridColumnStyle CreateGridColumn (PropertyDescriptor prop, bool isDefault)
                {
-                       throw new NotImplementedException ();
-               }               
+                       throw new NotImplementedException();
+               }
 
                protected override void Dispose (bool disposing)
                {
@@ -876,13 +1074,32 @@ namespace System.Windows.Forms
                }
 
                public virtual bool EndEdit (DataGridColumnStyle gridColumn, int rowNumber, bool shouldAbort)
-               {
-                       throw new NotImplementedException ();
+               {                                               
+                       if (is_adding == true) {                                
+                               if (shouldAbort) {
+                                       ListManager.CancelCurrentEdit ();
+                               } else {
+                                       ListManager.EndCurrentEdit ();
+                                       CalcAreasAndInvalidate ();
+                               }
+                               is_adding = false;
+                       } 
+
+                       if (shouldAbort || gridColumn.ParentReadOnly ==true) {
+                               gridColumn.Abort (rowNumber);
+                       } else {
+                               gridColumn.Commit (ListManager, rowNumber);
+                       }
+
+                       is_editing = false;
+                       is_changing = false;
+                       InvalidateCurrentRowHeader ();
+                       return true;
                }
 
                public virtual void EndInit ()
                {
-
+                       begininit = false;
                }
 
                public void Expand (int row)
@@ -890,61 +1107,76 @@ namespace System.Windows.Forms
 
                }
 
-               public Rectangle GetCellBounds (DataGridCell dgc)
+               public Rectangle GetCellBounds (DataGridCell cell)
                {
-                       throw new NotImplementedException ();
+                       return GetCellBounds (cell.RowNumber, cell.ColumnNumber);
                }
 
                public Rectangle GetCellBounds (int row, int col)
                {
-                       throw new NotImplementedException ();
+                       return grid_drawing.GetCellBounds (row, col);
                }
 
                public Rectangle GetCurrentCellBounds ()
                {
-                       throw new NotImplementedException ();
+                       return GetCellBounds (current_cell.RowNumber, current_cell.ColumnNumber);
                }
 
                protected virtual string GetOutputTextDelimiter ()
                {
-                       throw new NotImplementedException ();
+                       return string.Empty;
                }
 
                protected virtual void GridHScrolled (object sender, ScrollEventArgs se)
                {
+                       if (se.NewValue == horz_pixeloffset ||
+                               se.Type == ScrollEventType.EndScroll) {
+                               return;
+                       }
 
+                       ScrollToColumnInPixels (se.NewValue);
                }
 
                protected virtual void GridVScrolled (object sender, ScrollEventArgs se)
                {
-
+                       int old_first_visiblerow = first_visiblerow;
+                       first_visiblerow = se.NewValue;
+                       grid_drawing.UpdateVisibleRowCount ();
+                       
+                       if (first_visiblerow == old_first_visiblerow) {
+                               return;
+                       }                       
+                       ScrollToRow (old_first_visiblerow, first_visiblerow);
                }
 
                public HitTestInfo HitTest (Point position)
                {
-                       throw new NotImplementedException ();
+                       return HitTest (position.X, position.Y);
                }
 
                public HitTestInfo HitTest (int x, int y)
                {
-                       throw new NotImplementedException ();
+                       return grid_drawing.HitTest (x, y);
                }
 
+               [MonoTODO]
                public bool IsExpanded (int rowNumber)
                {
-                       throw new NotImplementedException ();
+                       return false;
                }
 
                public bool IsSelected (int row)
                {
-                       throw new NotImplementedException ();
+                       return selected_rows[row] != null;
                }
 
+               [MonoTODO]
                public void NavigateBack ()
                {
 
                }
 
+               [MonoTODO]
                public void NavigateTo (int rowNumber, string relationName)
                {
 
@@ -1023,6 +1255,7 @@ namespace System.Windows.Forms
 
                protected override void OnFontChanged (EventArgs e)
                {
+                       grid_drawing.CalcGridAreas ();
                        base.OnFontChanged (e);
                }
 
@@ -1034,6 +1267,7 @@ namespace System.Windows.Forms
                protected override void OnHandleCreated (EventArgs e)
                {
                        base.OnHandleCreated (e);
+                       grid_drawing.CalcGridAreas ();
                }
 
                protected override void OnHandleDestroyed (EventArgs e)
@@ -1044,6 +1278,13 @@ namespace System.Windows.Forms
                protected override void OnKeyDown (KeyEventArgs ke)
                {
                        base.OnKeyDown (ke);
+                       
+                       if (ProcessGridKey (ke) == true) {
+                               ke.Handled = true;
+                       }
+
+                       CurrentTableStyle.GridColumnStyles[current_cell.ColumnNumber].OnKeyDown
+                               (ke, current_cell.RowNumber, current_cell.ColumnNumber);
                }
 
                protected override void OnKeyPress (KeyPressEventArgs kpe)
@@ -1064,6 +1305,47 @@ namespace System.Windows.Forms
                protected override void OnMouseDown (MouseEventArgs e)
                {
                        base.OnMouseDown (e);
+
+                       HitTestInfo testinfo;
+                       testinfo = grid_drawing.HitTest (e.X, e.Y);
+
+                       switch (testinfo.type) {
+                       case HitTestType.Cell:
+                       {
+                               DataGridCell new_cell = new DataGridCell (testinfo.Row, testinfo.Column);
+
+                               if (new_cell.Equals (current_cell) == false) {
+                                       CancelEditing ();
+                                       CurrentCell = new_cell;
+                                       EditCell (current_cell);
+
+                               } else {
+                                       CurrentTableStyle.GridColumnStyles[testinfo.Column].OnMouseDown (e, testinfo.Row, testinfo.Column);
+                               }
+
+                               break;
+                       }
+                       case HitTestType.RowHeader:
+                       {
+                               if (ctrl_pressed == false && shift_pressed == false) {
+                                       ResetSelection (); // Invalidates selected rows
+                               }
+
+                               if (shift_pressed == true) {
+                                       ShiftSelection (testinfo.Row);
+                               } else { // ctrl_pressed or single item
+                                       Select (testinfo.Row);
+                               }
+
+                               CancelEditing ();
+                               CurrentCell = new DataGridCell (testinfo.Row, current_cell.ColumnNumber);
+                               OnRowHeaderClick (EventArgs.Empty);
+                               break;
+                       }                       
+                       
+                       default:
+                               break;
+                       }
                }
 
                protected override void OnMouseLeave (EventArgs e)
@@ -1084,6 +1366,17 @@ namespace System.Windows.Forms
                protected override void OnMouseWheel (MouseEventArgs e)
                {
                        base.OnMouseWheel (e);
+
+                       if (e.Delta > 0) {
+                               if (current_cell.RowNumber > 0) {
+                                       CurrentCell = new DataGridCell (current_cell.RowNumber - 1, current_cell.ColumnNumber);
+                               }
+                       }
+                       else {
+                               if (current_cell.RowNumber < RowsCount - 1) {
+                                       CurrentCell = new DataGridCell (current_cell.RowNumber + 1, current_cell.ColumnNumber);                                 
+                               }
+                       }
                }
 
                protected void OnNavigate (NavigateEventArgs e)
@@ -1095,14 +1388,14 @@ namespace System.Windows.Forms
 
                protected override void OnPaint (PaintEventArgs pe)
                {
-                       base.OnPaint (pe);
+                       ThemeEngine.Current.DataGridPaint (pe, this);
                }
 
                protected override void OnPaintBackground (PaintEventArgs ebe)
                {
                        base.OnPaintBackground (ebe);
                }
-               
+
                protected virtual void OnParentRowsLabelStyleChanged (EventArgs e)
                {
                        if (ParentRowsLabelStyleChanged != null) {
@@ -1154,20 +1447,118 @@ namespace System.Windows.Forms
                {
                        return base.ProcessDialogKey (keyData);
                }
-               
+
                protected bool ProcessGridKey (KeyEventArgs ke)
                {
-                       throw new NotImplementedException ();
+                       if (RowsCount == 0) {
+                               return false;
+                       }
+
+                       switch (ke.KeyCode) {
+                       case Keys.ControlKey:
+                               ctrl_pressed = true;
+                               break;
+                       case Keys.ShiftKey:
+                               shift_pressed = true;
+                               break;
+                       case Keys.Up:
+                       {
+                               if (current_cell.RowNumber > 0) {
+                                       CurrentCell = new DataGridCell (current_cell.RowNumber - 1, current_cell.ColumnNumber);
+                                       EditCell (current_cell);
+                               }
+                               break;
+                       }
+                       case Keys.Down:
+                       {
+                               if (current_cell.RowNumber < RowsCount - 1) {
+                                       CurrentCell = new DataGridCell (current_cell.RowNumber + 1, current_cell.ColumnNumber);
+                                       EditCell (current_cell);
+                               }
+                               break;
+                       }
+                       case Keys.Tab:
+                       case Keys.Right:
+                       {                               
+                               if (current_cell.ColumnNumber + 1 < CurrentTableStyle.GridColumnStyles.Count) {
+                                       CurrentCell = new DataGridCell (current_cell.RowNumber, current_cell.ColumnNumber + 1);
+                                       EditCell (current_cell);
+                               }
+                               break;
+                       }
+                       case Keys.Left:
+                       {
+                               if (current_cell.ColumnNumber > 0) {
+                                       CurrentCell = new DataGridCell (current_cell.RowNumber, current_cell.ColumnNumber - 1);
+                                       EditCell (current_cell);
+                               }
+                               break;
+                       }
+                       case Keys.PageUp:
+                       {
+                               if (current_cell.RowNumber > grid_drawing.VLargeChange) {
+                                       CurrentCell = new DataGridCell (current_cell.RowNumber - grid_drawing.VLargeChange, current_cell.ColumnNumber);
+                               } else {
+                                       CurrentCell = new DataGridCell (0, current_cell.ColumnNumber);
+                               }
+
+                               EditCell (current_cell);
+                               break;
+                       }
+                       case Keys.PageDown:
+                       {
+                               if (current_cell.RowNumber + grid_drawing.VLargeChange < RowsCount) {
+                                       CurrentCell = new DataGridCell (current_cell.RowNumber + grid_drawing.VLargeChange, current_cell.ColumnNumber);
+                               } else {
+                                       CurrentCell = new DataGridCell (RowsCount - 1, current_cell.ColumnNumber);
+                               }
+
+                               EditCell (current_cell);
+                               break;
+                       }
+                       case Keys.Home:
+                       {
+                               CurrentCell = new DataGridCell (0, current_cell.ColumnNumber);
+                               EditCell (current_cell);
+                               break;
+                       }
+                       case Keys.End:
+                       {
+                               CurrentCell = new DataGridCell (RowsCount - 1, current_cell.ColumnNumber);
+                               EditCell (current_cell);
+                               break;
+                       }
+                       case Keys.Delete:
+                       {                               
+                               foreach (int row in selected_rows.Keys) {
+                                       ListManager.RemoveAt (row);                                             
+                               }
+                               selected_rows.Clear ();
+                               CalcAreasAndInvalidate ();
+                               break;                                  
+                       }
+                       default:
+                               return false; // message not processed
+                       }
+
+                       return true; // message processed
                }
-               
+
+               // Called from DataGridTextBox
                protected override bool ProcessKeyPreview (ref Message m)
                {
+                       Keys key = (Keys) m.WParam.ToInt32 ();
+                       KeyEventArgs ke = new KeyEventArgs (key);
+                       if (ProcessGridKey (ke) == true) {
+                               return true;
+                       }
+
                        return base.ProcessKeyPreview (ref m);
                }
                
                protected bool ProcessTabKey (Keys keyData)
                {
-                       throw new NotImplementedException ();
+                       return false;
                }
 
                public void ResetAlternatingBackColor ()
@@ -1177,7 +1568,7 @@ namespace System.Windows.Forms
 
                public override void ResetBackColor ()
                {
-                       background_color = def_background_color;
+                       backColor = ThemeEngine.Current.DataGridBackColor;
                }
 
                public override void ResetForeColor ()
@@ -1216,8 +1607,13 @@ namespace System.Windows.Forms
                }
 
                protected void ResetSelection ()
-               {
+               {                       
+                       foreach (int row in selected_rows.Keys) {
+                               grid_drawing.InvalidateRow (row);
+                               grid_drawing.InvalidateRowHeader (row);
+                       }
 
+                       selected_rows.Clear ();
                }
 
                public void ResetSelectionBackColor ()
@@ -1232,15 +1628,24 @@ namespace System.Windows.Forms
 
                public void Select (int row)
                {
+                       if (selected_rows[row] == null) {
+                               selected_rows.Add (row, true);
+                       } else {
+                               selected_rows[row] = true;
+                       }
 
+                       grid_drawing.InvalidateRow (row);
                }
 
                public void SetDataBinding (object dataSource, string dataMember)
                {
-                       if (SetDataSource (dataSource) == false  && SetDataMember (dataMember) == false) {
+                       bool source = SetDataSource (dataSource);
+                       bool member = SetDataMember (dataMember);
+                       
+                       if (source == false  && member == false) {
                                return;
                        }
-                       
+
                        SetNewDataSource ();
                }
 
@@ -1301,7 +1706,7 @@ namespace System.Windows.Forms
 
                protected bool ShouldSerializePreferredRowHeight ()
                {
-                       return (parentrowsfore_color != def_parentrowsfore_color);
+                       return (preferredrow_height != def_preferredrow_height);
                }
 
                protected bool ShouldSerializeSelectionBackColor ()
@@ -1321,75 +1726,351 @@ namespace System.Windows.Forms
 
                public void UnSelect (int row)
                {
+                       selected_rows.Remove (row);
+                       grid_drawing.InvalidateRow (row);
 
                }
                #endregion      // Public Instance Methods
 
                #region Private Instance Methods
+
+               internal void CalcAreasAndInvalidate ()
+               {
+                       grid_drawing.CalcGridAreas ();
+                       Invalidate ();
+               }
+               
+               private void ConnectListManagerEvents ()
+               {
+                       cached_currencymgr_events.CurrentChanged += new EventHandler (OnListManagerCurrentChanged);                     
+               }
                
+               private void DisconnectListManagerEvents ()
+               {
+                       
+               }
 
-               private bool SetDataMember (string member)
+               // EndEdit current editing operation
+               internal virtual bool EndEdit (bool shouldAbort)
+               {
+                       return EndEdit (CurrentTableStyle.GridColumnStyles[current_cell.ColumnNumber],
+                               current_cell.RowNumber, shouldAbort);
+               }
+
+               private void EnsureCellVisilibility (DataGridCell cell)
+               {
+                       if (cell.ColumnNumber <= first_visiblecolumn ||
+                               cell.ColumnNumber + 1 >= first_visiblecolumn + visiblecolumn_count) {                   
+                                       
+                               first_visiblecolumn = grid_drawing.GetFirstColumnForColumnVisilibility (first_visiblecolumn, cell.ColumnNumber);                                                
+                               
+                               int pixel = grid_drawing.GetColumnStartingPixel (first_visiblecolumn);
+                               ScrollToColumnInPixels (pixel);
+                       }
+
+                       if (cell.RowNumber < first_visiblerow ||
+                               cell.RowNumber + 1 >= first_visiblerow + visiblerow_count) {
+
+                               if (cell.RowNumber + 1 >= first_visiblerow + visiblerow_count) {
+                                       int old_first_visiblerow = first_visiblerow;
+                                       first_visiblerow = 1 + cell.RowNumber - visiblerow_count;
+                                       grid_drawing.UpdateVisibleRowCount ();
+                                       ScrollToRow (old_first_visiblerow, first_visiblerow);
+                               }else {
+                                       int old_first_visiblerow = first_visiblerow;
+                                       first_visiblerow = cell.RowNumber;
+                                       grid_drawing.UpdateVisibleRowCount ();
+                                       ScrollToRow (old_first_visiblerow, first_visiblerow);
+                               }
+
+                               vert_scrollbar.Value = first_visiblerow;
+                       }
+               }
+               
+               internal IEnumerable GetDataSource (object source, string member)
+               {       
+                       IListSource src = (IListSource) source;
+                       IList list = src.GetList();
+                       IListSource listsource;
+                       ITypedList typedlist;
+                                       
+                       if (source is IEnumerable) {
+                               return (IEnumerable) source;
+                       }
+                       
+                       if(src.ContainsListCollection == false) {
+                               return list;
+                       }
+                       
+                       listsource = (IListSource) source;
+                       
+                       if (listsource == null) {
+                               return null;
+                       }
+                       
+                       list = src.GetList ();
+                       
+                       if (list == null) {
+                               return null;
+                       }
+                       
+                       typedlist = (ITypedList) list;
+                               
+                       if (typedlist == null) {
+                               return null;
+                       }                       
+
+                       PropertyDescriptorCollection col = typedlist.GetItemProperties (new PropertyDescriptor [0]);
+                       PropertyDescriptor prop = col.Find (member, true);
+                                                               
+                       if (prop == null) {
+                               if (col.Count > 0) {
+                                       prop = col[0];
+
+                                       if (prop == null) {
+                                               return null;
+                                       }
+                               }
+                       }
+                       
+                       IEnumerable result =  (IEnumerable)(prop.GetValue (list[0]));
+                       return result;          
+                       
+               }
+
+               internal void InvalidateCurrentRowHeader ()
                {
+                       grid_drawing.InvalidateRowHeader (current_cell.RowNumber);
+               }
+
+               private bool SetDataMember (string member)
+               {                       
                        if (member == datamember) {
                                return false;
                        }
 
                        datamember = member;
+                       real_datasource = GetDataSource (datasource, member);
+                       DisconnectListManagerEvents ();
+                       cached_currencymgr = cached_currencymgr_events = null;
                        return true;
                }
 
                private bool SetDataSource (object source)
-               {
-                       if (datasource != null && datasource.Equals (source)) {
-                               return false;
-                       }
+               {                       
 
                        if (source != null && source as IListSource != null && source as IList != null) {
                                throw new Exception ("Wrong complex data binding source");
                        }
-
+                       
+                       current_cell = new DataGridCell ();
                        datasource = source;
+                       DisconnectListManagerEvents ();
+                       cached_currencymgr = cached_currencymgr_events = null;
+                       try {
+                               real_datasource = GetDataSource (datasource, DataMember);
+                       }catch (Exception e) {                          
+                               real_datasource = source;
+                       }
+
                        OnDataSourceChanged (EventArgs.Empty);
                        return true;
                }
-               
+
                private void SetNewDataSource ()
+               {                               
+                       current_style.GridColumnStyles.Clear ();
+                       current_style.CreateColumnsForTable (false);
+                       CalcAreasAndInvalidate ();                      
+               }
+
+               private void OnKeyUpDG (object sender, KeyEventArgs e)
                {
-                       // Create Table Style 
-                       // Create columns Styles
-                       // Bind data
+                       switch (e.KeyCode) {
+                       case Keys.ControlKey:
+                               ctrl_pressed = false;
+                               break;
+                       case Keys.ShiftKey:
+                               shift_pressed = false;
+                               break;
+                       default:
+                               break;
+                       }
+               }
+               
+               private void OnListManagerCurrentChanged (object sender, EventArgs e)
+               {                       
+                       if (accept_listmgrevents == false) {
+                               return;
+                       }
                        
+                       CurrentCell = new DataGridCell (cached_currencymgr_events.Position, current_cell.RowNumber);
                }
-                               
+               
                private void OnTableStylesCollectionChanged (object sender, CollectionChangeEventArgs e)
+               {       
+                       if (ListManager != null && String.Compare (ListManager.ListName, ((DataGridTableStyle)e.Element).MappingName, true) == 0) {                     
+                               CurrentTableStyle = (DataGridTableStyle)e.Element;
+                               ((DataGridTableStyle) e.Element).CreateColumnsForTable (false);                         
+                       }
+                                               
+                       CalcAreasAndInvalidate ();
+               }
+
+               private void EditCell (DataGridCell cell)
                {
-                       Console.WriteLine ("Datagrid.TableStyles Collection Changed {0}, null {1}", e.Action,
-                               e.Element == null);
-                       /* 
-                               TODO: What's up if there are columns in the incoming TableStyle
-                       */
+                       ResetSelection (); // Invalidates selected rows
+                       is_editing = false;
+                       is_changing = false;
                        
-                       switch (e.Action)  {
-                               case CollectionChangeAction.Add: {
-                                       ((DataGridTableStyle) e.Element).CreateColumnsForTable ();
-                                       break;
-                               }
-                               case CollectionChangeAction.Remove:
-                                       break;
-                               case CollectionChangeAction.Refresh:
-                                       break;
-                                       
-                               default:
-                                       break;
+                       if (ShowEditRow && is_adding == false && cell.RowNumber >= RowsCount) {
+                               ListManager.AddNew ();
+                               is_adding = true;
+                               Invalidate (); // We have just added a new row
                        }
                        
+                       CurrentTableStyle.GridColumnStyles[cell.ColumnNumber].Edit (ListManager,
+                               cell.RowNumber, GetCellBounds (cell.RowNumber, cell.ColumnNumber),
+                               _readonly, string.Empty, true);
                }
-               
-               private void SetCurrentStyle (DataGridTableStyle style)
+
+               private void ShiftSelection (int index)
+               {
+                       int shorter_item = -1, dist = RowsCount + 1, cur_dist;                  
+
+                       foreach (int row in selected_rows.Keys) {
+
+                               if (row > index) {
+                                       cur_dist = row - index;
+                               }
+                               else {
+                                       cur_dist = index - row;
+                               }
+
+                               if (cur_dist < dist) {
+                                       dist = cur_dist;
+                                       shorter_item = row;
+                               }
+                       }
+
+                       if (shorter_item != -1) {
+                               int start, end;
+
+                               if (shorter_item > index) {
+                                       start = index;
+                                       end = shorter_item;
+                               } else {
+                                       start = shorter_item;
+                                       end = index;
+                               }
+
+                               ResetSelection ();
+                               for (int idx = start; idx <= end; idx++) {
+                                       Select (idx);
+                               }
+                       }
+               }
+
+               private void ScrollToColumnInPixels (int pixel)
+               {
+                       Rectangle invalidate = new Rectangle ();
+                       Rectangle invalidate_column = new Rectangle ();
+
+                       if (pixel > horz_pixeloffset) { // ScrollRight
+                               int pixels = pixel - horz_pixeloffset;
+                               
+                               horz_pixeloffset = horiz_scrollbar.Value = pixel;
+                               grid_drawing.UpdateVisibleColumn ();
+
+                               // Columns header
+                               invalidate_column.X = grid_drawing.ColumnsHeadersArea.X + grid_drawing.ColumnsHeadersArea.Width - pixels;
+                               invalidate_column.Y = grid_drawing.ColumnsHeadersArea.Y;
+                               invalidate_column.Width = pixels;
+                               invalidate_column.Height = grid_drawing.ColumnsHeadersArea.Height;
+                               XplatUI.ScrollWindow (Handle, grid_drawing.ColumnsHeadersArea, -pixels, 0, false);
+
+                               // Cells
+                               invalidate.X = grid_drawing.CellsArea.X + grid_drawing.CellsArea.Width - pixels;
+                               invalidate.Y = grid_drawing.CellsArea.Y;
+                               invalidate.Width = pixels;
+                               invalidate.Height = grid_drawing.CellsArea.Height;
+                               
+                               
+                               if (columnheaders_visible == true) {
+                                       invalidate.Y -= grid_drawing.ColumnsHeadersArea.Height;
+                                       invalidate.Height += grid_drawing.ColumnsHeadersArea.Height;
+                               }
+                               
+                               XplatUI.ScrollWindow (Handle, grid_drawing.CellsArea, -pixels, 0, false);
+                               Invalidate (invalidate_column);
+                               Invalidate (invalidate);
+
+
+                       } else {
+                               int pixels = horz_pixeloffset - pixel;
+                               Rectangle area = grid_drawing.CellsArea;
+                               
+                               horz_pixeloffset = horiz_scrollbar.Value = pixel;
+                               grid_drawing.UpdateVisibleColumn ();
+
+                               // Columns header
+                               invalidate_column.X = grid_drawing.ColumnsHeadersArea.X;
+                               invalidate_column.Y = grid_drawing.ColumnsHeadersArea.Y;
+                               invalidate_column.Width = pixels;
+                               invalidate_column.Height = grid_drawing.ColumnsHeadersArea.Height;
+                               //XplatUI.ScrollWindow (Handle, grid_drawing.ColumnsHeadersArea, pixels, 0, false);
+
+                               // Cells
+                               invalidate.X =  grid_drawing.CellsArea.X;
+                               invalidate.Y =  grid_drawing.CellsArea.Y;
+                               invalidate.Width = pixels;
+                               invalidate.Height = grid_drawing.CellsArea.Height;
+                               
+                               if (columnheaders_visible == true) {
+                                       invalidate.Y -= grid_drawing.ColumnsHeadersArea.Height;
+                                       invalidate.Height += grid_drawing.ColumnsHeadersArea.Height;
+                                       area.Y -= grid_drawing.ColumnsHeadersArea.Height;
+                                       area.Height += grid_drawing.ColumnsHeadersArea.Height;
+                               }
+                               
+                               XplatUI.ScrollWindow (Handle, area, pixels, 0, false);
+                               Invalidate (invalidate);
+                       }               
+                       
+               }
+
+               private void ScrollToRow (int old_row, int new_row)
                {
-                       default_style = style;
+                       Rectangle invalidate = new Rectangle ();                        
+                       
+                       if (new_row > old_row) { // Scrolldown
+                               int scrolled_rows = new_row - old_row;
+                               int pixels = scrolled_rows * RowHeight;
+                               Rectangle rows_area = grid_drawing.CellsArea; // Cells area - partial rows space
+                               rows_area.Height = grid_drawing.CellsArea.Height - grid_drawing.CellsArea.Height % RowHeight;
+                               
+                               invalidate.X =  grid_drawing.CellsArea.X;
+                               invalidate.Y =  grid_drawing.CellsArea.Y + rows_area.Height - pixels;
+                               invalidate.Width = grid_drawing.CellsArea.Width;
+                               invalidate.Height = pixels;
+
+                               XplatUI.ScrollWindow (Handle, rows_area, 0, -pixels, false);
+
+                       } else { // ScrollUp
+                               int scrolled_rows = old_row - new_row;                          
+                               int pixels = scrolled_rows * RowHeight;
+
+                               invalidate.X =  grid_drawing.CellsArea.X;
+                               invalidate.Y =  grid_drawing.CellsArea.Y;
+                               invalidate.Width = grid_drawing.CellsArea.Width;
+                               invalidate.Height = pixels;
+                               XplatUI.ScrollWindow (Handle, grid_drawing.CellsArea, 0, pixels, false);                                
+                       }
+
+                       // Right now we use ScrollWindow Invalidate, let's leave remarked it here for X11 if need it
+                       //Invalidate (invalidate);
+                       Invalidate (grid_drawing.RowsHeadersArea);
                }
-               
 
                #endregion Private Instance Methods
 
@@ -1398,11 +2079,19 @@ namespace System.Windows.Forms
                public event EventHandler AllowNavigationChanged;
                public event EventHandler BackButtonClick;
                public event EventHandler BackgroundColorChanged;
+
+               [Browsable(false)]
+               [EditorBrowsable(EditorBrowsableState.Never)]
                public new event EventHandler BackgroundImageChanged;
+
                public event EventHandler BorderStyleChanged;
                public event EventHandler CaptionVisibleChanged;
                public event EventHandler CurrentCellChanged;
+
+               [Browsable(false)]
+               [EditorBrowsable(EditorBrowsableState.Never)]
                public new event EventHandler CursorChanged;
+
                public event EventHandler DataSourceChanged;
                public event EventHandler FlatModeChanged;
                public event NavigateEventHandler Navigate;
@@ -1412,6 +2101,9 @@ namespace System.Windows.Forms
                protected event EventHandler RowHeaderClick;
                public event EventHandler Scroll;
                public event EventHandler ShowParentDetailsButtonClick;
+
+               [Browsable(false)]
+               [EditorBrowsable(EditorBrowsableState.Never)]
                public new event EventHandler TextChanged;
                #endregion      // Events
        }