2006-03-21 Alexander Olk <alex.olk@googlemail.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / DataGridView.cs
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 // 
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 // 
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 //
20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
21 //
22 // Author:
23 //      Pedro Martínez Juliá <pedromj@gmail.com>
24 //
25
26
27 #if NET_2_0
28
29 using System;
30 using System.ComponentModel;
31 using System.Runtime.InteropServices;
32 using System.Drawing;
33 using System.Collections;
34
35 namespace System.Windows.Forms {
36
37         [ComVisibleAttribute(true)]
38         [ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
39         public class DataGridView : Control, ISupportInitialize {
40
41                 private DataGridViewAdvancedBorderStyle adjustedTopLeftHeaderBorderStyle;
42                 private DataGridViewAdvancedBorderStyle advancedCellBorderStyle;
43                 private DataGridViewAdvancedBorderStyle advancedColumnHeadersBorderStyle;
44                 private DataGridViewAdvancedBorderStyle advancedRowHeadersBorderStyle;
45                 private bool allowUserToAddRows;
46                 private bool allowUserToDeleteRows;
47                 private bool allowUserToOrderColumns;
48                 private bool allowUserToResizeColumns;
49                 private bool allowUserToResizeRows;
50                 private DataGridViewCellStyle alternatingRowsDefaultCellStyle;
51                 private bool autoGenerateColumns;
52                 private bool autoSize;
53                 private DataGridViewAutoSizeColumnsMode autoSizeColumnsMode;
54                 private DataGridViewAutoSizeRowsMode autoSizeRowsMode;
55                 private Color backColor;
56                 private Color backgroundColor;
57                 private Image backgroundImage;
58                 private ImageLayout backgroundImageLayout;
59                 private BorderStyle borderStyle;
60                 private DataGridViewCellBorderStyle cellBorderStyle;
61                 private DataGridViewClipboardCopyMode clipboardCopyMode;
62                 private DataGridViewHeaderBorderStyle columnHeadersBorderStyle;
63                 private DataGridViewCellStyle columnHeadersDefaultCellStyle;
64                 private int columnHeadersHeight;
65                 private DataGridViewColumnHeadersHeightSizeMode columnHeadersHeightSizeMode;
66                 private bool columnHeadersVisible;
67                 private DataGridViewColumnCollection columns;
68                 private DataGridViewCell currentCell;
69                 private Point currentCellAddress;
70                 private DataGridViewRow currentRow;
71                 private string dataMember;
72                 private object dataSource;
73                 private DataGridViewCellStyle defaultCellStyle;
74                 private Control editingControl;
75                 private DataGridViewEditMode editMode;
76                 private bool enableHeadersVisualStyles;
77                 private DataGridViewCell firstDisplayedCell;
78                 private int firstDisplayedScrollingColumnHiddenWidth;
79                 private int firstDisplayedScrollingColumnIndex;
80                 private int firstDisplayedScrollingRowIndex;
81                 private Font font = Control.DefaultFont;
82                 private Color foreColor = Control.DefaultForeColor;
83                 private Color gridColor = Color.FromKnownColor(KnownColor.ControlDarkDark);
84                 private int horizontalScrollingOffset;
85                 private bool isCurrentCellDirty;
86                 private bool isCurrentRowDirty;
87                 private bool multiSelect;
88                 private bool readOnly;
89                 private DataGridViewHeaderBorderStyle rowHeadersBorderStyle;
90                 private DataGridViewCellStyle rowHeadersDefaultCellStyle;
91                 private bool rowHeadersVisible;
92                 private int rowHeadersWidth;
93                 private DataGridViewRowHeadersWidthSizeMode rowHeadersWidthSizeMode;
94                 private DataGridViewRowCollection rows;
95                 private DataGridViewCellStyle rowsDefaultCellStyle;
96                 private DataGridViewRow rowTemplate;
97                 private ScrollBars scrollBars;
98                 private DataGridViewSelectionMode selectionMode;
99                 private bool showCellErrors;
100                 private bool showCellToolTips;
101                 private bool showEditingIcon;
102                 private bool showRowErrors;
103                 private DataGridViewColumn sortedColumn = null;
104                 private SortOrder sortOrder;
105                 private bool standardTab;
106                 private string text;
107                 private DataGridViewHeaderCell topLeftHeaderCell;
108                 private Cursor userSetCursor;
109                 private int verticalScrollingOffset;
110                 private bool virtualMode;
111                 private Size defaultSize;
112                 private HScrollBar horizontalScrollBar;
113                 private VScrollBar verticalScrollBar;
114
115                 internal int gridWidth;
116                 internal int gridHeight;
117
118                 public DataGridView () {
119                         adjustedTopLeftHeaderBorderStyle = new DataGridViewAdvancedBorderStyle();
120                         adjustedTopLeftHeaderBorderStyle.All = DataGridViewAdvancedCellBorderStyle.Single;
121                         advancedCellBorderStyle = new DataGridViewAdvancedBorderStyle();
122                         advancedCellBorderStyle.All = DataGridViewAdvancedCellBorderStyle.Single;
123                         advancedColumnHeadersBorderStyle = new DataGridViewAdvancedBorderStyle();
124                         advancedColumnHeadersBorderStyle.All = DataGridViewAdvancedCellBorderStyle.Single;
125                         advancedRowHeadersBorderStyle = new DataGridViewAdvancedBorderStyle();
126                         advancedRowHeadersBorderStyle.All = DataGridViewAdvancedCellBorderStyle.Single;
127                         alternatingRowsDefaultCellStyle = new DataGridViewCellStyle();
128                         allowUserToAddRows = true;
129                         allowUserToDeleteRows = true;
130                         allowUserToOrderColumns = false;
131                         allowUserToResizeColumns = true;
132                         allowUserToResizeRows = true;
133                         autoGenerateColumns = true;
134                         autoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
135                         autoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
136                         backColor = Control.DefaultBackColor;
137                         backgroundColor = SystemColors.AppWorkspace;
138                         borderStyle = BorderStyle.FixedSingle;
139                         cellBorderStyle = DataGridViewCellBorderStyle.None;
140                         clipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithAutoHeaderText;
141                         columnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
142                         columnHeadersDefaultCellStyle = new DataGridViewCellStyle();
143                         columnHeadersDefaultCellStyle.BackColor = SystemColors.Control;
144                         columnHeadersDefaultCellStyle.ForeColor = SystemColors.WindowText;
145                         columnHeadersDefaultCellStyle.SelectionBackColor = SystemColors.Highlight;
146                         columnHeadersDefaultCellStyle.SelectionForeColor = SystemColors.HighlightText;
147                         columnHeadersDefaultCellStyle.Font = this.Font;
148                         columnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
149                         columnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.True;
150                         columnHeadersHeight = 23;
151                         columnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
152                         columnHeadersVisible = true;
153                         columns = CreateColumnsInstance();
154                         columns.CollectionChanged += OnColumnCollectionChanged;
155                         dataMember = String.Empty;
156                         defaultCellStyle = (DataGridViewCellStyle) columnHeadersDefaultCellStyle.Clone();
157                         editMode = DataGridViewEditMode.EditOnKeystrokeOrF2;
158                         multiSelect = true;
159                         readOnly = false;
160                         rowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
161                         rowHeadersDefaultCellStyle = (DataGridViewCellStyle) defaultCellStyle.Clone();
162                         rowHeadersVisible = true;
163                         rowHeadersWidth = 43;
164                         rowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.EnableResizing;
165                         rows = CreateRowsInstance();
166                         rowsDefaultCellStyle = new DataGridViewCellStyle();
167                         selectionMode = DataGridViewSelectionMode.RowHeaderSelect;
168                         showCellErrors = true;
169                         showEditingIcon = true;
170                         userSetCursor = Cursor.Current;
171                         virtualMode = false;
172
173                         horizontalScrollBar = new HScrollBar();
174                         horizontalScrollBar.Dock = DockStyle.Bottom;
175                         horizontalScrollBar.Scroll += OnHScrollBarScroll;
176                         horizontalScrollBar.Visible = false;
177                         verticalScrollBar = new VScrollBar();
178                         verticalScrollBar.Dock = DockStyle.Right;
179                         verticalScrollBar.Scroll += OnVScrollBarScroll;
180                         verticalScrollBar.Visible = false;
181                 }
182
183                 public void BeginInit () {
184                 }
185
186                 public void EndInit () {
187                 }
188
189                 // Propiedades
190
191                 public virtual DataGridViewAdvancedBorderStyle AdjustedTopLeftHeaderBorderStyle {
192                         get { return adjustedTopLeftHeaderBorderStyle; }
193                 }
194
195                 public DataGridViewAdvancedBorderStyle AdvancedCellBorderStyle {
196                         get { return advancedCellBorderStyle; }
197                 }
198
199                 public DataGridViewAdvancedBorderStyle AdvancedColumnHeadersBorderStyle {
200                         get { return advancedColumnHeadersBorderStyle; }
201                 }
202
203                 public DataGridViewAdvancedBorderStyle AdvancedRowHeadersBorderStyle {
204                         get { return advancedRowHeadersBorderStyle; }
205                 }
206
207                 public bool AllowUserToAddRows {
208                         get { return allowUserToAddRows; }
209                         set {
210                                 if (allowUserToAddRows != value) {
211                                         allowUserToAddRows = value;
212                                         OnAllowUserToAddRowsChanged(EventArgs.Empty);
213                                 }
214                         }
215                 }
216
217                 public bool AllowUserToDeleteRows {
218                         get { return allowUserToDeleteRows; }
219                         set {
220                                 if (allowUserToDeleteRows != value) {
221                                         allowUserToDeleteRows = value;
222                                         OnAllowUserToDeleteRowsChanged(EventArgs.Empty);
223                                 }
224                         }
225                 }
226
227                 public bool AllowUserToOrderColumns {
228                         get { return allowUserToOrderColumns; }
229                         set {
230                                 if (allowUserToOrderColumns != value) {
231                                         allowUserToOrderColumns = value;
232                                         OnAllowUserToOrderColumnsChanged(EventArgs.Empty);
233                                 }
234                         }
235                 }
236
237                 public bool AllowUserToResizeColumns {
238                         get { return allowUserToResizeColumns; }
239                         set {
240                                 if (allowUserToResizeColumns != value) {
241                                         allowUserToResizeColumns = value;
242                                         OnAllowUserToResizeColumnsChanged(EventArgs.Empty);
243                                 }
244                         }
245                 }
246
247                 public bool AllowUserToResizeRows {
248                         get { return allowUserToResizeRows; }
249                         set {
250                                 if (allowUserToResizeRows != value) {
251                                         allowUserToResizeRows = value;
252                                         OnAllowUserToResizeRowsChanged(EventArgs.Empty);
253                                 }
254                         }
255                 }
256
257                 public DataGridViewCellStyle AlternatingRowsDefaultCellStyle {
258                         get { return alternatingRowsDefaultCellStyle; }
259                         set {
260                                 if (alternatingRowsDefaultCellStyle != value) {
261                                         alternatingRowsDefaultCellStyle = value;
262                                         OnAlternatingRowsDefaultCellStyleChanged(EventArgs.Empty);
263                                         Invalidate();
264                                 }
265                         }
266                 }
267
268                 public bool AutoGenerateColumns {
269                         get { return autoGenerateColumns; }
270                         set {
271                                 if (autoGenerateColumns != value) {
272                                         autoGenerateColumns = value;
273                                         OnAutoGenerateColumnsChanged(EventArgs.Empty);
274                                 }
275                         }
276                 }
277
278                 //public override bool AutoSize {
279                 public bool AutoSize {
280                         get { return autoSize; }
281                         set {
282                                 if (autoSize != value) {
283                                         autoSize = value;
284                                         //OnAutoSizeChanged(EventArgs.Empty);
285                                 }
286                         }
287                 }
288
289                 public DataGridViewAutoSizeColumnsMode AutoSizeColumnsMode {
290                         get { return autoSizeColumnsMode; }
291                         set {
292                                 if (!Enum.IsDefined(typeof(DataGridViewAutoSizeColumnsMode), value)) {
293                                         throw new InvalidEnumArgumentException("Value is not valid DataGridViewAutoSizeColumnsMode.");
294                                 }
295                                 if (value == DataGridViewAutoSizeColumnsMode.ColumnHeader && columnHeadersVisible == false) {
296                                         foreach (DataGridViewColumn col in columns) {
297                                                 if (col.AutoSizeMode == DataGridViewAutoSizeColumnMode.NotSet) {
298                                                                 throw new InvalidOperationException("Cant set this property to ColumnHeader in this DataGridView.");
299                                                 }
300                                         }
301                                 }
302                                 if (value == DataGridViewAutoSizeColumnsMode.Fill) {
303                                         foreach (DataGridViewColumn col in columns) {
304                                                 if (col.AutoSizeMode == DataGridViewAutoSizeColumnMode.NotSet) {
305                                                         if (col.Frozen) {
306                                                                 throw new InvalidOperationException("Cant set this property to Fill in this DataGridView.");
307                                                         }
308                                                 }
309                                         }
310                                 }
311                                 autoSizeColumnsMode = value;
312                         }
313                 }
314
315                 public DataGridViewAutoSizeRowsMode AutoSizeRowsMode {
316                         get { return autoSizeRowsMode; }
317                         set {
318                                 if (autoSizeRowsMode != value) {
319                                         if (!Enum.IsDefined(typeof(DataGridViewAutoSizeRowsMode), value)) {
320                                                 throw new InvalidEnumArgumentException("Value is not valid DataGridViewRowsMode.");
321                                         }
322                                         if ((value == DataGridViewAutoSizeRowsMode.AllHeaders || value == DataGridViewAutoSizeRowsMode.DisplayedHeaders) && rowHeadersVisible == false) {
323                                                 throw new InvalidOperationException("Cant set this property to AllHeaders or DisplayedHeaders in this DataGridView.");
324                                         }
325                                         autoSizeRowsMode = value;
326                                         OnAutoSizeRowsModeChanged(new DataGridViewAutoSizeModeEventArgs(false));
327                                         ////////////////////////////////////////////////////////////////
328                                 }
329                         }
330                 }
331
332                 public override Color BackColor {
333                         get { return backColor; }
334                         set {
335                                 if (backColor != value) {
336                                         backColor = value;
337                                         OnBackColorChanged(EventArgs.Empty);
338                                 }
339                         }
340                 }
341
342                 public Color BackgroundColor {
343                         get { return backgroundColor; }
344                         set {
345                                 if (backgroundColor != value) {
346                                         if (value == Color.Empty) {
347                                                 throw new ArgumentException("Cant set an Empty color.");
348                                         }
349                                         backgroundColor = value;
350                                         OnBackgroundColorChanged(EventArgs.Empty);
351                                 }
352                         }
353                 }
354
355                 public override Image BackgroundImage {
356                         get { return backgroundImage; }
357                         set {
358                                 if (backgroundImage != value) {
359                                         backgroundImage = value;
360                                         OnBackgroundImageChanged(EventArgs.Empty);
361                                 }
362                         }
363                 }
364
365                 //public override ImageLayout BackgroundImageLayout {
366                 public ImageLayout BackgroundImageLayout {
367                         get { return backgroundImageLayout; }
368                         set {
369                                 if (backgroundImageLayout != value) {
370                                         backgroundImageLayout = value;
371                                         //OnBackgroundImageLayoutChanged(EventArg.Empty);
372                                 }
373                         }
374                 }
375
376                 public BorderStyle BorderStyle {
377                         get { return borderStyle; }
378                         set {
379                                 if (borderStyle != value) {
380                                         if (!Enum.IsDefined(typeof(BorderStyle), value)) {
381                                                 throw new InvalidEnumArgumentException("Invalid border style.");
382                                         }
383                                         borderStyle = value;
384                                         OnBorderStyleChanged(EventArgs.Empty);
385                                 }
386                         }
387                 }
388
389                 public DataGridViewCellBorderStyle CellBorderStyle {
390                         get { return cellBorderStyle; }
391                         set {
392                                 if (cellBorderStyle != value) {
393                                         cellBorderStyle = value;
394                                         OnCellBorderStyleChanged(EventArgs.Empty);
395                                 }
396                         }
397                 }
398
399                 public DataGridViewClipboardCopyMode ClipboardCopyMode {
400                         get { return clipboardCopyMode; }
401                         set { clipboardCopyMode = value; }
402                 }
403
404                 public int ColumnCount {
405                         get { return columns.Count; }
406                         set {
407                                 if (value < 0) {
408                                         throw new ArgumentException("ColumnCount must be >= 0.");
409                                 }
410                                 if (dataSource != null) {
411                                         throw new InvalidOperationException("Cant change column count if DataSource is set.");
412                                 }
413                                 if (value < columns.Count) {
414                                         for (int i = value; i < columns.Count; i++) {
415                                                 columns.RemoveAt(i);
416                                         }
417                                 }
418                                 else if (value > columns.Count) {
419                                         for (int i = 0; i < value; i++) {
420                                                 DataGridViewColumn col = new DataGridViewColumn();
421                                                 columns.Add(col);
422                                         }
423                                 }
424                         }
425                 }
426
427                 public DataGridViewHeaderBorderStyle ColumnHeadersBorderStyle {
428                         get { return columnHeadersBorderStyle; }
429                         set {
430                                 if (columnHeadersBorderStyle != value) {
431                                         columnHeadersBorderStyle = value;
432                                         OnColumnHeadersBorderStyleChanged(EventArgs.Empty);
433                                 }
434                         }
435                 }
436
437                 public DataGridViewCellStyle ColumnHeadersDefaultCellStyle {
438                         get { return columnHeadersDefaultCellStyle; }
439                         set {
440                                 if (columnHeadersDefaultCellStyle != value) {
441                                         columnHeadersDefaultCellStyle = value;
442                                         OnColumnHeadersDefaultCellStyleChanged(EventArgs.Empty);
443                                 }
444                         }
445                 }
446
447                 public int ColumnHeadersHeight {
448                         get { return columnHeadersHeight; }
449                         set {
450                                 if (columnHeadersHeight != value) {
451                                         if (value < 4) {
452                                                 throw new ArgumentException("Column headers height cant be less than 4.");
453                                         }
454                                         columnHeadersHeight = value;
455                                         OnColumnHeadersHeightChanged(EventArgs.Empty);
456                                 }
457                         }
458                 }
459
460                 public DataGridViewColumnHeadersHeightSizeMode ColumnHeadersHeightSizeMode {
461                         get { return columnHeadersHeightSizeMode; }
462                         set {
463                                 if (columnHeadersHeightSizeMode != value) {
464                                         if (!Enum.IsDefined(typeof(DataGridViewColumnHeadersHeightSizeMode), value)) {
465                                                 throw new InvalidEnumArgumentException("Value is not a valid DataGridViewColumnHeadersHeightSizeMode.");
466                                         }
467                                         columnHeadersHeightSizeMode = value;
468                                         OnColumnHeadersHeightSizeModeChanged(new DataGridViewAutoSizeModeEventArgs(false));
469                                 }
470                         }
471                 }
472
473                 public bool ColumnHeadersVisible {
474                         get { return columnHeadersVisible; }
475                         set { columnHeadersVisible = value; }
476                 }
477
478                 public DataGridViewColumnCollection Columns {
479                         get { return columns; }
480                 }
481
482                 public DataGridViewCell CurrentCell {
483                         get { return currentCell; }
484                         set {
485                                 /////////////////////////////////////////////////////
486                                 /// *** InvalidOperationException ***
487                                 /// Changes to the specified cell cannot be committed
488                                 /// to the data cache, or the new cell is in a hidden
489                                 /// row.
490                                 /////////////////////////////////////////////////////
491                                 if (value.DataGridView != this) {
492                                         throw new ArgumentException("The cell is not in this DataGridView.");
493                                 }
494                                 currentCell = value;
495                         }
496                 }
497
498                 public Point CurrentCellAddress {
499                         get { return currentCellAddress; }
500                 }
501
502                 public DataGridViewRow CurrentRow {
503                         get { return currentRow; }
504                 }
505
506                 public string DataMember {
507                         get { return dataMember; }
508                         set {
509                                 if (dataMember != value) {
510                                         dataMember = value;
511                                         OnDataMemberChanged(EventArgs.Empty);
512                                 }
513                         }
514                 }
515
516                 public object DataSource {
517                         get { return dataSource; }
518                         set {
519                                 if (dataSource != value) {
520                                         /* The System.Windows.Forms.DataGridView class supports the standard Windows Forms data-binding model. This means the data source can be of any type that implements:
521                                          - the System.Collections.IList interface, including one-dimensional arrays.
522                                          - the System.ComponentModel.IListSource interface, such as the System.Data.DataTable and System.Data.DataSet classes.
523                                          - the System.ComponentModel.IBindingList interface, such as the System.ComponentModel.Collections.BindingList<> class.
524                                          - the System.ComponentModel.IBindingListView interface, such as the System.Windows.Forms.BindingSource class.
525                                         */
526                                         if (!(value is IList) && !(value is IListSource) && !(value is IBindingList) && !(value is IBindingListView)) {
527                                                 throw new NotSupportedException("Type cant be binded.");
528                                         }
529                                         dataSource = value;
530                                         OnDataSourceChanged(EventArgs.Empty);
531                                         // DataBinding
532                                         if (value is IList) {
533                                                 BindIList(value as IList);
534                                         }
535                                         else if (value is IListSource) {
536                                                 BindIListSource(value as IListSource);
537                                         }
538                                         else if (value is IBindingList) {
539                                                 BindIBindingList(value as IBindingList);
540                                         }
541                                         else if (value is IBindingListView) {
542                                                 BindIBindingListView(value as IBindingListView);
543                                                 //bool cosa = ((value as IBindingListView).SortDescriptions as IList).IsFixedSize;
544                                         }
545                                         OnDataBindingComplete(new DataGridViewBindingCompleteEventArgs(ListChangedType.Reset));
546                                 }
547                         }
548                 }
549
550                 public DataGridViewCellStyle DefaultCellStyle {
551                         get { return defaultCellStyle; }
552                         set {
553                                 if (defaultCellStyle != value) {
554                                         defaultCellStyle = value;
555                                         OnDefaultCellStyleChanged(EventArgs.Empty);
556                                 }
557                         }
558                 }
559
560                 public override Rectangle DisplayRectangle {
561                         get { return base.DisplayRectangle; }
562                 }
563
564                 public Control EditingControl {
565                         get {
566                                 if (currentCell == null || !currentCell.IsInEditMode) {
567                                         return null;
568                                 }
569                                 return (Control) Activator.CreateInstance(currentCell.EditType);
570                         }
571                 }
572
573                 public Panel EditingPanel {
574                         get { throw new NotImplementedException(); }
575                 }
576
577                 public DataGridViewEditMode EditMode {
578                         get { return editMode; }
579                         set {
580                                 if (editMode != value) {
581                                         editMode = value;
582                                         OnEditModeChanged(EventArgs.Empty);
583                                 }
584                         }
585                 }
586
587                 public bool EnableHeadersVisualStyles {
588                         get { return enableHeadersVisualStyles; }
589                         set { enableHeadersVisualStyles = value; }
590                 }
591
592                 public DataGridViewCell FirstDisplayedCell {
593                         get { return firstDisplayedCell; }
594                         set {
595                                 if (value.DataGridView != this) {
596                                         throw new ArgumentException("The cell is not in this DataGridView.");
597                                 }
598                                 firstDisplayedCell = value;
599                         }
600                 }
601
602                 public int FirstDisplayedScrollingColumnHiddenWidth {
603                         get { return firstDisplayedScrollingColumnHiddenWidth; }
604                 }
605
606                 public int FirstDisplayedScrollingColumnIndex {
607                         get { return firstDisplayedScrollingColumnIndex; }
608                         set { firstDisplayedScrollingColumnIndex = value; }
609                 }
610
611                 public int FirstDisplayedScrollingRowIndex {
612                         get { return firstDisplayedScrollingRowIndex; }
613                         set { firstDisplayedScrollingRowIndex = value; }
614                 }
615
616                 public override Font Font {
617                         get { return font; }
618                         set {
619                                 if (font != value) {
620                                         font = value;
621                                         OnFontChanged(EventArgs.Empty);
622                                 }
623                         }
624                 }
625
626                 public override Color ForeColor {
627                         get { return foreColor; }
628                         set {
629                                 if (foreColor != value) {
630                                         foreColor = value;
631                                         OnForeColorChanged(EventArgs.Empty);
632                                 }
633                         }
634                 }
635
636                 public Color GridColor {
637                         get { return gridColor; }
638                         set {
639                                 if (gridColor != value) {
640                                         if (value == Color.Empty) {
641                                                 throw new ArgumentException("Cant set an Empty color.");
642                                         }
643                                         gridColor = value;
644                                         OnGridColorChanged(EventArgs.Empty);
645                                 }
646                         }
647                 }
648
649                 public int HorizontalScrollingOffset {
650                         get { return horizontalScrollingOffset; }
651                         set { horizontalScrollingOffset = value; }
652                 }
653
654                 public bool IsCurrentCellDirty {
655                         get { return isCurrentCellDirty; }
656                 }
657
658                 public bool IsCurrentCellInEditMode {
659                         get {
660                                 if (currentCell == null) {
661                                         return false;
662                                 }
663                                 return currentCell.IsInEditMode;
664                         }
665                 }
666
667                 public bool IsCurrentRowDirty {
668                         get {
669                                 if (!virtualMode) {
670                                         return IsCurrentCellDirty;
671                                 }
672                                 // Calcular
673                                 throw new NotImplementedException();
674                         }
675                 }
676
677                 public DataGridViewCell this [int columnIndex, int rowIndex] {
678                         get { return rows[rowIndex].Cells[columnIndex]; }
679                         set { rows[rowIndex].Cells[columnIndex] = value; }
680                 }
681
682                 public DataGridViewCell this [string columnName, int rowIndex] {
683                         get {
684                                 int columnIndex = -1;
685                                 foreach (DataGridViewColumn col in columns) {
686                                         if (col.Name == columnName) {
687                                                 columnIndex = col.Index;
688                                                 break;
689                                         }
690                                 }
691                                 return this[columnIndex, rowIndex];
692                         }
693                         set {
694                                 int columnIndex = -1;
695                                 foreach (DataGridViewColumn col in columns) {
696                                         if (col.Name == columnName) {
697                                                 columnIndex = col.Index;
698                                                 break;
699                                         }
700                                 }
701                                 this[columnIndex, rowIndex] = value;
702                         }
703                 }
704
705                 public bool MultiSelect {
706                         get { return multiSelect; }
707                         set {
708                                 if (multiSelect != value) {
709                                         multiSelect = value;
710                                         OnMultiSelectChanged(EventArgs.Empty);
711                                 }
712                         }
713                 }
714
715                 public int NewRowIndex {
716                         get {
717                                 if (!allowUserToAddRows) {
718                                         return -1;
719                                 }
720                                 return rows.Count - 1;
721                         }
722                 }
723
724                 public new Padding Padding {
725                         get { return Padding.Empty; }
726                         set { }
727                 }
728
729                 public bool ReadOnly {
730                         get { return readOnly; }
731                         set {
732                                 if (readOnly != value) {
733                                         readOnly = value;
734                                         OnReadOnlyChanged(EventArgs.Empty);
735                                 }
736                         }
737                 }
738
739                 public int RowCount {
740                         get { return rows.Count; }
741                         set {
742                                 if (value < 0) {
743                                         throw new ArgumentException("RowCount must be >= 0.");
744                                 }
745                                 if (value < 1 && allowUserToAddRows) {
746                                         throw new ArgumentException("RowCount must be >= 1 if AllowUserToAddRows is true.");
747                                 }
748                                 if (dataSource != null) {
749                                         throw new InvalidOperationException("Cant change row count if DataSource is set.");
750                                 }
751                                 if (value < rows.Count) {
752                                         for (int i = value; i < rows.Count; i++) {
753                                                 rows.RemoveAt(i);
754                                         }
755                                 }
756                                 else if (value > rows.Count) {
757                                         for (int i = 0; i < value; i++) {
758                                                 // DataGridViewRow row = new DataGridViewRow(); //(DataGridViewRow) rowTemplate.Clone();
759                                                 DataGridViewRow row = (DataGridViewRow) rowTemplate.Clone();
760                                                 rows.Add(row);
761                                                 foreach (DataGridViewColumn col in columns) {
762                                                         row.Cells.Add(col.CellTemplate.Clone() as DataGridViewCell);
763                                                 }
764                                         }
765                                 }
766                                 if (ColumnCount == 0) {
767                                         ///////////////////////////////////////////////////////////////
768                                         //columns.Add(new DataGridViewTextBoxColumn());
769                                         throw new NotImplementedException();
770                                 }
771                         }
772                 }
773
774                 public DataGridViewHeaderBorderStyle RowHeadersBorderStyle {
775                         get { return rowHeadersBorderStyle; }
776                         set {
777                                 if (rowHeadersBorderStyle != value) {
778                                         rowHeadersBorderStyle = value;
779                                         OnRowHeadersBorderStyleChanged(EventArgs.Empty);
780                                 }
781                         }
782                 }
783
784                 public DataGridViewCellStyle RowHeadersDefaultCellStyle {
785                         get { return rowHeadersDefaultCellStyle; }
786                         set {
787                                 if (rowHeadersDefaultCellStyle != value) {
788                                         rowHeadersDefaultCellStyle = value;
789                                         OnRowHeadersDefaultCellStyleChanged(EventArgs.Empty);
790                                 }
791                         }
792                 }
793
794                 public bool RowHeadersVisible {
795                         get { return rowHeadersVisible; }
796                         set { rowHeadersVisible = value; }
797                 }
798
799                 public int RowHeadersWidth {
800                         get { return rowHeadersWidth; }
801                         set {
802                                 if (rowHeadersWidth != value) {
803                                         if (value < 4) {
804                                                 throw new ArgumentException("RowHeadersWidth cant be less than 4.");
805                                         }
806                                         rowHeadersWidth = value;
807                                         OnRowHeadersWidthChanged(EventArgs.Empty);
808                                 }
809                         }
810                 }
811
812                 public DataGridViewRowHeadersWidthSizeMode RowHeadersWidthSizeMode {
813                         get { return rowHeadersWidthSizeMode; }
814                         set {
815                                 if (rowHeadersWidthSizeMode != value) {
816                                         if (!Enum.IsDefined(typeof(DataGridViewRowHeadersWidthSizeMode), value)) {
817                                                 throw new InvalidEnumArgumentException("Value is not valid DataGridViewRowHeadersWidthSizeMode.");
818                                         }
819                                         rowHeadersWidthSizeMode = value;
820                                         OnRowHeadersWidthSizeModeChanged(new DataGridViewAutoSizeModeEventArgs(false));
821                                 }
822                         }
823                 }
824
825                 public DataGridViewRowCollection Rows {
826                         get { return rows; }
827                 }
828
829                 public DataGridViewCellStyle RowsDefaultCellStyle {
830                         get { return rowsDefaultCellStyle; }
831                         set {
832                                 if (rowsDefaultCellStyle != value) {
833                                         rowsDefaultCellStyle = value;
834                                         OnRowsDefaultCellStyleChanged(EventArgs.Empty);
835                                 }
836                         }
837                 }
838
839                 public DataGridViewRow RowTemplate {
840                         get {
841                                 if (rowTemplate == null) {
842                                         return new DataGridViewRow();
843                                 }
844                                 return rowTemplate;
845                         }
846                         set {
847                                 rowTemplate = value;
848                                 rowTemplate.SetDataGridView(this);
849                         }
850                 }
851
852                 public ScrollBars ScrollBars {
853                         get { return scrollBars; }
854                         set {
855                                 if (!Enum.IsDefined(typeof(ScrollBars), value)) {
856                                         throw new InvalidEnumArgumentException("Invalid ScrollBars value.");
857                                 }
858                                 ////////////////////////////////////////////////////////////
859                                 /// *** InvalidOperationException ***
860                                 /// The System.Windows.Forms.DataGridView is unable to
861                                 /// scroll due to a cell change that cannot be committed
862                                 /// or canceled.
863                                 ///////////////////////////////////////////////////////////
864                                 scrollBars = value;
865                         }
866                 }
867
868                 public DataGridViewSelectedCellCollection SelectedCells {
869                         get {
870                                 DataGridViewSelectedCellCollection selectedCells = new DataGridViewSelectedCellCollection();
871                                 foreach (DataGridViewRow row in rows) {
872                                         foreach (DataGridViewCell cell in row.Cells) {
873                                                 if (cell.Selected) {
874                                                         selectedCells.InternalAdd(cell);
875                                                 }
876                                         }
877                                 }
878                                 return selectedCells;
879                         }
880                 }
881
882                 public DataGridViewSelectedColumnCollection SelectedColumns {
883                         get {
884                                 DataGridViewSelectedColumnCollection selectedColumns = new DataGridViewSelectedColumnCollection();
885                                 if (selectionMode == DataGridViewSelectionMode.FullColumnSelect || selectionMode == DataGridViewSelectionMode.ColumnHeaderSelect) {
886                                         foreach (DataGridViewColumn col in columns) {
887                                                 if (col.Selected) {
888                                                         selectedColumns.InternalAdd(col);
889                                                 }
890                                         }
891                                 }
892                                 return selectedColumns;
893                         }
894                 }
895
896                 public DataGridViewSelectedRowCollection SelectedRows {
897                         get {
898                                 DataGridViewSelectedRowCollection selectedRows = new DataGridViewSelectedRowCollection();
899                                 if (selectionMode == DataGridViewSelectionMode.FullColumnSelect || selectionMode == DataGridViewSelectionMode.RowHeaderSelect) {
900                                         foreach (DataGridViewRow row in rows) {
901                                                 if (row.Selected) {
902                                                         selectedRows.InternalAdd(row);
903                                                 }
904                                         }
905                                 }
906                                 return selectedRows;
907                         }
908                 }
909
910                 public DataGridViewSelectionMode SelectionMode {
911                         get { return selectionMode; }
912                         set {
913                                 if (!Enum.IsDefined(typeof(DataGridViewSelectionMode), value)) {
914                                         throw new InvalidEnumArgumentException("Value is not valid DataGridViewSelectionMode.");
915                                 }
916                                 selectionMode = value;
917                         }
918                 }
919
920                 public bool ShowCellErrors {
921                         get { return showCellErrors; }
922                         set { showCellErrors = value; }
923                 }
924
925                 public bool ShowCellToolTips {
926                         get { return showCellToolTips; }
927                         set { showCellToolTips = value; }
928                 }
929
930                 public bool ShowEditingIcon {
931                         get { return showEditingIcon; }
932                         set { showEditingIcon = value; }
933                 }
934
935                 public bool ShowRowErrors {
936                         get { return showRowErrors; }
937                         set { showRowErrors = value; }
938                 }
939
940                 public DataGridViewColumn SortedColumn {
941                         get { return sortedColumn; }
942                 }
943
944                 public SortOrder SortOrder {
945                         get { return sortOrder; }
946                 }
947
948                 public bool StandardTab {
949                         get { return standardTab; }
950                         set { standardTab = value; }
951                 }
952
953                 public override string Text {
954                         get { return text; }
955                         set { text = value; }
956                 }
957
958                 public DataGridViewHeaderCell TopLeftHeaderCell {
959                         get { return topLeftHeaderCell; }
960                         set { topLeftHeaderCell = value; }
961                 }
962
963                 public Cursor UserSetCursor {
964                         get { return userSetCursor; }
965                 }
966
967                 public int VerticalScrollingOffset {
968                         get { return verticalScrollingOffset; }
969                 }
970
971                 public bool VirtualMode {
972                         get { return virtualMode; }
973                         set { virtualMode = value; }
974                 }
975
976                 public event EventHandler AllowUserToAddRowsChanged;
977
978                 public event EventHandler AllowUserToDeleteRowsChanged;
979
980                 public event EventHandler AllowUserToOrderColumnsChanged;
981
982                 public event EventHandler AllowUserToResizeColumnsChanged;
983
984                 public event EventHandler AllowUserToResizeRowsChanged;
985
986                 public event EventHandler AlternatingRowsDefaultCellStyleChanged;
987
988                 public event EventHandler AutoGenerateColumnsChanged;
989
990                 public new event EventHandler AutoSizeChanged;
991
992                 public event DataGridViewAutoSizeColumnModeEventHandler AutoSizeColumnModeChanged;
993
994                 public event DataGridViewAutoSizeColumnsModeEventHandler AutoSizeColumnsModeChanged;
995
996                 public event DataGridViewAutoSizeModeEventHandler AutoSizeRowsModeChanged;
997
998                 public new event EventHandler BackColorChanged;
999
1000                 public event EventHandler BackgroundColorChanged;
1001
1002                 public new event EventHandler BackgroundImageChanged;
1003
1004                 public new event EventHandler BackgroundImageLayoutChanged;
1005
1006                 public event EventHandler BorderStyleChanged;
1007
1008                 public event QuestionEventHandler CancelRowEdit;
1009
1010                 public event DataGridViewCellCancelEventHandler CellBeginEdit;
1011
1012                 public event EventHandler CellBorderStyleChanged;
1013
1014                 public event DataGridViewCellEventHandler CellClick;
1015
1016                 public event DataGridViewCellEventHandler CellContentClick;
1017
1018                 public event DataGridViewCellEventHandler CellContentDoubleClick;
1019
1020                 public event DataGridViewCellEventHandler CellContextMenuStripChanged;
1021
1022                 public event DataGridViewCellContextMenuStripNeededEventHandler CellContextMenuStripNeeded;
1023
1024                 public event DataGridViewCellEventHandler CellDoubleClick;
1025
1026                 public event DataGridViewCellEventHandler CellEndEdit;
1027
1028                 public event DataGridViewCellEventHandler CellEnter;
1029
1030                 public event DataGridViewCellEventHandler CellErrorTextChanged;
1031
1032                 public event DataGridViewCellErrorTextNeededEventHandler CellErrorTextNeeded;
1033
1034                 public event DataGridViewCellFormattingEventHandler CellFormatting;
1035
1036                 public event DataGridViewCellEventHandler CellLeave;
1037
1038                 public event DataGridViewCellMouseEventHandler CellMouseClick;
1039
1040                 public event DataGridViewCellMouseEventHandler CellMouseDoubleClick;
1041
1042                 public event DataGridViewCellMouseEventHandler CellMouseDown;
1043
1044                 public event DataGridViewCellEventHandler CellMouseEnter;
1045
1046                 public event DataGridViewCellEventHandler CellMouseLeave;
1047
1048                 public event DataGridViewCellMouseEventHandler CellMouseMove;
1049
1050                 public event DataGridViewCellMouseEventHandler CellMouseUp;
1051
1052                 public event DataGridViewCellPaintingEventHandler CellPainting;
1053
1054                 public event DataGridViewCellParsingEventHandler CellParsing;
1055
1056                 public event DataGridViewCellStateChangedEventHandler CellStateChanged;
1057
1058                 public event DataGridViewCellEventHandler CellStyleChanged;
1059
1060                 public event DataGridViewCellStyleContentChangedEventHandler CellStyleContentChanged;
1061
1062                 public event DataGridViewCellEventHandler CellToolTipTextChanged;
1063
1064                 public event DataGridViewCellToolTipTextNeededEventHandler CellToolTipTextNeeded;
1065
1066                 public event DataGridViewCellEventHandler CellValidated;
1067
1068                 public event DataGridViewCellValidatingEventHandler CellValidating;
1069
1070                 public event DataGridViewCellEventHandler CellValueChanged;
1071
1072                 public event DataGridViewCellValueEventHandler CellValueNeeded;
1073
1074                 public event DataGridViewCellValueEventHandler CellValuePushed;
1075
1076                 public event DataGridViewColumnEventHandler ColumnAdded;
1077
1078                 public event DataGridViewColumnEventHandler ColumnContextMenuStripChanged;
1079
1080                 public event DataGridViewColumnEventHandler ColumnDataPropertyNameChanged;
1081
1082                 public event DataGridViewColumnEventHandler ColumnDefaultCellStyleChanged;
1083
1084                 public event DataGridViewColumnEventHandler ColumnDisplayIndexChanged;
1085
1086                 public event DataGridViewColumnDividerDoubleClickEventHandler ColumnDividerDoubleClick;
1087
1088                 public event DataGridViewColumnEventHandler ColumnDividerWidthChanged;
1089
1090                 public event DataGridViewColumnEventHandler ColumnHeaderCellChanged;
1091
1092                 public event DataGridViewCellMouseEventHandler ColumnHeaderMouseClick;
1093
1094                 public event DataGridViewCellMouseEventHandler ColumnHeaderMouseDoubleClick;
1095
1096                 public event EventHandler ColumnHeadersBorderStyleChanged;
1097
1098                 public event EventHandler ColumnHeadersDefaultCellStyleChanged;
1099
1100                 public event EventHandler ColumnHeadersHeightChanged;
1101
1102                 public event DataGridViewAutoSizeModeEventHandler ColumnHeadersHeightSizeModeChanged;
1103
1104                 public event DataGridViewColumnEventHandler ColumnMinimumWidthChanged;
1105
1106                 public event DataGridViewColumnEventHandler ColumnNameChanged;
1107
1108                 public event DataGridViewColumnEventHandler ColumnRemoved;
1109
1110                 public event DataGridViewColumnEventHandler ColumnSortModeChanged;
1111
1112                 public event DataGridViewColumnStateChangedEventHandler ColumnStateChanged;
1113
1114                 public event DataGridViewColumnEventHandler ColumnToolTipTextChanged;
1115
1116                 public event DataGridViewColumnEventHandler ColumnWidthChanged;
1117
1118                 public event EventHandler CurrentCellChanged;
1119
1120                 public event EventHandler CurrentCellDirtyStateChanged;
1121
1122                 public event DataGridViewBindingCompleteEventHandler DataBindingComplete;
1123
1124                 public event DataGridViewDataErrorEventHandler DataError;
1125
1126                 public event EventHandler DataMemberChanged;
1127
1128                 public event EventHandler DataSourceChanged;
1129
1130                 public event EventHandler DefaultCellStyleChanged;
1131
1132                 public event DataGridViewRowEventHandler DefaultValuesNeeded;
1133
1134                 public event DataGridViewEditingControlShowingEventHandler EditingControlShowing;
1135
1136                 public event EventHandler EditModeChanged;
1137
1138                 public new event EventHandler FontChanged;
1139
1140                 public new event EventHandler ForeColorChanged;
1141
1142                 public event EventHandler GridColorChanged;
1143
1144                 public event EventHandler MultiSelectChanged;
1145
1146                 public event DataGridViewRowEventHandler NewRowNeeded;
1147
1148                 public event EventHandler ReadOnlyChanged;
1149
1150                 public event DataGridViewRowEventHandler RowContextMenuStripChanged;
1151
1152                 public event DataGridViewRowContextMenuStripNeededEventHandler RowContextMenuStripNeeded;
1153
1154                 public event DataGridViewRowEventHandler RowDefaultCellStyleChanged;
1155
1156                 public event QuestionEventHandler RowDirtyStateNeeded;
1157
1158                 public event DataGridViewRowDividerDoubleClickEventHandler RowDividerDoubleClick;
1159
1160                 public event DataGridViewRowEventHandler RowDividerHeightChanged;
1161
1162                 public event DataGridViewCellEventHandler RowEnter;
1163
1164                 public event DataGridViewRowEventHandler RowErrorTextChanged;
1165
1166                 public event DataGridViewRowErrorTextNeededEventHandler RowErrorTextNeeded;
1167
1168                 public event DataGridViewRowEventHandler RowHeaderCellChanged;
1169
1170                 public event DataGridViewCellMouseEventHandler RowHeaderMouseClick;
1171
1172                 public event DataGridViewCellMouseEventHandler RowHeaderMouseDoubleClick;
1173
1174                 public event EventHandler RowHeadersBorderStyleChanged;
1175
1176                 public event EventHandler RowHeadersDefaultCellStyleChanged;
1177
1178                 public event EventHandler RowHeadersWidthChanged;
1179
1180                 public event DataGridViewAutoSizeModeEventHandler RowHeadersWidthSizeModeChanged;
1181
1182                 public event DataGridViewRowEventHandler RowHeightChanged;
1183
1184                 public event DataGridViewRowHeightInfoNeededEventHandler RowHeightInfoNeeded;
1185
1186                 public event DataGridViewRowHeightInfoPushedEventHandler RowHeightInfoPushed;
1187
1188                 public event DataGridViewCellEventHandler RowLeave;
1189
1190                 public event DataGridViewRowEventHandler RowMinimumHeightChanged;
1191
1192                 public event DataGridViewRowPostPaintEventHandler RowPostPaint;
1193
1194                 public event DataGridViewRowPrePaintEventHandler RowPrePaint;
1195
1196                 public event DataGridViewRowsAddedEventHandler RowsAdded;
1197
1198                 public event EventHandler RowsDefaultCellStyleChanged;
1199
1200                 public event DataGridViewRowsRemovedEventHandler RowsRemoved;
1201
1202                 public event DataGridViewRowStateChangedEventHandler RowStateChanged;
1203
1204                 public event DataGridViewRowEventHandler RowUnshared;
1205
1206                 public event DataGridViewCellEventHandler RowValidated;
1207
1208                 public event DataGridViewCellCancelEventHandler RowValidating;
1209
1210                 public event ScrollEventHandler Scroll;
1211
1212                 public event EventHandler SelectionChanged;
1213
1214                 public event DataGridViewSortCompareEventHandler SortCompare;
1215
1216                 public event EventHandler Sorted;
1217
1218                 public event DataGridViewRowEventHandler UserAddedRow;
1219
1220                 public event DataGridViewRowEventHandler UserDeletedRow;
1221
1222                 public event DataGridViewRowCancelEventHandler UserDeletingRow;
1223
1224                 public new event EventHandler StyleChanged;
1225
1226                 public new event EventHandler TextChanged;
1227
1228                 public virtual DataGridViewAdvancedBorderStyle AdjustColumnHeaderBorderStyle (DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStyleInput, DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceholder, bool isFirstDisplayedColumn, bool isLastVisibleColumn) {
1229                         return (DataGridViewAdvancedBorderStyle) dataGridViewAdvancedBorderStyleInput.Clone();
1230                 }
1231
1232                 public bool AreAllCellsSelected (bool includeInvisibleCells) {
1233                         foreach (DataGridViewRow row in rows) {
1234                                 foreach (DataGridViewCell cell in row.Cells) {
1235                                         if (includeInvisibleCells == false && cell.Visible == false) {
1236                                                 continue;
1237                                         }
1238                                         if (!cell.Selected) {
1239                                                 return false;
1240                                         }
1241                                 }
1242                         }
1243                         return true;
1244                 }
1245
1246                 public void AutoResizeColumn (int columnIndex) {
1247                         throw new NotImplementedException();
1248                 }
1249
1250                 public void AutoResizeColumn (int columnIndex, DataGridViewAutoSizeColumnMode autoSizeColumnMode) {
1251                         throw new NotImplementedException();
1252                 }
1253
1254                 public void AutoResizeColumnHeadersHeight () {
1255                         throw new NotImplementedException();
1256                 }
1257
1258                 public void AutoResizeColumnHeadersHeight (int columnIndex) {
1259                         throw new NotImplementedException();
1260                 }
1261
1262                 public void AutoResizeColumns () {
1263                         throw new NotImplementedException();
1264                 }
1265
1266                 public void AutoResizeColumns (DataGridViewAutoSizeColumnsMode autoSizeColumnsMode) {
1267                         throw new NotImplementedException();
1268                 }
1269
1270                 public void AutoResizeRow (int rowIndex) {
1271                         throw new NotImplementedException();
1272                 }
1273
1274                 public void AutoResizeRow (int rowIndex, DataGridViewAutoSizeRowMode autoSizeRowMode) {
1275                         throw new NotImplementedException();
1276                 }
1277
1278                 public void AutoResizeRowHeadersWidth (DataGridViewRowHeadersWidthSizeMode rowHeadersWidthSizeMode) {
1279                         throw new NotImplementedException();
1280                 }
1281
1282                 public void AutoResizeRowHeadersWidth (int rowIndex, DataGridViewRowHeadersWidthSizeMode rowHeadersWidthSizeMode) {
1283                         throw new NotImplementedException();
1284                 }
1285
1286                 public void AutoResizeRows () {
1287                         throw new NotImplementedException();
1288                 }
1289
1290                 public void AutoResizeRows (DataGridViewAutoSizeRowsMode autoSizeRowsMode) {
1291                         if (!Enum.IsDefined(typeof(DataGridViewAutoSizeRowsMode), autoSizeRowsMode)) {
1292                                 throw new InvalidEnumArgumentException("Parameter AutoSizeRowsMode is not valid DataGridViewRowsMode.");
1293                         }
1294                         if ((autoSizeRowsMode == DataGridViewAutoSizeRowsMode.AllHeaders || autoSizeRowsMode == DataGridViewAutoSizeRowsMode.DisplayedHeaders) && rowHeadersVisible == false) {
1295                                 throw new InvalidOperationException("Parameter AutoSizeRowsMode cant be AllHeaders or DisplayedHeaders in this DataGridView.");
1296                         }
1297                         if (autoSizeRowsMode == DataGridViewAutoSizeRowsMode.None) {
1298                                 throw new ArgumentException("Parameter AutoSieRowsMode cant be None.");
1299                         }
1300                 }
1301
1302                 public virtual bool BeginEdit (bool selectAll) {
1303                         throw new NotImplementedException();
1304                 }
1305
1306                 public bool CancelEdit () {
1307                         throw new NotImplementedException();
1308                 }
1309
1310                 public void ClearSelection () {
1311                         foreach (DataGridViewCell cell in SelectedCells) {
1312                                 cell.Selected = false;
1313                         }
1314                 }
1315
1316                 public bool CommitEdit (DataGridViewDataErrorContexts context) {
1317                         throw new NotImplementedException();
1318                 }
1319
1320                 public int DisplayedColumnCount (bool includePartialColumns) {
1321                         /////////////////////// PartialColumns?
1322                         int result = 0;
1323                         foreach (DataGridViewColumn col in columns) {
1324                                 if (col.Visible) {
1325                                         result++;
1326                                 }
1327                         }
1328                         return result;
1329                 }
1330
1331                 public int DisplayedRowCount (bool includePartialRow) {
1332                         /////////////////////// PartialRows?
1333                         int result = 0;
1334                         foreach (DataGridViewRow row in rows) {
1335                                 if (row.Visible) {
1336                                         result++;
1337                                 }
1338                         }
1339                         return result;
1340                 }
1341
1342                 public bool EndEdit () {
1343                         throw new NotImplementedException();
1344                 }
1345
1346                 public bool EndEdit (DataGridViewDataErrorContexts context) {
1347                         throw new NotImplementedException();
1348                 }
1349
1350                 public int GetCellCount (DataGridViewElementStates includeFilter) {
1351                         int result = 0;
1352                         foreach (DataGridViewRow row in rows) {
1353                                 foreach (DataGridViewCell cell in row.Cells) {
1354                                         if ((cell.State & includeFilter) != 0) {
1355                                                 result++;
1356                                         }
1357                                 }
1358                         }
1359                         return result;
1360                 }
1361
1362                 public Rectangle GetCellDisplayRectangle (int columnIndex, int rowIndex, bool cutOverflow) {
1363                         if (columnIndex < 0 || columnIndex >= columns.Count) {
1364                                 throw new ArgumentOutOfRangeException("Column index is out of range.");
1365                         }
1366                         throw new NotImplementedException();
1367                 }
1368
1369                 public virtual DataObject GetClipboardContent () {
1370                         throw new NotImplementedException();
1371                 }
1372
1373                 public Rectangle GetColumnDisplayRectangle (int columnIndex, bool cutOverflow) {
1374                         throw new NotImplementedException();
1375                 }
1376
1377                 public Rectangle GetRowDisplayRectangle (int rowIndex, bool cutOverflow) {
1378                         throw new NotImplementedException();
1379                 }
1380
1381                 public HitTestInfo HitTest (int x, int y) {
1382                         ///////////////////////////////////////////////////////
1383                         x += horizontalScrollingOffset;
1384                         y += verticalScrollingOffset;
1385                         int rowIndex = -1;
1386                         int totalHeight = (columnHeadersVisible)? 1 + columnHeadersHeight : 1;
1387                         if (columnHeadersVisible && y <= totalHeight) {
1388                                 rowIndex = -1;
1389                         }
1390                         else {
1391                                 foreach (DataGridViewRow row in rows.RowIndexSortedArrayList) {
1392                                         totalHeight += row.Height;
1393                                         if (y <= totalHeight) {
1394                                                 rowIndex = row.Index;
1395                                                 break;
1396                                         }
1397                                         totalHeight++; // sumar el ancho de las lineas...
1398                                 }
1399                         }
1400                         int colIndex = -1;
1401                         int totalWidth = (rowHeadersVisible)? 1 + rowHeadersWidth : 1;
1402                         if (rowHeadersVisible && x <= totalWidth) {
1403                                 colIndex = -1;
1404                         }
1405                         else {
1406                                 foreach (DataGridViewColumn col in columns.ColumnDisplayIndexSortedArrayList) {
1407                                         totalWidth += col.Width;
1408                                         if (x <= totalWidth) {
1409                                                 colIndex = col.Index;
1410                                                 break;
1411                                         }
1412                                         totalWidth++;
1413                                 }
1414                         }
1415                         HitTestInfo result = new HitTestInfo(colIndex, x, rowIndex, y, (colIndex >= 0 && rowIndex >= 0)? DataGridViewHitTestType.Cell : DataGridViewHitTestType.None);
1416                         return result;
1417                 }
1418
1419                 public void InvalidateCell (DataGridViewCell dataGridViewCell) {
1420                         if (dataGridViewCell == null) {
1421                                 throw new ArgumentNullException("Cell is null");
1422                         }
1423                         if (dataGridViewCell.DataGridView != this) {
1424                                 throw new ArgumentException("The specified cell does not belong to this DataGridView.");
1425                         }
1426                         throw new NotImplementedException();
1427                 }
1428
1429                 public void InvalidateCell (int columnIndex, int rowIndex) {
1430                         if (columnIndex < 0 || columnIndex >= columns.Count) {
1431                                 throw new ArgumentOutOfRangeException("Column index is out of range.");
1432                         }
1433                         if (rowIndex < 0 || rowIndex >= rows.Count) {
1434                                 throw new ArgumentOutOfRangeException("Row index is out of range.");
1435                         }
1436                         foreach (DataGridViewRow row in rows) {
1437                                 foreach (DataGridViewCell cell in row.Cells) {
1438                                         if (cell.RowIndex == rowIndex && cell.ColumnIndex == columnIndex) {
1439                                                 InvalidateCell(cell); //// O al revés, que el otro llame a este !!!
1440                                                 return;
1441                                         }
1442                                 }
1443                         }
1444                 }
1445
1446                 public void InvalidateColumn (int columnIndex) {
1447                         if (columnIndex < 0 || columnIndex >= columns.Count) {
1448                                 throw new ArgumentOutOfRangeException("Column index is out of range.");
1449                         }
1450                         throw new NotImplementedException();
1451                 }
1452
1453                 public void InvalidateRow (int rowIndex) {
1454                         if (rowIndex < 0 || rowIndex >= rows.Count) {
1455                                 throw new ArgumentOutOfRangeException("Row index is out of range.");
1456                         }
1457                         throw new NotImplementedException();
1458                 }
1459
1460                 public virtual void NotifyCurrentCellDirty (bool dirty) {
1461                         throw new NotImplementedException();
1462                 }
1463
1464                 public bool RefreshEdit () {
1465                         throw new NotImplementedException();
1466                 }
1467
1468                 public override void ResetText () {
1469                         throw new NotImplementedException();
1470                 }
1471
1472                 public void SelectAll () {
1473                         switch (selectionMode) {
1474                                 case DataGridViewSelectionMode.FullRowSelect:
1475                                         foreach (DataGridViewRow row in rows) {
1476                                                 (row as DataGridViewBand).Selected = true;
1477                                         }
1478                                         break;
1479                                 case DataGridViewSelectionMode.FullColumnSelect:
1480                                         foreach (DataGridViewColumn col in columns) {
1481                                                 (col as DataGridViewBand).Selected = true;
1482                                         }
1483                                         break;
1484                                 default:
1485                                         foreach (DataGridViewRow row in rows) {
1486                                                 foreach (DataGridViewCell cell in row.Cells) {
1487                                                         cell.Selected = true;
1488                                                 }
1489                                         }
1490                                         break;
1491                         }
1492                 }
1493
1494                 public virtual void Sort (IComparer comparer) {
1495                         throw new NotImplementedException();
1496                 }
1497
1498                 public virtual void Sort (DataGridViewColumn dataGridViewColumn, ListSortDirection direction) {
1499                         throw new NotImplementedException();
1500                 }
1501
1502                 public void UpdateCellErrorText (int columnIndex, int rowIndex) {
1503                         throw new NotImplementedException();
1504                 }
1505
1506                 public void UpdateRowErrorText (int rowIndex) {
1507                         throw new NotImplementedException();
1508                 }
1509
1510                 public void UpdateRowErrorText (int rowIndexStart, int rowIndexEnd) {
1511                         throw new NotImplementedException();
1512                 }
1513
1514                 public void UpdateRowHeightInfo (int rowIndex, bool updateToEnd) {
1515                         throw new NotImplementedException();
1516                 }
1517
1518                 protected override Size DefaultSize {
1519                         get { return defaultSize; }
1520                 }
1521
1522                 protected ScrollBar HorizontalScrollBar {
1523                         get { return horizontalScrollBar; }
1524                 }
1525
1526                 protected ScrollBar VerticalScrollBar {
1527                         get { return verticalScrollBar; }
1528                 }
1529
1530                 protected void AutoResizeColumn (int columnIndex, DataGridViewAutoSizeColumnMode autoSizeColumnMode, bool fixedHeight) {
1531                         throw new NotImplementedException();
1532                 }
1533
1534                 protected void AutoResizeColumnHeadersHeight (bool fixedRowHeadersWidth, bool fixedColumnsWidth) {
1535                         throw new NotImplementedException();
1536                 }
1537
1538                 protected void AutoResizeColumnHeadersHeight (int columnIndex, bool fixedRowHeadersWidth, bool fixedColumnWidth) {
1539                         throw new NotImplementedException();
1540                 }
1541
1542                 protected void AutoResizeColumns (DataGridViewAutoSizeColumnsMode autoSizeColumnsMode, bool fixedHeight) {
1543                         throw new NotImplementedException();
1544                 }
1545
1546                 protected void AutoResizeRow (int rowIndex, DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth) {
1547                         throw new NotImplementedException();
1548                 }
1549
1550                 protected void AutoResizeRowHeadersWidth (DataGridViewRowHeadersWidthSizeMode rowHeadersWidthSizeMode, bool fixedColumnHeadersHeight, bool fixedRowsHeight) {
1551                         throw new NotImplementedException();
1552                 }
1553
1554                 protected void AutoResizeRowHeadersWidth (int rowIndex, DataGridViewRowHeadersWidthSizeMode rowHeadersWidthSizeMode, bool fixedColumnHeadersHeight, bool fixedRowHeight) {
1555                         throw new NotImplementedException();
1556                 }
1557
1558                 protected void AutoResizeRows (DataGridViewAutoSizeRowsMode autoSizeRowsMode, bool fixedWidth) {
1559                         throw new NotImplementedException();
1560                 }
1561
1562                 protected void AutoResizeRows (int rowIndexStart, int rowsCount, DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth) {
1563                         throw new NotImplementedException();
1564                 }
1565
1566                 protected void ClearSelection (int columnIndexException, int rowIndexException, bool selectExceptionElement) {
1567                         if (columnIndexException >= columns.Count) {
1568                                 throw new ArgumentOutOfRangeException("ColumnIndexException is greater than the highest column index.");
1569                         }
1570                         if (selectionMode == DataGridViewSelectionMode.FullRowSelect) {
1571                                 if (columnIndexException < -1) {
1572                                         throw new ArgumentOutOfRangeException("ColumnIndexException is less than -1.");
1573                                 }
1574                         }
1575                         else {
1576                                 if (columnIndexException < 0) {
1577                                         throw new ArgumentOutOfRangeException("ColumnIndexException is less than 0.");
1578                                 }
1579                         }
1580                         if (rowIndexException >= rows.Count) {
1581                                 throw new ArgumentOutOfRangeException("RowIndexException is greater than the highest row index.");
1582                         }
1583                         if (selectionMode == DataGridViewSelectionMode.FullColumnSelect) {
1584                                 if (rowIndexException < -1) {
1585                                         throw new ArgumentOutOfRangeException("RowIndexException is less than -1.");
1586                                 }
1587                         }
1588                         else {
1589                                 if (rowIndexException < 0) {
1590                                         throw new ArgumentOutOfRangeException("RowIndexException is less than 0.");
1591                                 }
1592                         }
1593                         switch (selectionMode) {
1594                                 case DataGridViewSelectionMode.FullRowSelect:
1595                                         foreach (DataGridViewRow row in rows) {
1596                                                 if (selectExceptionElement && row.Index == rowIndexException) {
1597                                                         continue;
1598                                                 }
1599                                                 row.Selected = false;
1600                                         }
1601                                         break;
1602                                 case DataGridViewSelectionMode.FullColumnSelect:
1603                                         foreach (DataGridViewColumn col in columns) {
1604                                                 if (selectExceptionElement && col.Index == columnIndexException) {
1605                                                         continue;
1606                                                 }
1607                                                 col.Selected = false;
1608                                         }
1609                                         break;
1610                                 default:
1611                                         foreach (DataGridViewCell cell in SelectedCells) {
1612                                                 if (selectExceptionElement && cell.RowIndex == rowIndexException && cell.ColumnIndex == columnIndexException) {
1613                                                         continue;
1614                                                 }
1615                                                 cell.Selected = false;
1616                                         }
1617                                         break;
1618                         }
1619                 }
1620
1621                 protected override AccessibleObject CreateAccessibilityInstance () {
1622                         return new DataGridViewAccessibleObject(this);
1623                 }
1624
1625                 protected virtual DataGridViewColumnCollection CreateColumnsInstance () {
1626                         return new DataGridViewColumnCollection(this);
1627                 }
1628
1629                 protected override Control.ControlCollection CreateControlsInstance () {
1630                         return base.CreateControlsInstance(); //new Control.ControlCollection(this);
1631                 }
1632
1633                 protected virtual DataGridViewRowCollection CreateRowsInstance () {
1634                         return new DataGridViewRowCollection(this);
1635                 }
1636
1637                 protected override void Dispose (bool disposing) {
1638                 }
1639
1640                 //protected override AccessibleObject GetAccessibilityObjectById (int objectId) {
1641                 protected AccessibleObject GetAccessibilityObjectById (int objectId) {
1642                         throw new NotImplementedException();
1643                 }
1644
1645                 protected override bool IsInputChar (char charCode) {
1646                         return base.IsInputChar(charCode);
1647                         //throw new NotImplementedException();
1648                 }
1649
1650                 protected override bool IsInputKey (Keys keyData) {
1651                         return base.IsInputKey(keyData);
1652                         //throw new NotImplementedException();
1653                 }
1654
1655                 protected virtual void OnAllowUserToAddRowsChanged (EventArgs e) {
1656                         if (AllowUserToAddRowsChanged != null) {
1657                                 AllowUserToAddRowsChanged(this, e);
1658                         }
1659                 }
1660
1661                 protected virtual void OnAllowUserToDeleteRowsChanged (EventArgs e) {
1662                         if (AllowUserToDeleteRowsChanged != null) {
1663                                 AllowUserToDeleteRowsChanged(this, e);
1664                         }
1665                 }
1666
1667                 protected virtual void OnAllowUserToOrderColumnsChanged (EventArgs e) {
1668                         if (AllowUserToOrderColumnsChanged != null) {
1669                                 AllowUserToOrderColumnsChanged(this, e);
1670                         }
1671                 }
1672
1673                 protected virtual void OnAllowUserToResizeColumnsChanged (EventArgs e) {
1674                         if (AllowUserToResizeColumnsChanged != null) {
1675                                 AllowUserToResizeColumnsChanged(this, e);
1676                         }
1677                 }
1678
1679                 protected virtual void OnAllowUserToResizeRowsChanged (EventArgs e) {
1680                         if (AllowUserToResizeRowsChanged != null) {
1681                                 AllowUserToResizeRowsChanged(this, e);
1682                         }
1683                 }
1684
1685                 protected virtual void OnAlternatingRowsDefaultCellStyleChanged (EventArgs e) {
1686                         if (AlternatingRowsDefaultCellStyleChanged != null) {
1687                                 AlternatingRowsDefaultCellStyleChanged(this, e);
1688                         }
1689                 }
1690
1691                 protected virtual void OnAutoGenerateColumnsChanged (EventArgs e) {
1692                         if (AutoGenerateColumnsChanged != null) {
1693                                 AutoGenerateColumnsChanged(this, e);
1694                         }
1695                 }
1696
1697                 protected virtual void OnAutoSizeColumnModeChanged (DataGridViewAutoSizeColumnModeEventArgs e) {
1698                         if (AutoSizeColumnModeChanged != null) {
1699                                 AutoSizeColumnModeChanged(this, e);
1700                         }
1701                 }
1702
1703                 protected virtual void OnAutoSizeColumnsModeChanged (DataGridViewAutoSizeColumnsModeEventArgs e) {
1704                         if (AutoSizeColumnsModeChanged != null) {
1705                                 AutoSizeColumnsModeChanged(this, e);
1706                         }
1707                 }
1708
1709                 protected virtual void OnAutoSizeRowsModeChanged (DataGridViewAutoSizeModeEventArgs e) {
1710                         if (AutoSizeRowsModeChanged != null) {
1711                                 AutoSizeRowsModeChanged(this, e);
1712                         }
1713                 }
1714
1715                 protected virtual void OnBackgroundColorChanged (EventArgs e) {
1716                         if (BackgroundColorChanged != null) {
1717                                 BackgroundColorChanged(this, e);
1718                         }
1719                 }
1720
1721                 protected override void OnBindingContextChanged (EventArgs e) {
1722                         base.OnBindingContextChanged(e);
1723                 }
1724
1725                 protected virtual void OnBorderStyleChanged (EventArgs e) {
1726                         if (BorderStyleChanged != null) {
1727                                 BorderStyleChanged(this, e);
1728                         }
1729                 }
1730
1731                 protected virtual void OnCancelRowEdit (QuestionEventArgs e) {
1732                         if (CancelRowEdit != null) {
1733                                 CancelRowEdit(this, e);
1734                         }
1735                 }
1736
1737                 protected virtual void OnCellBeginEdit (DataGridViewCellCancelEventArgs e) {
1738                         if (CellBeginEdit != null) {
1739                                 CellBeginEdit(this, e);
1740                         }
1741                 }
1742
1743                 protected virtual void OnCellBorderStyleChanged (EventArgs e) {
1744                         if (CellBorderStyleChanged != null) {
1745                                 CellBorderStyleChanged(this, e);
1746                         }
1747                 }
1748
1749                 protected virtual void OnCellClick (DataGridViewCellEventArgs e) {
1750                         if (CellClick != null) {
1751                                 CellClick(this, e);
1752                         }
1753                 }
1754
1755                 protected virtual void OnCellContentClick (DataGridViewCellEventArgs e) {
1756                         if (CellContentClick != null) {
1757                                 CellContentClick(this, e);
1758                         }
1759                 }
1760
1761                 protected virtual void OnCellContentDoubleClick (DataGridViewCellEventArgs e) {
1762                         if (CellContentDoubleClick != null) {
1763                                 CellContentDoubleClick(this, e);
1764                         }
1765                 }
1766
1767                 protected virtual void OnCellContextMenuStripChanged (DataGridViewCellEventArgs e) {
1768                         if (CellContextMenuStripChanged != null) {
1769                                 CellContextMenuStripChanged(this, e);
1770                         }
1771                 }
1772
1773                 protected virtual void OnCellContextMenuStripNeeded (DataGridViewCellContextMenuStripNeededEventArgs e) {
1774                         if (CellContextMenuStripNeeded != null) {
1775                                 CellContextMenuStripNeeded(this, e);
1776                         }
1777                 }
1778
1779                 protected virtual void OnCellDoubleClick (DataGridViewCellEventArgs e) {
1780                         if (CellDoubleClick != null) {
1781                                 CellDoubleClick(this, e);
1782                         }
1783                 }
1784
1785                 protected virtual void OnCellEndEdit (DataGridViewCellEventArgs e) {
1786                         if (CellEndEdit != null) {
1787                                 CellEndEdit(this, e);
1788                         }
1789                 }
1790
1791                 protected virtual void OnCellEnter (DataGridViewCellEventArgs e) {
1792                         if (CellEnter != null) {
1793                                 CellEnter(this, e);
1794                         }
1795                 }
1796
1797                 // In MSDN2 documentation there's no internal here
1798                 protected internal virtual void OnCellErrorTextChanged (DataGridViewCellEventArgs e) {
1799                         if (CellErrorTextChanged != null) {
1800                                 CellErrorTextChanged(this, e);
1801                         }
1802                 }
1803
1804                 protected virtual void OnCellErrorTextNeeded (DataGridViewCellErrorTextNeededEventArgs e) {
1805                         if (CellErrorTextNeeded != null) {
1806                                 CellErrorTextNeeded(this, e);
1807                         }
1808                 }
1809
1810                 protected virtual void OnCellFormatting (DataGridViewCellFormattingEventArgs e) {
1811                         if (CellFormatting != null) {
1812                                 CellFormatting(this, e);
1813                         }
1814                 }
1815
1816                 protected virtual void OnCellLeave (DataGridViewCellEventArgs e) {
1817                         if (CellLeave != null) {
1818                                 CellLeave(this, e);
1819                         }
1820                 }
1821
1822                 protected virtual void OnCellMouseClick (DataGridViewCellMouseEventArgs e) {
1823                         if (CellMouseClick != null) {
1824                                 CellMouseClick(this, e);
1825                         }
1826                 }
1827
1828                 protected virtual void OnCellMouseDoubleClick (DataGridViewCellMouseEventArgs e) {
1829                         if (CellMouseDoubleClick != null) {
1830                                 CellMouseDoubleClick(this, e);
1831                         }
1832                 }
1833
1834                 protected virtual void OnCellMouseDown (DataGridViewCellMouseEventArgs e) {
1835                         if (CellMouseDown != null) {
1836                                 CellMouseDown(this, e);
1837                         }
1838                 }
1839
1840                 protected virtual void OnCellMouseEnter (DataGridViewCellEventArgs e) {
1841                         if (CellMouseEnter != null) {
1842                                 CellMouseEnter(this, e);
1843                         }
1844                 }
1845
1846                 protected virtual void OnCellMouseLeave (DataGridViewCellEventArgs e) {
1847                         if (CellMouseLeave != null) {
1848                                 CellMouseLeave(this, e);
1849                         }
1850                 }
1851
1852                 protected virtual void OnCellMouseMove (DataGridViewCellMouseEventArgs e) {
1853                         if (CellMouseMove != null) {
1854                                 CellMouseMove(this, e);
1855                         }
1856                 }
1857
1858                 protected virtual void OnCellMouseUp (DataGridViewCellMouseEventArgs e) {
1859                         if (CellMouseUp != null) {
1860                                 CellMouseUp(this, e);
1861                         }
1862                 }
1863
1864                 protected virtual void OnCellPainting (DataGridViewCellPaintingEventArgs e) {
1865                         if (CellPainting != null) {
1866                                 CellPainting(this, e);
1867                         }
1868                 }
1869
1870                 protected internal virtual void OnCellParsing (DataGridViewCellParsingEventArgs e) {
1871                         if (CellParsing != null) {
1872                                 CellParsing(this, e);
1873                         }
1874                 }
1875
1876                 protected virtual void OnCellStateChanged (DataGridViewCellStateChangedEventArgs e) {
1877                         if (CellStateChanged != null) {
1878                                 CellStateChanged(this, e);
1879                         }
1880                 }
1881
1882                 protected virtual void OnCellStyleChanged (DataGridViewCellEventArgs e) {
1883                         if (CellStyleChanged != null) {
1884                                 CellStyleChanged(this, e);
1885                         }
1886                 }
1887
1888                 protected virtual void OnCellStyleContentChanged (DataGridViewCellStyleContentChangedEventArgs e) {
1889                         if (CellStyleContentChanged != null) {
1890                                 CellStyleContentChanged(this, e);
1891                         }
1892                 }
1893
1894                 protected virtual void OnCellToolTipTextChanged (DataGridViewCellEventArgs e) {
1895                         if (CellToolTipTextChanged != null) {
1896                                 CellToolTipTextChanged(this, e);
1897                         }
1898                 }
1899
1900                 protected virtual void OnCellToolTipTextNeeded (DataGridViewCellToolTipTextNeededEventArgs e) {
1901                         if (CellToolTipTextNeeded != null) {
1902                                 CellToolTipTextNeeded(this, e);
1903                         }
1904                 }
1905
1906                 protected virtual void OnCellValidated (DataGridViewCellEventArgs e) {
1907                         if (CellValidated != null) {
1908                                 CellValidated(this, e);
1909                         }
1910                 }
1911
1912                 protected virtual void OnCellValidating (DataGridViewCellValidatingEventArgs e) {
1913                         if (CellValidating != null) {
1914                                 CellValidating(this, e);
1915                         }
1916                 }
1917
1918                 protected virtual void OnCellValueChanged (DataGridViewCellEventArgs e) {
1919                         if (CellValueChanged != null) {
1920                                 CellValueChanged(this, e);
1921                         }
1922                 }
1923
1924                 protected virtual void OnCellValueNeeded (DataGridViewCellValueEventArgs e) {
1925                         if (CellValueNeeded != null) {
1926                                 CellValueNeeded(this, e);
1927                         }
1928                 }
1929
1930                 protected virtual void OnCellValuePushed (DataGridViewCellValueEventArgs e) {
1931                         if (CellValuePushed != null) {
1932                                 CellValuePushed(this, e);
1933                         }
1934                 }
1935
1936                 protected virtual void OnColumnAdded (DataGridViewColumnEventArgs e) {
1937                         if (ColumnAdded != null) {
1938                                 ColumnAdded(this, e);
1939                         }
1940                 }
1941
1942                 // In MSDN2 documentation there's no internal here
1943                 protected internal virtual void OnColumnContextMenuStripChanged (DataGridViewColumnEventArgs e) {
1944                         if (ColumnContextMenuStripChanged != null) {
1945                                 ColumnContextMenuStripChanged(this, e);
1946                         }
1947                 }
1948
1949                 // In MSDN2 documentation there's no internal here
1950                 protected internal virtual void OnColumnDataPropertyNameChanged (DataGridViewColumnEventArgs e) {
1951                         if (ColumnDataPropertyNameChanged != null) {
1952                                 ColumnDataPropertyNameChanged(this, e);
1953                         }
1954                 }
1955
1956                 // In MSDN2 documentation there's no internal here
1957                 protected internal virtual void OnColumnDefaultCellStyleChanged (DataGridViewColumnEventArgs e) {
1958                         if (ColumnDefaultCellStyleChanged != null) {
1959                                 ColumnDefaultCellStyleChanged(this, e);
1960                         }
1961                 }
1962
1963                 // In MSDN2 documentation there's no internal here
1964                 protected internal virtual void OnColumnDisplayIndexChanged (DataGridViewColumnEventArgs e) {
1965                         if (ColumnDisplayIndexChanged != null) {
1966                                 ColumnDisplayIndexChanged(this, e);
1967                         }
1968                 }
1969
1970                 protected virtual void OnColumnDividerDoubleClick (DataGridViewColumnDividerDoubleClickEventArgs e) {
1971                         if (ColumnDividerDoubleClick != null) {
1972                                 ColumnDividerDoubleClick(this, e);
1973                         }
1974                 }
1975
1976                 // In MSDN2 documentation there's no internal here
1977                 protected internal virtual void OnColumnDividerWidthChanged (DataGridViewColumnEventArgs e) {
1978                         if (ColumnDividerWidthChanged != null) {
1979                                 ColumnDividerWidthChanged(this, e);
1980                         }
1981                 }
1982
1983                 // In MSDN2 documentation there's no internal here
1984                 protected internal virtual void OnColumnHeaderCellChanged (DataGridViewColumnEventArgs e) {
1985                         if (ColumnHeaderCellChanged != null) {
1986                                 ColumnHeaderCellChanged(this, e);
1987                         }
1988                 }
1989
1990                 protected virtual void OnColumnHeaderMouseClick (DataGridViewCellMouseEventArgs e) {
1991                         if (ColumnHeaderMouseClick != null) {
1992                                 ColumnHeaderMouseClick(this, e);
1993                         }
1994                 }
1995
1996                 protected virtual void OnColumnHeaderMouseDoubleClick (DataGridViewCellMouseEventArgs e) {
1997                         if (ColumnHeaderMouseDoubleClick != null) {
1998                                 ColumnHeaderMouseDoubleClick(this, e);
1999                         }
2000                 }
2001
2002                 protected virtual void OnColumnHeadersBorderStyleChanged (EventArgs e) {
2003                         if (ColumnHeadersBorderStyleChanged != null) {
2004                                 ColumnHeadersBorderStyleChanged(this, e);
2005                         }
2006                 }
2007
2008                 protected virtual void OnColumnHeadersDefaultCellStyleChanged (EventArgs e) {
2009                         if (ColumnHeadersDefaultCellStyleChanged != null) {
2010                                 ColumnHeadersDefaultCellStyleChanged(this, e);
2011                         }
2012                 }
2013
2014                 protected virtual void OnColumnHeadersHeightChanged (EventArgs e) {
2015                         if (ColumnHeadersHeightChanged != null) {
2016                                 ColumnHeadersHeightChanged(this, e);
2017                         }
2018                 }
2019
2020                 protected virtual void OnColumnHeadersHeightSizeModeChanged (DataGridViewAutoSizeModeEventArgs e) {
2021                         if (ColumnHeadersHeightSizeModeChanged != null) {
2022                                 ColumnHeadersHeightSizeModeChanged(this, e);
2023                         }
2024                 }
2025
2026                 // In MSDN2 documentation there's no internal here
2027                 protected internal virtual void OnColumnMinimumWidthChanged (DataGridViewColumnEventArgs e) {
2028                         if (ColumnMinimumWidthChanged != null) {
2029                                 ColumnMinimumWidthChanged(this, e);
2030                         }
2031                 }
2032
2033                 // In MSDN2 documentation there's no internal here
2034                 protected internal virtual void OnColumnNameChanged (DataGridViewColumnEventArgs e) {
2035                         if (ColumnNameChanged != null) {
2036                                 ColumnNameChanged(this, e);
2037                         }
2038                 }
2039
2040                 protected virtual void OnColumnRemoved (DataGridViewColumnEventArgs e) {
2041                         if (ColumnRemoved != null) {
2042                                 ColumnRemoved(this, e);
2043                         }
2044                 }
2045
2046                 // In MSDN2 documentation there's no internal here
2047                 protected internal virtual void OnColumnSortModeChanged (DataGridViewColumnEventArgs e) {
2048                         if (ColumnSortModeChanged != null) {
2049                                 ColumnSortModeChanged(this, e);
2050                         }
2051                 }
2052
2053                 // In MSDN2 documentation there's no internal here
2054                 protected internal virtual void OnColumnStateChanged (DataGridViewColumnStateChangedEventArgs e) {
2055                         if (ColumnStateChanged != null) {
2056                                 ColumnStateChanged(this, e);
2057                         }
2058                 }
2059
2060                 // In MSDN2 documentation there's no internal here
2061                 protected internal virtual void OnColumnToolTipTextChanged (DataGridViewColumnEventArgs e) {
2062                         if (ColumnToolTipTextChanged != null) {
2063                                 ColumnToolTipTextChanged(this, e);
2064                         }
2065                 }
2066
2067                 // In MSDN2 documentation there's no internal here
2068                 protected internal virtual void OnColumnWidthChanged (DataGridViewColumnEventArgs e) {
2069                         if (ColumnWidthChanged != null) {
2070                                 ColumnWidthChanged(this, e);
2071                         }
2072                 }
2073
2074                 protected virtual void OnCurrentCellChanged (EventArgs e) {
2075                         if (CurrentCellChanged != null) {
2076                                 CurrentCellChanged(this, e);
2077                         }
2078                 }
2079
2080                 protected virtual void OnCurrentCellDirtyStateChanged (EventArgs e) {
2081                         if (CurrentCellDirtyStateChanged != null) {
2082                                 CurrentCellDirtyStateChanged(this, e);
2083                         }
2084                 }
2085
2086                 protected virtual void OnDataBindingComplete (DataGridViewBindingCompleteEventArgs e) {
2087                         if (DataBindingComplete != null) {
2088                                 DataBindingComplete(this, e);
2089                         }
2090                 }
2091
2092                 protected virtual void OnDataError (bool displayErrorDialogIfNoHandler, DataGridViewDataErrorEventArgs e) {
2093                         if (DataError != null) {
2094                                 DataError(this, e);
2095                         }
2096                         else {
2097                                 if (displayErrorDialogIfNoHandler) {
2098                                         /////////////////////////////////// ERROR DIALOG //////////////////////////////////7
2099                                 }
2100                         }
2101                 }
2102                 protected virtual void OnDataMemberChanged (EventArgs e) {
2103                         if (DataMemberChanged != null) {
2104                                 DataMemberChanged(this, e);
2105                         }
2106                 }
2107
2108                 protected virtual void OnDataSourceChanged (EventArgs e) {
2109                         if (DataSourceChanged != null) {
2110                                 DataSourceChanged(this, e);
2111                         }
2112                 }
2113
2114                 protected virtual void OnDefaultCellStyleChanged (EventArgs e) {
2115                         if (DefaultCellStyleChanged != null) {
2116                                 DefaultCellStyleChanged(this, e);
2117                         }
2118                 }
2119
2120                 protected virtual void OnDefaultValuesNeeded (DataGridViewRowEventArgs e) {
2121                         if (DefaultValuesNeeded != null) {
2122                                 DefaultValuesNeeded(this, e);
2123                         }
2124                 }
2125
2126                 protected override void OnDoubleClick (EventArgs e) {
2127                         base.OnDoubleClick(e);
2128                 }
2129
2130                 protected virtual void OnEditingControlShowing (DataGridViewEditingControlShowingEventArgs e) {
2131                         if (EditingControlShowing != null) {
2132                                 EditingControlShowing(this, e);
2133                         }
2134                 }
2135
2136                 protected virtual void OnEditModeChanged (EventArgs e) {
2137                         if (EditModeChanged != null) {
2138                                 EditModeChanged(this, e);
2139                         }
2140                 }
2141
2142                 protected override void OnEnabledChanged (EventArgs e) {
2143                         base.OnEnabledChanged(e);
2144                 }
2145
2146                 protected override void OnEnter (EventArgs e ) {
2147                         base.OnEnter(e);
2148                 }
2149
2150                 protected override void OnFontChanged (EventArgs e) {
2151                         base.OnFontChanged(e);
2152                         if (FontChanged != null) {
2153                                 FontChanged(this, e);
2154                         }
2155                 }
2156
2157                 protected override void OnForeColorChanged (EventArgs e) {
2158                         base.OnForeColorChanged(e);
2159                         if (ForeColorChanged != null) {
2160                                 ForeColorChanged(this, e);
2161                         }
2162                 }
2163
2164                 protected virtual void OnGridColorChanged (EventArgs e) {
2165                         if (GridColorChanged != null) {
2166                                 GridColorChanged(this, e);
2167                         }
2168                 }
2169
2170                 protected override void OnHandleCreated (EventArgs e) {
2171                         base.OnHandleCreated(e);
2172                 }
2173
2174                 protected override void OnKeyDown (KeyEventArgs e) {
2175                         base.OnKeyDown(e);
2176                 }
2177
2178                 protected override void OnKeyPress (KeyPressEventArgs e) {
2179                         base.OnKeyPress(e);
2180                 }
2181
2182                 protected override void OnKeyUp (KeyEventArgs e) {
2183                         base.OnKeyUp(e);
2184                 }
2185
2186                 protected override void OnLayout (LayoutEventArgs e) {
2187                         base.OnLayout(e);
2188                 }
2189
2190                 protected override void OnLeave (EventArgs e) {
2191                         base.OnLeave(e);
2192                 }
2193
2194                 //protected override void OnMouseClick (MouseEventArgs e) {
2195                 protected void OnMouseClick (MouseEventArgs e) {
2196                         //base.OnMouseClick(e);
2197                         //Console.WriteLine("Mouse: Clicks: {0}; Delta: {1}; X: {2}; Y: {3};", e.Clicks, e.Delta, e.X, e.Y);
2198                 }
2199
2200                 //protected override void OnMouseDoubleClick (MouseEventArgs e) {
2201                 protected void OnMouseDoubleClick (MouseEventArgs e) {
2202                         //base.OnMouseDoubleClick(e);
2203                 }
2204
2205                 protected override void OnMouseDown (MouseEventArgs e) {
2206                         base.OnMouseDown(e);
2207                         //Console.WriteLine("Mouse: Clicks: {0}; Delta: {1}; X: {2}; Y: {3};", e.Clicks, e.Delta, e.X, e.Y);
2208                         HitTestInfo hitTest = HitTest(e.X, e.Y);
2209                         //Console.WriteLine("HitTest: Column: {0}; Row: {1};", hitTest.ColumnIndex, hitTest.RowIndex);
2210                         if (hitTest.RowIndex < 0 || hitTest.ColumnIndex < 0) {
2211                                 return;
2212                         }
2213                         OnCellClick(new DataGridViewCellEventArgs(hitTest.ColumnIndex, hitTest.RowIndex));
2214                         DataGridViewRow row = rows[hitTest.RowIndex];
2215                         DataGridViewCell cell = row.Cells[hitTest.ColumnIndex];
2216                         ClearSelection(0, 0, false);
2217                         switch (selectionMode) {
2218                                 case DataGridViewSelectionMode.FullRowSelect:
2219                                         row.Selected = true;
2220                                         break;
2221                                 case DataGridViewSelectionMode.FullColumnSelect:
2222                                         //////////////////
2223                                         break;
2224                                 default:
2225                                         cell.Selected = true;
2226                                         break;
2227                         }
2228                         if (cell == currentCell) {
2229                                 currentCell.SetIsInEditMode(true);
2230                                 OnCellBeginEdit(new DataGridViewCellCancelEventArgs(currentCell.ColumnIndex, currentCell.RowIndex));
2231                                 Invalidate();
2232                                 return;
2233                         }
2234                         if (currentCell != null) {
2235                                 if (currentCell.IsInEditMode) {
2236                                         currentCell.SetIsInEditMode(false);
2237                                         currentCell.DetachEditingControl();
2238                                         OnCellEndEdit(new DataGridViewCellEventArgs(currentCell.ColumnIndex, currentCell.RowIndex));
2239                                 }
2240                                 OnCellLeave(new DataGridViewCellEventArgs(currentCell.ColumnIndex, currentCell.RowIndex));
2241                         }
2242                         currentCell = cell;
2243                         OnCurrentCellChanged(EventArgs.Empty);
2244                         OnCellEnter(new DataGridViewCellEventArgs(cell.ColumnIndex, cell.RowIndex));
2245                         if (editMode == DataGridViewEditMode.EditOnEnter) {
2246                                 currentCell.SetIsInEditMode(true);
2247                                 OnCellBeginEdit(new DataGridViewCellCancelEventArgs(currentCell.ColumnIndex, currentCell.RowIndex));
2248                         }
2249                         Invalidate();
2250                         return;
2251                 }
2252
2253                 protected override void OnMouseEnter (EventArgs e) {
2254                         base.OnMouseEnter(e);
2255                 }
2256
2257                 protected override void OnMouseLeave (EventArgs e) {
2258                         base.OnMouseLeave(e);
2259                 }
2260
2261                 protected override void OnMouseMove (MouseEventArgs e) {
2262                         base.OnMouseMove(e);
2263                 }
2264
2265                 protected override void OnMouseUp (MouseEventArgs e) {
2266                         base.OnMouseUp(e);
2267                 }
2268
2269                 protected override void OnMouseWheel (MouseEventArgs e) {
2270                         base.OnMouseWheel(e);
2271                 }
2272
2273                 protected virtual void OnMultiSelectChanged (EventArgs e) {
2274                         if (MultiSelectChanged != null) {
2275                                 MultiSelectChanged(this, e);
2276                         }
2277                 }
2278
2279                 protected virtual void OnNewRowNeeded (DataGridViewRowEventArgs e) {
2280                         if (NewRowNeeded != null) {
2281                                 NewRowNeeded(this, e);
2282                         }
2283                 }
2284
2285                 protected override void OnPaint (PaintEventArgs e) {
2286                         base.OnPaint(e);
2287                         Console.WriteLine(e.ClipRectangle);
2288                         Rectangle bounds = ClientRectangle; //e.ClipRectangle;
2289                         e.Graphics.FillRectangle(new SolidBrush(backgroundColor), bounds);
2290                         Pen pen = new Pen(gridColor);
2291                         pen.Width = 1;
2292                         int i = 0;
2293                         ArrayList sortedColumns = columns.ColumnDisplayIndexSortedArrayList;
2294                         bounds.Y = -verticalScrollingOffset;
2295                         bounds.X = -horizontalScrollingOffset;
2296                         gridWidth = 0;
2297                         foreach (DataGridViewColumn col in sortedColumns) {
2298                                 gridWidth += col.Width;
2299                         }
2300                         if (columnHeadersVisible) {
2301                                 Rectangle headerBounds = bounds;
2302                                 if (rowHeadersVisible) {
2303                                         headerBounds.X += rowHeadersWidth;
2304                                 }
2305                                 headerBounds.Height = columnHeadersHeight;
2306                                 int j = 0;
2307                                 foreach (DataGridViewColumn col in sortedColumns) {
2308                                         headerBounds.Width = col.Width;
2309                                         DataGridViewCell cell = col.HeaderCell;
2310                                         DataGridViewCellStyle style = columnHeadersDefaultCellStyle;
2311                                         DataGridViewAdvancedBorderStyle intermediateBorderStyle = (DataGridViewAdvancedBorderStyle) this.AdvancedColumnHeadersBorderStyle.Clone();;
2312                                         DataGridViewAdvancedBorderStyle borderStyle = AdjustColumnHeaderBorderStyle(this.AdvancedColumnHeadersBorderStyle, intermediateBorderStyle, j == 0, j == columns.Count - 1);
2313                                         cell.InternalPaint(e.Graphics, e.ClipRectangle, headerBounds, cell.RowIndex, cell.State, cell.Value, cell.FormattedValue, cell.ErrorText, style, borderStyle, DataGridViewPaintParts.All);
2314                                         headerBounds.X += col.Width;
2315                                         j++;
2316                                 }
2317                                 bounds.Y += columnHeadersHeight;
2318                         }
2319                         gridHeight = 0;
2320                         foreach (DataGridViewRow row in rows) {
2321                                 gridHeight += row.Height;
2322                                 if (rowHeadersVisible) {
2323                                         Rectangle rowHeaderBounds = bounds;
2324                                         rowHeaderBounds.Height = row.Height;
2325                                         rowHeaderBounds.Width = rowHeadersWidth;
2326                                         DataGridViewCell cell = row.HeaderCell;
2327                                         DataGridViewCellStyle style = rowHeadersDefaultCellStyle;
2328                                         DataGridViewAdvancedBorderStyle intermediateBorderStyle = (DataGridViewAdvancedBorderStyle) this.AdvancedRowHeadersBorderStyle.Clone();;
2329                                         DataGridViewAdvancedBorderStyle borderStyle = cell.AdjustCellBorderStyle(this.AdvancedRowHeadersBorderStyle, intermediateBorderStyle, true, true, false, cell.RowIndex == 0);
2330                                         cell.InternalPaint(e.Graphics, e.ClipRectangle, rowHeaderBounds, cell.RowIndex, cell.State, cell.Value, cell.FormattedValue, cell.ErrorText, style, borderStyle, DataGridViewPaintParts.All);
2331                                         //e.Graphics.FillRectangle(new SolidBrush(rowHeadersDefaultCellStyle.BackColor), rowHeadersBounds);
2332                                         bounds.X += rowHeadersWidth;
2333                                 }
2334                                 bounds.Height = row.Height;
2335                                 for (int j = 0; j < sortedColumns.Count; j++) {
2336                                         DataGridViewColumn col = (DataGridViewColumn) sortedColumns[j];
2337                                         foreach (DataGridViewCell cell in row.Cells) {
2338                                                 if (cell.ColumnIndex == col.Index) {
2339                                                         bounds.Width = col.Width;
2340                                                         cell.SetSize(new Size(bounds.Width, bounds.Height));
2341                                                         DataGridViewCellStyle style = cell.InheritedStyle;
2342                                                         if (cell == currentCell && cell.IsInEditMode) {
2343                                                                 cell.InitializeEditingControl(cell.RowIndex, cell.FormattedValue, style);
2344                                                                 cell.PositionEditingControl(true, true, bounds, e.ClipRectangle, style, false, false, (columns[currentCell.ColumnIndex].DisplayIndex == 0), (currentCell.RowIndex == 0));
2345                                                         }
2346                                                         else {
2347                                                                 DataGridViewAdvancedBorderStyle intermediateBorderStyle = (DataGridViewAdvancedBorderStyle) this.AdvancedCellBorderStyle.Clone();;
2348                                                                 DataGridViewAdvancedBorderStyle borderStyle = cell.AdjustCellBorderStyle(this.AdvancedCellBorderStyle, intermediateBorderStyle, true, true, j == 0, cell.RowIndex == 0);
2349                                                                 OnCellFormatting(new DataGridViewCellFormattingEventArgs(cell.ColumnIndex, cell.RowIndex, cell.Value, cell.FormattedValueType, style));
2350                                                                 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);
2351                                                                 OnCellPainting(args);
2352                                                                 if (!args.Handled) {
2353                                                                         cell.InternalPaint(e.Graphics, e.ClipRectangle, bounds, cell.RowIndex, cell.State, cell.Value, cell.FormattedValue, cell.ErrorText, style, borderStyle, DataGridViewPaintParts.All);
2354                                                                 }
2355                                                         }
2356                                                         bounds.X += bounds.Width;
2357                                                 }
2358                                         }
2359                                 }
2360                                 bounds.Y += bounds.Height;
2361                                 bounds.X = -horizontalScrollingOffset;
2362                                 i++;
2363                         }
2364                         if (rowHeadersVisible) {
2365                                 gridWidth += rowHeadersWidth;
2366                         }
2367                         if (columnHeadersVisible) {
2368                                 gridHeight += columnHeadersHeight;
2369                         }
2370                         horizontalScrollBar.Visible = false;
2371                         verticalScrollBar.Visible = false;
2372                         if (AutoSize) {
2373                                 if (gridWidth > Size.Width || gridHeight > Size.Height) {
2374                                         Size = new Size(gridWidth, gridHeight);
2375                                 }
2376                         }
2377                         else {
2378                                 if (gridWidth > Size.Width) {
2379                                         horizontalScrollBar.Visible = true;
2380                                 }
2381                                 if (gridHeight > Size.Height) {
2382                                         verticalScrollBar.Visible = true;
2383                                 }
2384                                 if (horizontalScrollBar.Visible && (gridHeight + horizontalScrollBar.Height) > Size.Height) {
2385                                         verticalScrollBar.Visible = true;
2386                                 }
2387                                 if (verticalScrollBar.Visible && (gridWidth + horizontalScrollBar.Width) > Size.Width) {
2388                                         horizontalScrollBar.Visible = true;
2389                                 }
2390                                 if (horizontalScrollBar.Visible) {
2391                                         horizontalScrollBar.Minimum = 0;
2392                                         if (verticalScrollBar.Visible) {
2393                                                 horizontalScrollBar.Maximum = gridWidth - ClientRectangle.Width + verticalScrollBar.Width;
2394                                         }
2395                                         else {
2396                                                 horizontalScrollBar.Maximum = gridWidth - ClientRectangle.Width;
2397                                         }
2398                                         horizontalScrollBar.LargeChange = horizontalScrollBar.Maximum / 10;
2399                                         horizontalScrollBar.SmallChange = horizontalScrollBar.Maximum / 20;
2400                                 }
2401                                 if (verticalScrollBar.Visible) {
2402                                         verticalScrollBar.Minimum = 0;
2403                                         if (horizontalScrollBar.Visible) {
2404                                                 verticalScrollBar.Maximum = gridHeight - ClientRectangle.Height + horizontalScrollBar.Height;
2405                                         }
2406                                         else {
2407                                                 verticalScrollBar.Maximum = gridHeight - ClientRectangle.Height;
2408                                         }
2409                                         verticalScrollBar.LargeChange = verticalScrollBar.Maximum / 10;
2410                                         verticalScrollBar.SmallChange = verticalScrollBar.Maximum / 20;
2411                                 }
2412                         }
2413                         if (horizontalScrollBar.Visible && !this.Controls.Contains(horizontalScrollBar)) {
2414                                 this.Controls.Add(horizontalScrollBar);
2415                         }
2416                         else if (!horizontalScrollBar.Visible && this.Controls.Contains(horizontalScrollBar)) {
2417                                 this.Controls.Remove(horizontalScrollBar);
2418                         }
2419                         if (verticalScrollBar.Visible && !this.Controls.Contains(verticalScrollBar)) {
2420                                 this.Controls.Add(verticalScrollBar);
2421                         }
2422                         else if (!verticalScrollBar.Visible && this.Controls.Contains(verticalScrollBar)) {
2423                                 this.Controls.Remove(verticalScrollBar);
2424                         }
2425                 }
2426
2427                 protected virtual void OnReadOnlyChanged (EventArgs e) {
2428                         if (ReadOnlyChanged != null) {
2429                                 ReadOnlyChanged(this, e);
2430                         }
2431                 }
2432
2433                 protected override void OnResize (EventArgs e) {
2434                         base.OnResize(e);
2435                         horizontalScrollingOffset = ((gridWidth - Size.Width) > 0)? (gridWidth - Size.Width) : 0;
2436                         verticalScrollingOffset = ((gridHeight - Size.Height) > 0)? (gridHeight - Size.Height) : 0;
2437
2438                 }
2439
2440                 protected override void OnRightToLeftChanged (EventArgs e) {
2441                         base.OnRightToLeftChanged(e);
2442                 }
2443
2444                 // In MSDN2 documentation there's no internal here
2445                 protected internal virtual void OnRowContextMenuStripChanged (DataGridViewRowEventArgs e) {
2446                         if (RowContextMenuStripChanged != null) {
2447                                 RowContextMenuStripChanged(this, e);
2448                         }
2449                 }
2450
2451                 protected virtual void OnRowContextMenuStripNeeded (DataGridViewRowContextMenuStripNeededEventArgs e) {
2452                         if (RowContextMenuStripNeeded != null) {
2453                                 RowContextMenuStripNeeded(this, e);
2454                         }
2455                 }
2456
2457                 // In MSDN2 documentation there's no internal here
2458                 protected internal virtual void OnRowDefaultCellStyleChanged (DataGridViewRowEventArgs e) {
2459                         if (RowDefaultCellStyleChanged != null) {
2460                                 RowDefaultCellStyleChanged(this, e);
2461                         }
2462                 }
2463
2464                 protected virtual void OnRowDirtyStateNeeded (QuestionEventArgs e) {
2465                         if (RowDirtyStateNeeded != null) {
2466                                 RowDirtyStateNeeded(this, e);
2467                         }
2468                 }
2469
2470                 protected virtual void OnRowDividerDoubleClick (DataGridViewRowDividerDoubleClickEventArgs e) {
2471                         if (RowDividerDoubleClick != null) {
2472                                 RowDividerDoubleClick(this, e);
2473                         }
2474                 }
2475
2476                 protected virtual void OnRowDividerHeightChanged (DataGridViewRowEventArgs e) {
2477                         if (RowDividerHeightChanged != null) {
2478                                 RowDividerHeightChanged(this, e);
2479                         }
2480                 }
2481
2482                 protected virtual void OnRowEnter (DataGridViewCellEventArgs e) {
2483                         if (RowEnter != null) {
2484                                 RowEnter(this, e);
2485                         }
2486                 }
2487
2488                 // In MSDN2 documentation there's no internal here
2489                 protected internal virtual void OnRowErrorTextChanged (DataGridViewRowEventArgs e) {
2490                         if (RowErrorTextChanged != null) {
2491                                 RowErrorTextChanged(this, e);
2492                         }
2493                 }
2494
2495                 protected virtual void OnRowErrorTextNeeded (DataGridViewRowErrorTextNeededEventArgs e) {
2496                         if (RowErrorTextNeeded != null) {
2497                                 RowErrorTextNeeded(this, e);
2498                         }
2499                 }
2500
2501                 // In MSDN2 documentation there's no internal here
2502                 protected internal virtual void OnRowHeaderCellChanged (DataGridViewRowEventArgs e) {
2503                         if (RowHeaderCellChanged != null) {
2504                                 RowHeaderCellChanged(this, e);
2505                         }
2506                 }
2507
2508                 protected virtual void OnRowHeaderMouseClick (DataGridViewCellMouseEventArgs e) {
2509                         if (RowHeaderMouseClick != null) {
2510                                 RowHeaderMouseClick(this, e);
2511                         }
2512                 }
2513
2514                 protected virtual void OnRowHeaderMouseDoubleClick (DataGridViewCellMouseEventArgs e) {
2515                         if (RowHeaderMouseDoubleClick != null) {
2516                                 RowHeaderMouseDoubleClick(this, e);
2517                         }
2518                 }
2519
2520                 protected virtual void OnRowHeadersBorderStyleChanged (EventArgs e) {
2521                         if (RowHeadersBorderStyleChanged != null) {
2522                                 RowHeadersBorderStyleChanged(this, e);
2523                         }
2524                 }
2525
2526                 protected virtual void OnRowHeadersDefaultCellStyleChanged (EventArgs e) {
2527                         if (RowHeadersDefaultCellStyleChanged != null) {
2528                                 RowHeadersDefaultCellStyleChanged(this, e);
2529                         }
2530                 }
2531
2532                 protected virtual void OnRowHeadersWidthChanged (EventArgs e) {
2533                         if (RowHeadersWidthChanged != null) {
2534                                 RowHeadersWidthChanged(this, e);
2535                         }
2536                 }
2537
2538                 protected virtual void OnRowHeadersWidthSizeModeChanged (DataGridViewAutoSizeModeEventArgs e) {
2539                         if (RowHeadersWidthSizeModeChanged != null) {
2540                                 RowHeadersWidthSizeModeChanged(this, e);
2541                         }
2542                 }
2543
2544                 // In MSDN2 documentation there's no internal here
2545                 protected internal virtual void OnRowHeightChanged (DataGridViewRowEventArgs e) {
2546                         if (RowHeightChanged != null) {
2547                                 RowHeightChanged(this, e);
2548                         }
2549                 }
2550
2551                 protected virtual void OnRowHeightInfoNeeded (DataGridViewRowHeightInfoNeededEventArgs e) {
2552                         if (RowHeightInfoNeeded != null) {
2553                                 RowHeightInfoNeeded(this, e);
2554                         }
2555                 }
2556
2557                 protected virtual void OnRowHeightInfoPushed (DataGridViewRowHeightInfoPushedEventArgs e) {
2558                         if (RowHeightInfoPushed != null) {
2559                                 RowHeightInfoPushed(this, e);
2560                         }
2561                 }
2562
2563                 protected virtual void OnRowLeave (DataGridViewCellEventArgs e) {
2564                         if (RowLeave != null) {
2565                                 RowLeave(this, e);
2566                         }
2567                 }
2568
2569                 // In MSDN2 documentation there's no internal here
2570                 protected internal virtual void OnRowMinimumHeightChanged (DataGridViewRowEventArgs e) {
2571                         if (RowMinimumHeightChanged != null) {
2572                                 RowMinimumHeightChanged(this, e);
2573                         }
2574                 }
2575
2576                 protected internal virtual void OnRowPostPaint (DataGridViewRowPostPaintEventArgs e) {
2577                         if (RowPostPaint != null) {
2578                                 RowPostPaint(this, e);
2579                         }
2580                 }
2581
2582                 protected internal virtual void OnRowPrePaint (DataGridViewRowPrePaintEventArgs e) {
2583                         if (RowPrePaint != null) {
2584                                 RowPrePaint(this, e);
2585                         }
2586                 }
2587
2588                 // In MSDN2 documentation there's no internal here
2589                 protected internal virtual void OnRowsAdded (DataGridViewRowsAddedEventArgs e) {
2590                         if (RowsAdded != null) {
2591                                 RowsAdded(this, e);
2592                         }
2593                 }
2594
2595                 protected virtual void OnRowsDefaultCellStyleChanged (EventArgs e) {
2596                         if (RowsDefaultCellStyleChanged != null) {
2597                                 RowsDefaultCellStyleChanged(this, e);
2598                         }
2599                 }
2600
2601                 // In MSDN2 documentation there's no internal here
2602                 protected internal virtual void OnRowsRemoved (DataGridViewRowsRemovedEventArgs e) {
2603                         if (RowsRemoved != null) {
2604                                 RowsRemoved(this, e);
2605                         }
2606                 }
2607
2608                 // In MSDN2 documentation there's no internal here
2609                 protected internal virtual void OnRowStateChanged (int rowIndex, DataGridViewRowStateChangedEventArgs e) {
2610                         if (RowStateChanged != null) {
2611                                 RowStateChanged(this, e);
2612                         }
2613                 }
2614
2615                 protected virtual void OnRowUnshared (DataGridViewRowEventArgs e) {
2616                         if (RowUnshared != null) {
2617                                 RowUnshared(this, e);
2618                         }
2619                 }
2620
2621                 protected virtual void OnRowValidated (DataGridViewCellEventArgs e) {
2622                         if (RowValidated != null) {
2623                                 RowValidated(this, e);
2624                         }
2625                 }
2626
2627                 protected virtual void OnRowValidating (DataGridViewCellCancelEventArgs e) {
2628                         if (RowValidating != null) {
2629                                 RowValidating(this, e);
2630                         }
2631                 }
2632
2633                 protected virtual void OnScroll (ScrollEventArgs e) {
2634                         if (Scroll != null) {
2635                                 Scroll(this, e);
2636                         }
2637                 }
2638
2639                 protected virtual void OnSelectionChanged (EventArgs e) {
2640                         if (SelectionChanged != null) {
2641                                 SelectionChanged(this, e);
2642                         }
2643                 }
2644
2645                 protected virtual void OnSortCompare (DataGridViewSortCompareEventArgs e) {
2646                         if (SortCompare != null) {
2647                                 SortCompare(this, e);
2648                         }
2649                 }
2650
2651                 protected virtual void OnSorted (EventArgs e) {
2652                         if (Sorted != null) {
2653                                 Sorted(this, e);
2654                         }
2655                 }
2656
2657                 protected virtual void OnUserAddedRow (DataGridViewRowEventArgs e) {
2658                         if (UserAddedRow != null) {
2659                                 UserAddedRow(this, e);
2660                         }
2661                 }
2662
2663                 protected virtual void OnUserDeletedRow (DataGridViewRowEventArgs e) {
2664                         if (UserDeletedRow != null) {
2665                                 UserDeletedRow(this, e);
2666                         }
2667                 }
2668
2669                 protected virtual void OnUserDeletingRow (DataGridViewRowCancelEventArgs e) {
2670                         if (UserDeletingRow != null) {
2671                                 UserDeletingRow(this, e);
2672                         }
2673                 }
2674
2675                 protected override void OnValidating (CancelEventArgs e) {
2676                         base.OnValidating(e);
2677                 }
2678
2679                 protected override void OnVisibleChanged (EventArgs e) {
2680                         base.OnVisibleChanged(e);
2681                 }
2682
2683                 protected virtual void PaintBackground (Graphics graphics, Rectangle clipBounds, Rectangle gridBounds) {
2684                 }
2685
2686                 protected bool ProcessAKey (Keys keyData) {
2687                         throw new NotImplementedException();
2688                 }
2689
2690                 protected bool ProcessDataGridViewKey (KeyEventArgs e) {
2691                         throw new NotImplementedException();
2692                 }
2693
2694                 protected bool ProcessDeleteKey (Keys keyData) {
2695                         throw new NotImplementedException();
2696                 }
2697
2698                 protected override bool ProcessDialogKey (Keys keyData) {
2699                         return base.ProcessDialogKey(keyData);
2700                         //throw new NotImplementedException();
2701                 }
2702
2703                 protected bool ProcessDownKey (Keys keyData) {
2704                         throw new NotImplementedException();
2705                 }
2706
2707                 protected bool ProcessEndKey (Keys keyData) {
2708                         throw new NotImplementedException();
2709                 }
2710
2711                 protected bool ProcessEnterKey (Keys keyData) {
2712                         throw new NotImplementedException();
2713                 }
2714
2715                 protected bool ProcessEscapeKey (Keys keyData) {
2716                         throw new NotImplementedException();
2717                 }
2718
2719                 protected bool ProcessF2Key (Keys keyData) {
2720                         throw new NotImplementedException();
2721                 }
2722
2723                 protected bool ProcessHomeKey (Keys keyData) {
2724                         throw new NotImplementedException();
2725                 }
2726
2727                 protected bool ProcessInsertKey (Keys keyData) {
2728                         throw new NotImplementedException();
2729                 }
2730
2731                 protected override bool ProcessKeyEventArgs (ref Message m) {
2732                         return base.ProcessKeyEventArgs(ref m);
2733                         //throw new NotImplementedException();
2734                 }
2735
2736                 protected override bool ProcessKeyPreview (ref Message m) {
2737                         return base.ProcessKeyPreview(ref m);
2738                         //throw new NotImplementedException();
2739                 }
2740
2741                 protected bool ProcessLeftKey (Keys keyData) {
2742                         throw new NotImplementedException();
2743                 }
2744
2745                 protected bool ProcessNextKey (Keys keyData) {
2746                         // PAGE DOWN
2747                         throw new NotImplementedException();
2748                 }
2749
2750                 protected bool ProcessPriorKey (Keys keyData) {
2751                         // PAGE UP
2752                         throw new NotImplementedException();
2753                 }
2754
2755                 protected bool ProcessRightKey (Keys keyData) {
2756                         throw new NotImplementedException();
2757                 }
2758
2759                 protected bool ProcessSpaceKey (Keys keyData) {
2760                         throw new NotImplementedException();
2761                 }
2762
2763                 protected bool ProcessTabKey (Keys keyData) {
2764                         throw new NotImplementedException();
2765                 }
2766
2767                 protected bool ProcessUpKey (Keys keyData) {
2768                         throw new NotImplementedException();
2769                 }
2770
2771                 protected bool ProcessZeroKey (Keys keyData) {
2772                         throw new NotImplementedException();
2773                 }
2774
2775                 protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified) {
2776                         base.SetBoundsCore(x, y, width, height, specified);
2777                 }
2778
2779                 protected virtual bool SetCurrentCellAddressCore (int columnIndex, int rowIndex, bool setAnchorCellAddress, bool validateCurrentCell, bool throughMouseClick) {
2780                         throw new NotImplementedException();
2781                 }
2782
2783                 protected virtual void SetSelectedCellCore (int columnIndex, int rowIndex, bool selected) {
2784                         throw new NotImplementedException();
2785                 }
2786
2787                 protected virtual void SetSelectedColumnCore (int columnIndex, bool selected) {
2788                         throw new NotImplementedException();
2789                 }
2790
2791                 protected virtual void SetSelectedRowCore (int rowIndex, bool selected) {
2792                         throw new NotImplementedException();
2793                 }
2794
2795                 protected override void WndProc (ref Message m) {
2796                         base.WndProc(ref m);
2797                 }
2798
2799                 internal void InternalOnCellClick (DataGridViewCellEventArgs e) {
2800                         OnCellClick(e);
2801                 }
2802
2803                 internal void InternalOnCellContentClick (DataGridViewCellEventArgs e) {
2804                         OnCellContentClick(e);
2805                 }
2806
2807                 internal void InternalOnCellContentDoubleClick (DataGridViewCellEventArgs e) {
2808                         OnCellContentDoubleClick(e);
2809                 }
2810
2811                 internal void InternalOnCellValueChanged (DataGridViewCellEventArgs e) {
2812                         OnCellValueChanged(e);
2813                 }
2814
2815                 internal void InternalOnDataError (DataGridViewDataErrorEventArgs e) {
2816                         /////////////// false? ////////////
2817                         OnDataError(false, e);
2818                 }
2819
2820                 internal void InternalOnMouseWheel (MouseEventArgs e) {
2821                         OnMouseWheel(e);
2822                 }
2823
2824                 internal void OnHScrollBarScroll (object sender, ScrollEventArgs e) {
2825                         horizontalScrollingOffset = e.NewValue;
2826                         Invalidate();
2827                         OnScroll(e);
2828                 }
2829
2830                 internal void OnVScrollBarScroll (object sender, ScrollEventArgs e) {
2831                         verticalScrollingOffset = e.NewValue;
2832                         Invalidate();
2833                         OnScroll(e);
2834                 }
2835
2836                 internal void RaiseCellStyleChanged (DataGridViewCellEventArgs e) {
2837                         OnCellStyleChanged(e);
2838                 }
2839
2840                 internal void OnColumnCollectionChanged (object sender, CollectionChangeEventArgs e) {
2841                         switch (e.Action) {
2842                                 case CollectionChangeAction.Add:
2843                                         OnColumnAdded(new DataGridViewColumnEventArgs(e.Element as DataGridViewColumn));
2844                                         break;
2845                                 case CollectionChangeAction.Remove:
2846                                         OnColumnRemoved(new DataGridViewColumnEventArgs(e.Element as DataGridViewColumn));
2847                                         break;
2848                                 case CollectionChangeAction.Refresh:
2849                                         break;
2850                         }
2851                 }
2852
2853                 private void BindIList (IList list) {
2854                         if (list.Count > 0) {
2855                                 DataGridViewCell template = new DataGridViewTextBoxCell();
2856                                 foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(list[0])) {
2857                                         DataGridViewColumn col = new DataGridViewColumn(template);
2858                                         col.Name = property.DisplayName;
2859                                         columns.Add(col);
2860                                 }
2861                         }
2862                         foreach (object element in list) {
2863                                 DataGridViewRow row = new DataGridViewRow();
2864                                 rows.InternalAdd(row);
2865                                 PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(element);
2866                                 foreach (PropertyDescriptor property in properties) {
2867                                         DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell();
2868                                         cell.Value = property.GetValue(element);
2869                                         cell.ValueType = property.PropertyType;
2870                                         row.Cells.Add(cell);
2871                                 }
2872                         }
2873                 }
2874
2875                 private void BindIListSource (IListSource list) {
2876                         BindIList(list.GetList());
2877                 }
2878
2879                 private void BindIBindingList (IBindingList list) {
2880                         BindIList(list);
2881                 }
2882
2883                 private void BindIBindingListView (IBindingListView list) {
2884                         BindIList(list);
2885                 }
2886
2887                 public sealed class HitTestInfo {
2888
2889                         public static readonly HitTestInfo Nowhere = new HitTestInfo(-1, -1, -1, -1, DataGridViewHitTestType.None);
2890
2891                         private int columnIndex;
2892                         private int columnX;
2893                         private int rowIndex;
2894                         private int rowY;
2895                         private DataGridViewHitTestType type;
2896
2897                         internal HitTestInfo (int columnIndex, int columnX, int rowIndex, int rowY, DataGridViewHitTestType type) {
2898                                 this.columnIndex = columnIndex;
2899                                 this.columnX = columnX;
2900                                 this.rowIndex = rowIndex;
2901                                 this.rowY = rowY;
2902                                 this.type = type;
2903                         }
2904
2905                         public int ColumnIndex {
2906                                 get { return columnIndex; }
2907                         }
2908
2909                         public int ColumnX {
2910                                 get { return columnX; }
2911                         }
2912
2913                         public int RowIndex {
2914                                 get { return rowIndex; }
2915                         }
2916
2917                         public int RowY {
2918                                 get { return rowY; }
2919                         }
2920
2921                         public DataGridViewHitTestType Type {
2922                                 get { return type; }
2923                         }
2924
2925                         public override bool Equals (object value) {
2926                                 if (value is HitTestInfo) {
2927                                         HitTestInfo aux = (HitTestInfo) value;
2928                                         if (aux.columnIndex == columnIndex && aux.columnX == columnX && aux.rowIndex == rowIndex && aux.rowY == rowY && aux.type == type) {
2929                                                 return true;
2930                                         }
2931                                 }
2932                                 return false;
2933                         }
2934
2935                         public override int GetHashCode () {
2936                                 return base.GetHashCode();
2937                         }
2938
2939                         public override string ToString () {
2940                                 return GetType().Name;
2941                         }
2942
2943                 }
2944
2945                 [ComVisibleAttribute(true)]
2946                 protected class DataGridViewAccessibleObject : ControlAccessibleObject {
2947
2948                         public DataGridViewAccessibleObject (DataGridView owner) : base (owner){
2949                         }
2950
2951                         public override AccessibleRole Role {
2952                                 get { return base.Role; }
2953                         }
2954
2955                         public override AccessibleObject GetChild (int index) {
2956                                 return base.GetChild(index);
2957                         }
2958
2959                         public override int GetChildCount () {
2960                                 return base.GetChildCount();
2961                         }
2962
2963                         public override AccessibleObject GetFocused () {
2964                                 return base.GetFocused();
2965                         }
2966
2967                         public override AccessibleObject GetSelected () {
2968                                 return base.GetSelected();
2969                         }
2970
2971                         public override AccessibleObject HitTest (int x, int y) {
2972                                 return base.HitTest(x, y);
2973                         }
2974
2975                         public override AccessibleObject Navigate( AccessibleNavigation navigationDirection) {
2976                                 return base.Navigate(navigationDirection);
2977                         }
2978
2979                 }
2980
2981         }
2982
2983 }
2984
2985 #endif