1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
23 // Pedro MartÃnez Juliá <pedromj@gmail.com>
30 using System.ComponentModel;
31 using System.Runtime.InteropServices;
33 using System.Collections;
35 namespace System.Windows.Forms {
37 [ComVisibleAttribute(true)]
38 [ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
39 public class DataGridView : Control, ISupportInitialize {
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;
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;
115 internal int gridWidth;
116 internal int gridHeight;
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;
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;
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;
183 public void BeginInit () {
186 public void EndInit () {
191 public virtual DataGridViewAdvancedBorderStyle AdjustedTopLeftHeaderBorderStyle {
192 get { return adjustedTopLeftHeaderBorderStyle; }
195 public DataGridViewAdvancedBorderStyle AdvancedCellBorderStyle {
196 get { return advancedCellBorderStyle; }
199 public DataGridViewAdvancedBorderStyle AdvancedColumnHeadersBorderStyle {
200 get { return advancedColumnHeadersBorderStyle; }
203 public DataGridViewAdvancedBorderStyle AdvancedRowHeadersBorderStyle {
204 get { return advancedRowHeadersBorderStyle; }
207 public bool AllowUserToAddRows {
208 get { return allowUserToAddRows; }
210 if (allowUserToAddRows != value) {
211 allowUserToAddRows = value;
212 OnAllowUserToAddRowsChanged(EventArgs.Empty);
217 public bool AllowUserToDeleteRows {
218 get { return allowUserToDeleteRows; }
220 if (allowUserToDeleteRows != value) {
221 allowUserToDeleteRows = value;
222 OnAllowUserToDeleteRowsChanged(EventArgs.Empty);
227 public bool AllowUserToOrderColumns {
228 get { return allowUserToOrderColumns; }
230 if (allowUserToOrderColumns != value) {
231 allowUserToOrderColumns = value;
232 OnAllowUserToOrderColumnsChanged(EventArgs.Empty);
237 public bool AllowUserToResizeColumns {
238 get { return allowUserToResizeColumns; }
240 if (allowUserToResizeColumns != value) {
241 allowUserToResizeColumns = value;
242 OnAllowUserToResizeColumnsChanged(EventArgs.Empty);
247 public bool AllowUserToResizeRows {
248 get { return allowUserToResizeRows; }
250 if (allowUserToResizeRows != value) {
251 allowUserToResizeRows = value;
252 OnAllowUserToResizeRowsChanged(EventArgs.Empty);
257 public DataGridViewCellStyle AlternatingRowsDefaultCellStyle {
258 get { return alternatingRowsDefaultCellStyle; }
260 if (alternatingRowsDefaultCellStyle != value) {
261 alternatingRowsDefaultCellStyle = value;
262 OnAlternatingRowsDefaultCellStyleChanged(EventArgs.Empty);
268 public bool AutoGenerateColumns {
269 get { return autoGenerateColumns; }
271 if (autoGenerateColumns != value) {
272 autoGenerateColumns = value;
273 OnAutoGenerateColumnsChanged(EventArgs.Empty);
278 //public override bool AutoSize {
279 public bool AutoSize {
280 get { return autoSize; }
282 if (autoSize != value) {
284 //OnAutoSizeChanged(EventArgs.Empty);
289 public DataGridViewAutoSizeColumnsMode AutoSizeColumnsMode {
290 get { return autoSizeColumnsMode; }
292 if (!Enum.IsDefined(typeof(DataGridViewAutoSizeColumnsMode), value)) {
293 throw new InvalidEnumArgumentException("Value is not valid DataGridViewAutoSizeColumnsMode.");
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.");
302 if (value == DataGridViewAutoSizeColumnsMode.Fill) {
303 foreach (DataGridViewColumn col in columns) {
304 if (col.AutoSizeMode == DataGridViewAutoSizeColumnMode.NotSet) {
306 throw new InvalidOperationException("Cant set this property to Fill in this DataGridView.");
311 autoSizeColumnsMode = value;
315 public DataGridViewAutoSizeRowsMode AutoSizeRowsMode {
316 get { return autoSizeRowsMode; }
318 if (autoSizeRowsMode != value) {
319 if (!Enum.IsDefined(typeof(DataGridViewAutoSizeRowsMode), value)) {
320 throw new InvalidEnumArgumentException("Value is not valid DataGridViewRowsMode.");
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.");
325 autoSizeRowsMode = value;
326 OnAutoSizeRowsModeChanged(new DataGridViewAutoSizeModeEventArgs(false));
327 ////////////////////////////////////////////////////////////////
332 public override Color BackColor {
333 get { return backColor; }
335 if (backColor != value) {
337 OnBackColorChanged(EventArgs.Empty);
342 public Color BackgroundColor {
343 get { return backgroundColor; }
345 if (backgroundColor != value) {
346 if (value == Color.Empty) {
347 throw new ArgumentException("Cant set an Empty color.");
349 backgroundColor = value;
350 OnBackgroundColorChanged(EventArgs.Empty);
355 public override Image BackgroundImage {
356 get { return backgroundImage; }
358 if (backgroundImage != value) {
359 backgroundImage = value;
360 OnBackgroundImageChanged(EventArgs.Empty);
365 //public override ImageLayout BackgroundImageLayout {
366 public ImageLayout BackgroundImageLayout {
367 get { return backgroundImageLayout; }
369 if (backgroundImageLayout != value) {
370 backgroundImageLayout = value;
371 //OnBackgroundImageLayoutChanged(EventArg.Empty);
376 public BorderStyle BorderStyle {
377 get { return borderStyle; }
379 if (borderStyle != value) {
380 if (!Enum.IsDefined(typeof(BorderStyle), value)) {
381 throw new InvalidEnumArgumentException("Invalid border style.");
384 OnBorderStyleChanged(EventArgs.Empty);
389 public DataGridViewCellBorderStyle CellBorderStyle {
390 get { return cellBorderStyle; }
392 if (cellBorderStyle != value) {
393 cellBorderStyle = value;
394 OnCellBorderStyleChanged(EventArgs.Empty);
399 public DataGridViewClipboardCopyMode ClipboardCopyMode {
400 get { return clipboardCopyMode; }
401 set { clipboardCopyMode = value; }
404 public int ColumnCount {
405 get { return columns.Count; }
408 throw new ArgumentException("ColumnCount must be >= 0.");
410 if (dataSource != null) {
411 throw new InvalidOperationException("Cant change column count if DataSource is set.");
413 if (value < columns.Count) {
414 for (int i = value; i < columns.Count; i++) {
418 else if (value > columns.Count) {
419 for (int i = 0; i < value; i++) {
420 DataGridViewColumn col = new DataGridViewColumn();
427 public DataGridViewHeaderBorderStyle ColumnHeadersBorderStyle {
428 get { return columnHeadersBorderStyle; }
430 if (columnHeadersBorderStyle != value) {
431 columnHeadersBorderStyle = value;
432 OnColumnHeadersBorderStyleChanged(EventArgs.Empty);
437 public DataGridViewCellStyle ColumnHeadersDefaultCellStyle {
438 get { return columnHeadersDefaultCellStyle; }
440 if (columnHeadersDefaultCellStyle != value) {
441 columnHeadersDefaultCellStyle = value;
442 OnColumnHeadersDefaultCellStyleChanged(EventArgs.Empty);
447 public int ColumnHeadersHeight {
448 get { return columnHeadersHeight; }
450 if (columnHeadersHeight != value) {
452 throw new ArgumentException("Column headers height cant be less than 4.");
454 columnHeadersHeight = value;
455 OnColumnHeadersHeightChanged(EventArgs.Empty);
460 public DataGridViewColumnHeadersHeightSizeMode ColumnHeadersHeightSizeMode {
461 get { return columnHeadersHeightSizeMode; }
463 if (columnHeadersHeightSizeMode != value) {
464 if (!Enum.IsDefined(typeof(DataGridViewColumnHeadersHeightSizeMode), value)) {
465 throw new InvalidEnumArgumentException("Value is not a valid DataGridViewColumnHeadersHeightSizeMode.");
467 columnHeadersHeightSizeMode = value;
468 OnColumnHeadersHeightSizeModeChanged(new DataGridViewAutoSizeModeEventArgs(false));
473 public bool ColumnHeadersVisible {
474 get { return columnHeadersVisible; }
475 set { columnHeadersVisible = value; }
478 public DataGridViewColumnCollection Columns {
479 get { return columns; }
482 public DataGridViewCell CurrentCell {
483 get { return currentCell; }
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
490 /////////////////////////////////////////////////////
491 if (value.DataGridView != this) {
492 throw new ArgumentException("The cell is not in this DataGridView.");
498 public Point CurrentCellAddress {
499 get { return currentCellAddress; }
502 public DataGridViewRow CurrentRow {
503 get { return currentRow; }
506 public string DataMember {
507 get { return dataMember; }
509 if (dataMember != value) {
511 OnDataMemberChanged(EventArgs.Empty);
516 public object DataSource {
517 get { return dataSource; }
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.
526 if (!(value is IList) && !(value is IListSource) && !(value is IBindingList) && !(value is IBindingListView)) {
527 throw new NotSupportedException("Type cant be binded.");
530 OnDataSourceChanged(EventArgs.Empty);
532 if (value is IList) {
533 BindIList(value as IList);
535 else if (value is IListSource) {
536 BindIListSource(value as IListSource);
538 else if (value is IBindingList) {
539 BindIBindingList(value as IBindingList);
541 else if (value is IBindingListView) {
542 BindIBindingListView(value as IBindingListView);
543 //bool cosa = ((value as IBindingListView).SortDescriptions as IList).IsFixedSize;
545 OnDataBindingComplete(new DataGridViewBindingCompleteEventArgs(ListChangedType.Reset));
550 public DataGridViewCellStyle DefaultCellStyle {
551 get { return defaultCellStyle; }
553 if (defaultCellStyle != value) {
554 defaultCellStyle = value;
555 OnDefaultCellStyleChanged(EventArgs.Empty);
560 public override Rectangle DisplayRectangle {
561 get { return base.DisplayRectangle; }
564 public Control EditingControl {
566 if (currentCell == null || !currentCell.IsInEditMode) {
569 return (Control) Activator.CreateInstance(currentCell.EditType);
573 public Panel EditingPanel {
574 get { throw new NotImplementedException(); }
577 public DataGridViewEditMode EditMode {
578 get { return editMode; }
580 if (editMode != value) {
582 OnEditModeChanged(EventArgs.Empty);
587 public bool EnableHeadersVisualStyles {
588 get { return enableHeadersVisualStyles; }
589 set { enableHeadersVisualStyles = value; }
592 public DataGridViewCell FirstDisplayedCell {
593 get { return firstDisplayedCell; }
595 if (value.DataGridView != this) {
596 throw new ArgumentException("The cell is not in this DataGridView.");
598 firstDisplayedCell = value;
602 public int FirstDisplayedScrollingColumnHiddenWidth {
603 get { return firstDisplayedScrollingColumnHiddenWidth; }
606 public int FirstDisplayedScrollingColumnIndex {
607 get { return firstDisplayedScrollingColumnIndex; }
608 set { firstDisplayedScrollingColumnIndex = value; }
611 public int FirstDisplayedScrollingRowIndex {
612 get { return firstDisplayedScrollingRowIndex; }
613 set { firstDisplayedScrollingRowIndex = value; }
616 public override Font Font {
621 OnFontChanged(EventArgs.Empty);
626 public override Color ForeColor {
627 get { return foreColor; }
629 if (foreColor != value) {
631 OnForeColorChanged(EventArgs.Empty);
636 public Color GridColor {
637 get { return gridColor; }
639 if (gridColor != value) {
640 if (value == Color.Empty) {
641 throw new ArgumentException("Cant set an Empty color.");
644 OnGridColorChanged(EventArgs.Empty);
649 public int HorizontalScrollingOffset {
650 get { return horizontalScrollingOffset; }
651 set { horizontalScrollingOffset = value; }
654 public bool IsCurrentCellDirty {
655 get { return isCurrentCellDirty; }
658 public bool IsCurrentCellInEditMode {
660 if (currentCell == null) {
663 return currentCell.IsInEditMode;
667 public bool IsCurrentRowDirty {
670 return IsCurrentCellDirty;
673 throw new NotImplementedException();
677 public DataGridViewCell this [int columnIndex, int rowIndex] {
678 get { return rows[rowIndex].Cells[columnIndex]; }
679 set { rows[rowIndex].Cells[columnIndex] = value; }
682 public DataGridViewCell this [string columnName, int rowIndex] {
684 int columnIndex = -1;
685 foreach (DataGridViewColumn col in columns) {
686 if (col.Name == columnName) {
687 columnIndex = col.Index;
691 return this[columnIndex, rowIndex];
694 int columnIndex = -1;
695 foreach (DataGridViewColumn col in columns) {
696 if (col.Name == columnName) {
697 columnIndex = col.Index;
701 this[columnIndex, rowIndex] = value;
705 public bool MultiSelect {
706 get { return multiSelect; }
708 if (multiSelect != value) {
710 OnMultiSelectChanged(EventArgs.Empty);
715 public int NewRowIndex {
717 if (!allowUserToAddRows) {
720 return rows.Count - 1;
724 public new Padding Padding {
725 get { return Padding.Empty; }
729 public bool ReadOnly {
730 get { return readOnly; }
732 if (readOnly != value) {
734 OnReadOnlyChanged(EventArgs.Empty);
739 public int RowCount {
740 get { return rows.Count; }
743 throw new ArgumentException("RowCount must be >= 0.");
745 if (value < 1 && allowUserToAddRows) {
746 throw new ArgumentException("RowCount must be >= 1 if AllowUserToAddRows is true.");
748 if (dataSource != null) {
749 throw new InvalidOperationException("Cant change row count if DataSource is set.");
751 if (value < rows.Count) {
752 for (int i = value; i < rows.Count; i++) {
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();
761 foreach (DataGridViewColumn col in columns) {
762 row.Cells.Add(col.CellTemplate.Clone() as DataGridViewCell);
766 if (ColumnCount == 0) {
767 ///////////////////////////////////////////////////////////////
768 //columns.Add(new DataGridViewTextBoxColumn());
769 throw new NotImplementedException();
774 public DataGridViewHeaderBorderStyle RowHeadersBorderStyle {
775 get { return rowHeadersBorderStyle; }
777 if (rowHeadersBorderStyle != value) {
778 rowHeadersBorderStyle = value;
779 OnRowHeadersBorderStyleChanged(EventArgs.Empty);
784 public DataGridViewCellStyle RowHeadersDefaultCellStyle {
785 get { return rowHeadersDefaultCellStyle; }
787 if (rowHeadersDefaultCellStyle != value) {
788 rowHeadersDefaultCellStyle = value;
789 OnRowHeadersDefaultCellStyleChanged(EventArgs.Empty);
794 public bool RowHeadersVisible {
795 get { return rowHeadersVisible; }
796 set { rowHeadersVisible = value; }
799 public int RowHeadersWidth {
800 get { return rowHeadersWidth; }
802 if (rowHeadersWidth != value) {
804 throw new ArgumentException("RowHeadersWidth cant be less than 4.");
806 rowHeadersWidth = value;
807 OnRowHeadersWidthChanged(EventArgs.Empty);
812 public DataGridViewRowHeadersWidthSizeMode RowHeadersWidthSizeMode {
813 get { return rowHeadersWidthSizeMode; }
815 if (rowHeadersWidthSizeMode != value) {
816 if (!Enum.IsDefined(typeof(DataGridViewRowHeadersWidthSizeMode), value)) {
817 throw new InvalidEnumArgumentException("Value is not valid DataGridViewRowHeadersWidthSizeMode.");
819 rowHeadersWidthSizeMode = value;
820 OnRowHeadersWidthSizeModeChanged(new DataGridViewAutoSizeModeEventArgs(false));
825 public DataGridViewRowCollection Rows {
829 public DataGridViewCellStyle RowsDefaultCellStyle {
830 get { return rowsDefaultCellStyle; }
832 if (rowsDefaultCellStyle != value) {
833 rowsDefaultCellStyle = value;
834 OnRowsDefaultCellStyleChanged(EventArgs.Empty);
839 public DataGridViewRow RowTemplate {
841 if (rowTemplate == null) {
842 return new DataGridViewRow();
848 rowTemplate.SetDataGridView(this);
852 public ScrollBars ScrollBars {
853 get { return scrollBars; }
855 if (!Enum.IsDefined(typeof(ScrollBars), value)) {
856 throw new InvalidEnumArgumentException("Invalid ScrollBars value.");
858 ////////////////////////////////////////////////////////////
859 /// *** InvalidOperationException ***
860 /// The System.Windows.Forms.DataGridView is unable to
861 /// scroll due to a cell change that cannot be committed
863 ///////////////////////////////////////////////////////////
868 public DataGridViewSelectedCellCollection SelectedCells {
870 DataGridViewSelectedCellCollection selectedCells = new DataGridViewSelectedCellCollection();
871 foreach (DataGridViewRow row in rows) {
872 foreach (DataGridViewCell cell in row.Cells) {
874 selectedCells.InternalAdd(cell);
878 return selectedCells;
882 public DataGridViewSelectedColumnCollection SelectedColumns {
884 DataGridViewSelectedColumnCollection selectedColumns = new DataGridViewSelectedColumnCollection();
885 if (selectionMode == DataGridViewSelectionMode.FullColumnSelect || selectionMode == DataGridViewSelectionMode.ColumnHeaderSelect) {
886 foreach (DataGridViewColumn col in columns) {
888 selectedColumns.InternalAdd(col);
892 return selectedColumns;
896 public DataGridViewSelectedRowCollection SelectedRows {
898 DataGridViewSelectedRowCollection selectedRows = new DataGridViewSelectedRowCollection();
899 if (selectionMode == DataGridViewSelectionMode.FullColumnSelect || selectionMode == DataGridViewSelectionMode.RowHeaderSelect) {
900 foreach (DataGridViewRow row in rows) {
902 selectedRows.InternalAdd(row);
910 public DataGridViewSelectionMode SelectionMode {
911 get { return selectionMode; }
913 if (!Enum.IsDefined(typeof(DataGridViewSelectionMode), value)) {
914 throw new InvalidEnumArgumentException("Value is not valid DataGridViewSelectionMode.");
916 selectionMode = value;
920 public bool ShowCellErrors {
921 get { return showCellErrors; }
922 set { showCellErrors = value; }
925 public bool ShowCellToolTips {
926 get { return showCellToolTips; }
927 set { showCellToolTips = value; }
930 public bool ShowEditingIcon {
931 get { return showEditingIcon; }
932 set { showEditingIcon = value; }
935 public bool ShowRowErrors {
936 get { return showRowErrors; }
937 set { showRowErrors = value; }
940 public DataGridViewColumn SortedColumn {
941 get { return sortedColumn; }
944 public SortOrder SortOrder {
945 get { return sortOrder; }
948 public bool StandardTab {
949 get { return standardTab; }
950 set { standardTab = value; }
953 public override string Text {
955 set { text = value; }
958 public DataGridViewHeaderCell TopLeftHeaderCell {
959 get { return topLeftHeaderCell; }
960 set { topLeftHeaderCell = value; }
963 public Cursor UserSetCursor {
964 get { return userSetCursor; }
967 public int VerticalScrollingOffset {
968 get { return verticalScrollingOffset; }
971 public bool VirtualMode {
972 get { return virtualMode; }
973 set { virtualMode = value; }
976 public event EventHandler AllowUserToAddRowsChanged;
978 public event EventHandler AllowUserToDeleteRowsChanged;
980 public event EventHandler AllowUserToOrderColumnsChanged;
982 public event EventHandler AllowUserToResizeColumnsChanged;
984 public event EventHandler AllowUserToResizeRowsChanged;
986 public event EventHandler AlternatingRowsDefaultCellStyleChanged;
988 public event EventHandler AutoGenerateColumnsChanged;
990 public new event EventHandler AutoSizeChanged;
992 public event DataGridViewAutoSizeColumnModeEventHandler AutoSizeColumnModeChanged;
994 public event DataGridViewAutoSizeColumnsModeEventHandler AutoSizeColumnsModeChanged;
996 public event DataGridViewAutoSizeModeEventHandler AutoSizeRowsModeChanged;
998 public new event EventHandler BackColorChanged;
1000 public event EventHandler BackgroundColorChanged;
1002 public new event EventHandler BackgroundImageChanged;
1004 public new event EventHandler BackgroundImageLayoutChanged;
1006 public event EventHandler BorderStyleChanged;
1008 public event QuestionEventHandler CancelRowEdit;
1010 public event DataGridViewCellCancelEventHandler CellBeginEdit;
1012 public event EventHandler CellBorderStyleChanged;
1014 public event DataGridViewCellEventHandler CellClick;
1016 public event DataGridViewCellEventHandler CellContentClick;
1018 public event DataGridViewCellEventHandler CellContentDoubleClick;
1020 public event DataGridViewCellEventHandler CellContextMenuStripChanged;
1022 public event DataGridViewCellContextMenuStripNeededEventHandler CellContextMenuStripNeeded;
1024 public event DataGridViewCellEventHandler CellDoubleClick;
1026 public event DataGridViewCellEventHandler CellEndEdit;
1028 public event DataGridViewCellEventHandler CellEnter;
1030 public event DataGridViewCellEventHandler CellErrorTextChanged;
1032 public event DataGridViewCellErrorTextNeededEventHandler CellErrorTextNeeded;
1034 public event DataGridViewCellFormattingEventHandler CellFormatting;
1036 public event DataGridViewCellEventHandler CellLeave;
1038 public event DataGridViewCellMouseEventHandler CellMouseClick;
1040 public event DataGridViewCellMouseEventHandler CellMouseDoubleClick;
1042 public event DataGridViewCellMouseEventHandler CellMouseDown;
1044 public event DataGridViewCellEventHandler CellMouseEnter;
1046 public event DataGridViewCellEventHandler CellMouseLeave;
1048 public event DataGridViewCellMouseEventHandler CellMouseMove;
1050 public event DataGridViewCellMouseEventHandler CellMouseUp;
1052 public event DataGridViewCellPaintingEventHandler CellPainting;
1054 public event DataGridViewCellParsingEventHandler CellParsing;
1056 public event DataGridViewCellStateChangedEventHandler CellStateChanged;
1058 public event DataGridViewCellEventHandler CellStyleChanged;
1060 public event DataGridViewCellStyleContentChangedEventHandler CellStyleContentChanged;
1062 public event DataGridViewCellEventHandler CellToolTipTextChanged;
1064 public event DataGridViewCellToolTipTextNeededEventHandler CellToolTipTextNeeded;
1066 public event DataGridViewCellEventHandler CellValidated;
1068 public event DataGridViewCellValidatingEventHandler CellValidating;
1070 public event DataGridViewCellEventHandler CellValueChanged;
1072 public event DataGridViewCellValueEventHandler CellValueNeeded;
1074 public event DataGridViewCellValueEventHandler CellValuePushed;
1076 public event DataGridViewColumnEventHandler ColumnAdded;
1078 public event DataGridViewColumnEventHandler ColumnContextMenuStripChanged;
1080 public event DataGridViewColumnEventHandler ColumnDataPropertyNameChanged;
1082 public event DataGridViewColumnEventHandler ColumnDefaultCellStyleChanged;
1084 public event DataGridViewColumnEventHandler ColumnDisplayIndexChanged;
1086 public event DataGridViewColumnDividerDoubleClickEventHandler ColumnDividerDoubleClick;
1088 public event DataGridViewColumnEventHandler ColumnDividerWidthChanged;
1090 public event DataGridViewColumnEventHandler ColumnHeaderCellChanged;
1092 public event DataGridViewCellMouseEventHandler ColumnHeaderMouseClick;
1094 public event DataGridViewCellMouseEventHandler ColumnHeaderMouseDoubleClick;
1096 public event EventHandler ColumnHeadersBorderStyleChanged;
1098 public event EventHandler ColumnHeadersDefaultCellStyleChanged;
1100 public event EventHandler ColumnHeadersHeightChanged;
1102 public event DataGridViewAutoSizeModeEventHandler ColumnHeadersHeightSizeModeChanged;
1104 public event DataGridViewColumnEventHandler ColumnMinimumWidthChanged;
1106 public event DataGridViewColumnEventHandler ColumnNameChanged;
1108 public event DataGridViewColumnEventHandler ColumnRemoved;
1110 public event DataGridViewColumnEventHandler ColumnSortModeChanged;
1112 public event DataGridViewColumnStateChangedEventHandler ColumnStateChanged;
1114 public event DataGridViewColumnEventHandler ColumnToolTipTextChanged;
1116 public event DataGridViewColumnEventHandler ColumnWidthChanged;
1118 public event EventHandler CurrentCellChanged;
1120 public event EventHandler CurrentCellDirtyStateChanged;
1122 public event DataGridViewBindingCompleteEventHandler DataBindingComplete;
1124 public event DataGridViewDataErrorEventHandler DataError;
1126 public event EventHandler DataMemberChanged;
1128 public event EventHandler DataSourceChanged;
1130 public event EventHandler DefaultCellStyleChanged;
1132 public event DataGridViewRowEventHandler DefaultValuesNeeded;
1134 public event DataGridViewEditingControlShowingEventHandler EditingControlShowing;
1136 public event EventHandler EditModeChanged;
1138 public new event EventHandler FontChanged;
1140 public new event EventHandler ForeColorChanged;
1142 public event EventHandler GridColorChanged;
1144 public event EventHandler MultiSelectChanged;
1146 public event DataGridViewRowEventHandler NewRowNeeded;
1148 public event EventHandler ReadOnlyChanged;
1150 public event DataGridViewRowEventHandler RowContextMenuStripChanged;
1152 public event DataGridViewRowContextMenuStripNeededEventHandler RowContextMenuStripNeeded;
1154 public event DataGridViewRowEventHandler RowDefaultCellStyleChanged;
1156 public event QuestionEventHandler RowDirtyStateNeeded;
1158 public event DataGridViewRowDividerDoubleClickEventHandler RowDividerDoubleClick;
1160 public event DataGridViewRowEventHandler RowDividerHeightChanged;
1162 public event DataGridViewCellEventHandler RowEnter;
1164 public event DataGridViewRowEventHandler RowErrorTextChanged;
1166 public event DataGridViewRowErrorTextNeededEventHandler RowErrorTextNeeded;
1168 public event DataGridViewRowEventHandler RowHeaderCellChanged;
1170 public event DataGridViewCellMouseEventHandler RowHeaderMouseClick;
1172 public event DataGridViewCellMouseEventHandler RowHeaderMouseDoubleClick;
1174 public event EventHandler RowHeadersBorderStyleChanged;
1176 public event EventHandler RowHeadersDefaultCellStyleChanged;
1178 public event EventHandler RowHeadersWidthChanged;
1180 public event DataGridViewAutoSizeModeEventHandler RowHeadersWidthSizeModeChanged;
1182 public event DataGridViewRowEventHandler RowHeightChanged;
1184 public event DataGridViewRowHeightInfoNeededEventHandler RowHeightInfoNeeded;
1186 public event DataGridViewRowHeightInfoPushedEventHandler RowHeightInfoPushed;
1188 public event DataGridViewCellEventHandler RowLeave;
1190 public event DataGridViewRowEventHandler RowMinimumHeightChanged;
1192 public event DataGridViewRowPostPaintEventHandler RowPostPaint;
1194 public event DataGridViewRowPrePaintEventHandler RowPrePaint;
1196 public event DataGridViewRowsAddedEventHandler RowsAdded;
1198 public event EventHandler RowsDefaultCellStyleChanged;
1200 public event DataGridViewRowsRemovedEventHandler RowsRemoved;
1202 public event DataGridViewRowStateChangedEventHandler RowStateChanged;
1204 public event DataGridViewRowEventHandler RowUnshared;
1206 public event DataGridViewCellEventHandler RowValidated;
1208 public event DataGridViewCellCancelEventHandler RowValidating;
1210 public event ScrollEventHandler Scroll;
1212 public event EventHandler SelectionChanged;
1214 public event DataGridViewSortCompareEventHandler SortCompare;
1216 public event EventHandler Sorted;
1218 public event DataGridViewRowEventHandler UserAddedRow;
1220 public event DataGridViewRowEventHandler UserDeletedRow;
1222 public event DataGridViewRowCancelEventHandler UserDeletingRow;
1224 public new event EventHandler StyleChanged;
1226 public new event EventHandler TextChanged;
1228 public virtual DataGridViewAdvancedBorderStyle AdjustColumnHeaderBorderStyle (DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStyleInput, DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceholder, bool isFirstDisplayedColumn, bool isLastVisibleColumn) {
1229 return (DataGridViewAdvancedBorderStyle) dataGridViewAdvancedBorderStyleInput.Clone();
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) {
1238 if (!cell.Selected) {
1246 public void AutoResizeColumn (int columnIndex) {
1247 throw new NotImplementedException();
1250 public void AutoResizeColumn (int columnIndex, DataGridViewAutoSizeColumnMode autoSizeColumnMode) {
1251 throw new NotImplementedException();
1254 public void AutoResizeColumnHeadersHeight () {
1255 throw new NotImplementedException();
1258 public void AutoResizeColumnHeadersHeight (int columnIndex) {
1259 throw new NotImplementedException();
1262 public void AutoResizeColumns () {
1263 throw new NotImplementedException();
1266 public void AutoResizeColumns (DataGridViewAutoSizeColumnsMode autoSizeColumnsMode) {
1267 throw new NotImplementedException();
1270 public void AutoResizeRow (int rowIndex) {
1271 throw new NotImplementedException();
1274 public void AutoResizeRow (int rowIndex, DataGridViewAutoSizeRowMode autoSizeRowMode) {
1275 throw new NotImplementedException();
1278 public void AutoResizeRowHeadersWidth (DataGridViewRowHeadersWidthSizeMode rowHeadersWidthSizeMode) {
1279 throw new NotImplementedException();
1282 public void AutoResizeRowHeadersWidth (int rowIndex, DataGridViewRowHeadersWidthSizeMode rowHeadersWidthSizeMode) {
1283 throw new NotImplementedException();
1286 public void AutoResizeRows () {
1287 throw new NotImplementedException();
1290 public void AutoResizeRows (DataGridViewAutoSizeRowsMode autoSizeRowsMode) {
1291 if (!Enum.IsDefined(typeof(DataGridViewAutoSizeRowsMode), autoSizeRowsMode)) {
1292 throw new InvalidEnumArgumentException("Parameter AutoSizeRowsMode is not valid DataGridViewRowsMode.");
1294 if ((autoSizeRowsMode == DataGridViewAutoSizeRowsMode.AllHeaders || autoSizeRowsMode == DataGridViewAutoSizeRowsMode.DisplayedHeaders) && rowHeadersVisible == false) {
1295 throw new InvalidOperationException("Parameter AutoSizeRowsMode cant be AllHeaders or DisplayedHeaders in this DataGridView.");
1297 if (autoSizeRowsMode == DataGridViewAutoSizeRowsMode.None) {
1298 throw new ArgumentException("Parameter AutoSieRowsMode cant be None.");
1302 public virtual bool BeginEdit (bool selectAll) {
1303 throw new NotImplementedException();
1306 public bool CancelEdit () {
1307 throw new NotImplementedException();
1310 public void ClearSelection () {
1311 foreach (DataGridViewCell cell in SelectedCells) {
1312 cell.Selected = false;
1316 public bool CommitEdit (DataGridViewDataErrorContexts context) {
1317 throw new NotImplementedException();
1320 public int DisplayedColumnCount (bool includePartialColumns) {
1321 /////////////////////// PartialColumns?
1323 foreach (DataGridViewColumn col in columns) {
1331 public int DisplayedRowCount (bool includePartialRow) {
1332 /////////////////////// PartialRows?
1334 foreach (DataGridViewRow row in rows) {
1342 public bool EndEdit () {
1343 throw new NotImplementedException();
1346 public bool EndEdit (DataGridViewDataErrorContexts context) {
1347 throw new NotImplementedException();
1350 public int GetCellCount (DataGridViewElementStates includeFilter) {
1352 foreach (DataGridViewRow row in rows) {
1353 foreach (DataGridViewCell cell in row.Cells) {
1354 if ((cell.State & includeFilter) != 0) {
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.");
1366 throw new NotImplementedException();
1369 public virtual DataObject GetClipboardContent () {
1370 throw new NotImplementedException();
1373 public Rectangle GetColumnDisplayRectangle (int columnIndex, bool cutOverflow) {
1374 throw new NotImplementedException();
1377 public Rectangle GetRowDisplayRectangle (int rowIndex, bool cutOverflow) {
1378 throw new NotImplementedException();
1381 public HitTestInfo HitTest (int x, int y) {
1382 ///////////////////////////////////////////////////////
1383 x += horizontalScrollingOffset;
1384 y += verticalScrollingOffset;
1386 int totalHeight = (columnHeadersVisible)? 1 + columnHeadersHeight : 1;
1387 if (columnHeadersVisible && y <= totalHeight) {
1391 foreach (DataGridViewRow row in rows.RowIndexSortedArrayList) {
1392 totalHeight += row.Height;
1393 if (y <= totalHeight) {
1394 rowIndex = row.Index;
1397 totalHeight++; // sumar el ancho de las lineas...
1401 int totalWidth = (rowHeadersVisible)? 1 + rowHeadersWidth : 1;
1402 if (rowHeadersVisible && x <= totalWidth) {
1406 foreach (DataGridViewColumn col in columns.ColumnDisplayIndexSortedArrayList) {
1407 totalWidth += col.Width;
1408 if (x <= totalWidth) {
1409 colIndex = col.Index;
1415 HitTestInfo result = new HitTestInfo(colIndex, x, rowIndex, y, (colIndex >= 0 && rowIndex >= 0)? DataGridViewHitTestType.Cell : DataGridViewHitTestType.None);
1419 public void InvalidateCell (DataGridViewCell dataGridViewCell) {
1420 if (dataGridViewCell == null) {
1421 throw new ArgumentNullException("Cell is null");
1423 if (dataGridViewCell.DataGridView != this) {
1424 throw new ArgumentException("The specified cell does not belong to this DataGridView.");
1426 throw new NotImplementedException();
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.");
1433 if (rowIndex < 0 || rowIndex >= rows.Count) {
1434 throw new ArgumentOutOfRangeException("Row index is out of range.");
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 !!!
1446 public void InvalidateColumn (int columnIndex) {
1447 if (columnIndex < 0 || columnIndex >= columns.Count) {
1448 throw new ArgumentOutOfRangeException("Column index is out of range.");
1450 throw new NotImplementedException();
1453 public void InvalidateRow (int rowIndex) {
1454 if (rowIndex < 0 || rowIndex >= rows.Count) {
1455 throw new ArgumentOutOfRangeException("Row index is out of range.");
1457 throw new NotImplementedException();
1460 public virtual void NotifyCurrentCellDirty (bool dirty) {
1461 throw new NotImplementedException();
1464 public bool RefreshEdit () {
1465 throw new NotImplementedException();
1468 public override void ResetText () {
1469 throw new NotImplementedException();
1472 public void SelectAll () {
1473 switch (selectionMode) {
1474 case DataGridViewSelectionMode.FullRowSelect:
1475 foreach (DataGridViewRow row in rows) {
1476 (row as DataGridViewBand).Selected = true;
1479 case DataGridViewSelectionMode.FullColumnSelect:
1480 foreach (DataGridViewColumn col in columns) {
1481 (col as DataGridViewBand).Selected = true;
1485 foreach (DataGridViewRow row in rows) {
1486 foreach (DataGridViewCell cell in row.Cells) {
1487 cell.Selected = true;
1494 public virtual void Sort (IComparer comparer) {
1495 throw new NotImplementedException();
1498 public virtual void Sort (DataGridViewColumn dataGridViewColumn, ListSortDirection direction) {
1499 throw new NotImplementedException();
1502 public void UpdateCellErrorText (int columnIndex, int rowIndex) {
1503 throw new NotImplementedException();
1506 public void UpdateRowErrorText (int rowIndex) {
1507 throw new NotImplementedException();
1510 public void UpdateRowErrorText (int rowIndexStart, int rowIndexEnd) {
1511 throw new NotImplementedException();
1514 public void UpdateRowHeightInfo (int rowIndex, bool updateToEnd) {
1515 throw new NotImplementedException();
1518 protected override Size DefaultSize {
1519 get { return defaultSize; }
1522 protected ScrollBar HorizontalScrollBar {
1523 get { return horizontalScrollBar; }
1526 protected ScrollBar VerticalScrollBar {
1527 get { return verticalScrollBar; }
1530 protected void AutoResizeColumn (int columnIndex, DataGridViewAutoSizeColumnMode autoSizeColumnMode, bool fixedHeight) {
1531 throw new NotImplementedException();
1534 protected void AutoResizeColumnHeadersHeight (bool fixedRowHeadersWidth, bool fixedColumnsWidth) {
1535 throw new NotImplementedException();
1538 protected void AutoResizeColumnHeadersHeight (int columnIndex, bool fixedRowHeadersWidth, bool fixedColumnWidth) {
1539 throw new NotImplementedException();
1542 protected void AutoResizeColumns (DataGridViewAutoSizeColumnsMode autoSizeColumnsMode, bool fixedHeight) {
1543 throw new NotImplementedException();
1546 protected void AutoResizeRow (int rowIndex, DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth) {
1547 throw new NotImplementedException();
1550 protected void AutoResizeRowHeadersWidth (DataGridViewRowHeadersWidthSizeMode rowHeadersWidthSizeMode, bool fixedColumnHeadersHeight, bool fixedRowsHeight) {
1551 throw new NotImplementedException();
1554 protected void AutoResizeRowHeadersWidth (int rowIndex, DataGridViewRowHeadersWidthSizeMode rowHeadersWidthSizeMode, bool fixedColumnHeadersHeight, bool fixedRowHeight) {
1555 throw new NotImplementedException();
1558 protected void AutoResizeRows (DataGridViewAutoSizeRowsMode autoSizeRowsMode, bool fixedWidth) {
1559 throw new NotImplementedException();
1562 protected void AutoResizeRows (int rowIndexStart, int rowsCount, DataGridViewAutoSizeRowMode autoSizeRowMode, bool fixedWidth) {
1563 throw new NotImplementedException();
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.");
1570 if (selectionMode == DataGridViewSelectionMode.FullRowSelect) {
1571 if (columnIndexException < -1) {
1572 throw new ArgumentOutOfRangeException("ColumnIndexException is less than -1.");
1576 if (columnIndexException < 0) {
1577 throw new ArgumentOutOfRangeException("ColumnIndexException is less than 0.");
1580 if (rowIndexException >= rows.Count) {
1581 throw new ArgumentOutOfRangeException("RowIndexException is greater than the highest row index.");
1583 if (selectionMode == DataGridViewSelectionMode.FullColumnSelect) {
1584 if (rowIndexException < -1) {
1585 throw new ArgumentOutOfRangeException("RowIndexException is less than -1.");
1589 if (rowIndexException < 0) {
1590 throw new ArgumentOutOfRangeException("RowIndexException is less than 0.");
1593 switch (selectionMode) {
1594 case DataGridViewSelectionMode.FullRowSelect:
1595 foreach (DataGridViewRow row in rows) {
1596 if (selectExceptionElement && row.Index == rowIndexException) {
1599 row.Selected = false;
1602 case DataGridViewSelectionMode.FullColumnSelect:
1603 foreach (DataGridViewColumn col in columns) {
1604 if (selectExceptionElement && col.Index == columnIndexException) {
1607 col.Selected = false;
1611 foreach (DataGridViewCell cell in SelectedCells) {
1612 if (selectExceptionElement && cell.RowIndex == rowIndexException && cell.ColumnIndex == columnIndexException) {
1615 cell.Selected = false;
1621 protected override AccessibleObject CreateAccessibilityInstance () {
1622 return new DataGridViewAccessibleObject(this);
1625 protected virtual DataGridViewColumnCollection CreateColumnsInstance () {
1626 return new DataGridViewColumnCollection(this);
1629 protected override Control.ControlCollection CreateControlsInstance () {
1630 return base.CreateControlsInstance(); //new Control.ControlCollection(this);
1633 protected virtual DataGridViewRowCollection CreateRowsInstance () {
1634 return new DataGridViewRowCollection(this);
1637 protected override void Dispose (bool disposing) {
1640 //protected override AccessibleObject GetAccessibilityObjectById (int objectId) {
1641 protected AccessibleObject GetAccessibilityObjectById (int objectId) {
1642 throw new NotImplementedException();
1645 protected override bool IsInputChar (char charCode) {
1646 return base.IsInputChar(charCode);
1647 //throw new NotImplementedException();
1650 protected override bool IsInputKey (Keys keyData) {
1651 return base.IsInputKey(keyData);
1652 //throw new NotImplementedException();
1655 protected virtual void OnAllowUserToAddRowsChanged (EventArgs e) {
1656 if (AllowUserToAddRowsChanged != null) {
1657 AllowUserToAddRowsChanged(this, e);
1661 protected virtual void OnAllowUserToDeleteRowsChanged (EventArgs e) {
1662 if (AllowUserToDeleteRowsChanged != null) {
1663 AllowUserToDeleteRowsChanged(this, e);
1667 protected virtual void OnAllowUserToOrderColumnsChanged (EventArgs e) {
1668 if (AllowUserToOrderColumnsChanged != null) {
1669 AllowUserToOrderColumnsChanged(this, e);
1673 protected virtual void OnAllowUserToResizeColumnsChanged (EventArgs e) {
1674 if (AllowUserToResizeColumnsChanged != null) {
1675 AllowUserToResizeColumnsChanged(this, e);
1679 protected virtual void OnAllowUserToResizeRowsChanged (EventArgs e) {
1680 if (AllowUserToResizeRowsChanged != null) {
1681 AllowUserToResizeRowsChanged(this, e);
1685 protected virtual void OnAlternatingRowsDefaultCellStyleChanged (EventArgs e) {
1686 if (AlternatingRowsDefaultCellStyleChanged != null) {
1687 AlternatingRowsDefaultCellStyleChanged(this, e);
1691 protected virtual void OnAutoGenerateColumnsChanged (EventArgs e) {
1692 if (AutoGenerateColumnsChanged != null) {
1693 AutoGenerateColumnsChanged(this, e);
1697 protected virtual void OnAutoSizeColumnModeChanged (DataGridViewAutoSizeColumnModeEventArgs e) {
1698 if (AutoSizeColumnModeChanged != null) {
1699 AutoSizeColumnModeChanged(this, e);
1703 protected virtual void OnAutoSizeColumnsModeChanged (DataGridViewAutoSizeColumnsModeEventArgs e) {
1704 if (AutoSizeColumnsModeChanged != null) {
1705 AutoSizeColumnsModeChanged(this, e);
1709 protected virtual void OnAutoSizeRowsModeChanged (DataGridViewAutoSizeModeEventArgs e) {
1710 if (AutoSizeRowsModeChanged != null) {
1711 AutoSizeRowsModeChanged(this, e);
1715 protected virtual void OnBackgroundColorChanged (EventArgs e) {
1716 if (BackgroundColorChanged != null) {
1717 BackgroundColorChanged(this, e);
1721 protected override void OnBindingContextChanged (EventArgs e) {
1722 base.OnBindingContextChanged(e);
1725 protected virtual void OnBorderStyleChanged (EventArgs e) {
1726 if (BorderStyleChanged != null) {
1727 BorderStyleChanged(this, e);
1731 protected virtual void OnCancelRowEdit (QuestionEventArgs e) {
1732 if (CancelRowEdit != null) {
1733 CancelRowEdit(this, e);
1737 protected virtual void OnCellBeginEdit (DataGridViewCellCancelEventArgs e) {
1738 if (CellBeginEdit != null) {
1739 CellBeginEdit(this, e);
1743 protected virtual void OnCellBorderStyleChanged (EventArgs e) {
1744 if (CellBorderStyleChanged != null) {
1745 CellBorderStyleChanged(this, e);
1749 protected virtual void OnCellClick (DataGridViewCellEventArgs e) {
1750 if (CellClick != null) {
1755 protected virtual void OnCellContentClick (DataGridViewCellEventArgs e) {
1756 if (CellContentClick != null) {
1757 CellContentClick(this, e);
1761 protected virtual void OnCellContentDoubleClick (DataGridViewCellEventArgs e) {
1762 if (CellContentDoubleClick != null) {
1763 CellContentDoubleClick(this, e);
1767 protected virtual void OnCellContextMenuStripChanged (DataGridViewCellEventArgs e) {
1768 if (CellContextMenuStripChanged != null) {
1769 CellContextMenuStripChanged(this, e);
1773 protected virtual void OnCellContextMenuStripNeeded (DataGridViewCellContextMenuStripNeededEventArgs e) {
1774 if (CellContextMenuStripNeeded != null) {
1775 CellContextMenuStripNeeded(this, e);
1779 protected virtual void OnCellDoubleClick (DataGridViewCellEventArgs e) {
1780 if (CellDoubleClick != null) {
1781 CellDoubleClick(this, e);
1785 protected virtual void OnCellEndEdit (DataGridViewCellEventArgs e) {
1786 if (CellEndEdit != null) {
1787 CellEndEdit(this, e);
1791 protected virtual void OnCellEnter (DataGridViewCellEventArgs e) {
1792 if (CellEnter != null) {
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);
1804 protected virtual void OnCellErrorTextNeeded (DataGridViewCellErrorTextNeededEventArgs e) {
1805 if (CellErrorTextNeeded != null) {
1806 CellErrorTextNeeded(this, e);
1810 protected virtual void OnCellFormatting (DataGridViewCellFormattingEventArgs e) {
1811 if (CellFormatting != null) {
1812 CellFormatting(this, e);
1816 protected virtual void OnCellLeave (DataGridViewCellEventArgs e) {
1817 if (CellLeave != null) {
1822 protected virtual void OnCellMouseClick (DataGridViewCellMouseEventArgs e) {
1823 if (CellMouseClick != null) {
1824 CellMouseClick(this, e);
1828 protected virtual void OnCellMouseDoubleClick (DataGridViewCellMouseEventArgs e) {
1829 if (CellMouseDoubleClick != null) {
1830 CellMouseDoubleClick(this, e);
1834 protected virtual void OnCellMouseDown (DataGridViewCellMouseEventArgs e) {
1835 if (CellMouseDown != null) {
1836 CellMouseDown(this, e);
1840 protected virtual void OnCellMouseEnter (DataGridViewCellEventArgs e) {
1841 if (CellMouseEnter != null) {
1842 CellMouseEnter(this, e);
1846 protected virtual void OnCellMouseLeave (DataGridViewCellEventArgs e) {
1847 if (CellMouseLeave != null) {
1848 CellMouseLeave(this, e);
1852 protected virtual void OnCellMouseMove (DataGridViewCellMouseEventArgs e) {
1853 if (CellMouseMove != null) {
1854 CellMouseMove(this, e);
1858 protected virtual void OnCellMouseUp (DataGridViewCellMouseEventArgs e) {
1859 if (CellMouseUp != null) {
1860 CellMouseUp(this, e);
1864 protected virtual void OnCellPainting (DataGridViewCellPaintingEventArgs e) {
1865 if (CellPainting != null) {
1866 CellPainting(this, e);
1870 protected internal virtual void OnCellParsing (DataGridViewCellParsingEventArgs e) {
1871 if (CellParsing != null) {
1872 CellParsing(this, e);
1876 protected virtual void OnCellStateChanged (DataGridViewCellStateChangedEventArgs e) {
1877 if (CellStateChanged != null) {
1878 CellStateChanged(this, e);
1882 protected virtual void OnCellStyleChanged (DataGridViewCellEventArgs e) {
1883 if (CellStyleChanged != null) {
1884 CellStyleChanged(this, e);
1888 protected virtual void OnCellStyleContentChanged (DataGridViewCellStyleContentChangedEventArgs e) {
1889 if (CellStyleContentChanged != null) {
1890 CellStyleContentChanged(this, e);
1894 protected virtual void OnCellToolTipTextChanged (DataGridViewCellEventArgs e) {
1895 if (CellToolTipTextChanged != null) {
1896 CellToolTipTextChanged(this, e);
1900 protected virtual void OnCellToolTipTextNeeded (DataGridViewCellToolTipTextNeededEventArgs e) {
1901 if (CellToolTipTextNeeded != null) {
1902 CellToolTipTextNeeded(this, e);
1906 protected virtual void OnCellValidated (DataGridViewCellEventArgs e) {
1907 if (CellValidated != null) {
1908 CellValidated(this, e);
1912 protected virtual void OnCellValidating (DataGridViewCellValidatingEventArgs e) {
1913 if (CellValidating != null) {
1914 CellValidating(this, e);
1918 protected virtual void OnCellValueChanged (DataGridViewCellEventArgs e) {
1919 if (CellValueChanged != null) {
1920 CellValueChanged(this, e);
1924 protected virtual void OnCellValueNeeded (DataGridViewCellValueEventArgs e) {
1925 if (CellValueNeeded != null) {
1926 CellValueNeeded(this, e);
1930 protected virtual void OnCellValuePushed (DataGridViewCellValueEventArgs e) {
1931 if (CellValuePushed != null) {
1932 CellValuePushed(this, e);
1936 protected virtual void OnColumnAdded (DataGridViewColumnEventArgs e) {
1937 if (ColumnAdded != null) {
1938 ColumnAdded(this, e);
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);
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);
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);
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);
1970 protected virtual void OnColumnDividerDoubleClick (DataGridViewColumnDividerDoubleClickEventArgs e) {
1971 if (ColumnDividerDoubleClick != null) {
1972 ColumnDividerDoubleClick(this, e);
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);
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);
1990 protected virtual void OnColumnHeaderMouseClick (DataGridViewCellMouseEventArgs e) {
1991 if (ColumnHeaderMouseClick != null) {
1992 ColumnHeaderMouseClick(this, e);
1996 protected virtual void OnColumnHeaderMouseDoubleClick (DataGridViewCellMouseEventArgs e) {
1997 if (ColumnHeaderMouseDoubleClick != null) {
1998 ColumnHeaderMouseDoubleClick(this, e);
2002 protected virtual void OnColumnHeadersBorderStyleChanged (EventArgs e) {
2003 if (ColumnHeadersBorderStyleChanged != null) {
2004 ColumnHeadersBorderStyleChanged(this, e);
2008 protected virtual void OnColumnHeadersDefaultCellStyleChanged (EventArgs e) {
2009 if (ColumnHeadersDefaultCellStyleChanged != null) {
2010 ColumnHeadersDefaultCellStyleChanged(this, e);
2014 protected virtual void OnColumnHeadersHeightChanged (EventArgs e) {
2015 if (ColumnHeadersHeightChanged != null) {
2016 ColumnHeadersHeightChanged(this, e);
2020 protected virtual void OnColumnHeadersHeightSizeModeChanged (DataGridViewAutoSizeModeEventArgs e) {
2021 if (ColumnHeadersHeightSizeModeChanged != null) {
2022 ColumnHeadersHeightSizeModeChanged(this, e);
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);
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);
2040 protected virtual void OnColumnRemoved (DataGridViewColumnEventArgs e) {
2041 if (ColumnRemoved != null) {
2042 ColumnRemoved(this, e);
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);
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);
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);
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);
2074 protected virtual void OnCurrentCellChanged (EventArgs e) {
2075 if (CurrentCellChanged != null) {
2076 CurrentCellChanged(this, e);
2080 protected virtual void OnCurrentCellDirtyStateChanged (EventArgs e) {
2081 if (CurrentCellDirtyStateChanged != null) {
2082 CurrentCellDirtyStateChanged(this, e);
2086 protected virtual void OnDataBindingComplete (DataGridViewBindingCompleteEventArgs e) {
2087 if (DataBindingComplete != null) {
2088 DataBindingComplete(this, e);
2092 protected virtual void OnDataError (bool displayErrorDialogIfNoHandler, DataGridViewDataErrorEventArgs e) {
2093 if (DataError != null) {
2097 if (displayErrorDialogIfNoHandler) {
2098 /////////////////////////////////// ERROR DIALOG //////////////////////////////////7
2102 protected virtual void OnDataMemberChanged (EventArgs e) {
2103 if (DataMemberChanged != null) {
2104 DataMemberChanged(this, e);
2108 protected virtual void OnDataSourceChanged (EventArgs e) {
2109 if (DataSourceChanged != null) {
2110 DataSourceChanged(this, e);
2114 protected virtual void OnDefaultCellStyleChanged (EventArgs e) {
2115 if (DefaultCellStyleChanged != null) {
2116 DefaultCellStyleChanged(this, e);
2120 protected virtual void OnDefaultValuesNeeded (DataGridViewRowEventArgs e) {
2121 if (DefaultValuesNeeded != null) {
2122 DefaultValuesNeeded(this, e);
2126 protected override void OnDoubleClick (EventArgs e) {
2127 base.OnDoubleClick(e);
2130 protected virtual void OnEditingControlShowing (DataGridViewEditingControlShowingEventArgs e) {
2131 if (EditingControlShowing != null) {
2132 EditingControlShowing(this, e);
2136 protected virtual void OnEditModeChanged (EventArgs e) {
2137 if (EditModeChanged != null) {
2138 EditModeChanged(this, e);
2142 protected override void OnEnabledChanged (EventArgs e) {
2143 base.OnEnabledChanged(e);
2146 protected override void OnEnter (EventArgs e ) {
2150 protected override void OnFontChanged (EventArgs e) {
2151 base.OnFontChanged(e);
2152 if (FontChanged != null) {
2153 FontChanged(this, e);
2157 protected override void OnForeColorChanged (EventArgs e) {
2158 base.OnForeColorChanged(e);
2159 if (ForeColorChanged != null) {
2160 ForeColorChanged(this, e);
2164 protected virtual void OnGridColorChanged (EventArgs e) {
2165 if (GridColorChanged != null) {
2166 GridColorChanged(this, e);
2170 protected override void OnHandleCreated (EventArgs e) {
2171 base.OnHandleCreated(e);
2174 protected override void OnKeyDown (KeyEventArgs e) {
2178 protected override void OnKeyPress (KeyPressEventArgs e) {
2182 protected override void OnKeyUp (KeyEventArgs e) {
2186 protected override void OnLayout (LayoutEventArgs e) {
2190 protected override void OnLeave (EventArgs e) {
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);
2200 //protected override void OnMouseDoubleClick (MouseEventArgs e) {
2201 protected void OnMouseDoubleClick (MouseEventArgs e) {
2202 //base.OnMouseDoubleClick(e);
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) {
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;
2221 case DataGridViewSelectionMode.FullColumnSelect:
2225 cell.Selected = true;
2228 if (cell == currentCell) {
2229 currentCell.SetIsInEditMode(true);
2230 OnCellBeginEdit(new DataGridViewCellCancelEventArgs(currentCell.ColumnIndex, currentCell.RowIndex));
2234 if (currentCell != null) {
2235 if (currentCell.IsInEditMode) {
2236 currentCell.SetIsInEditMode(false);
2237 currentCell.DetachEditingControl();
2238 OnCellEndEdit(new DataGridViewCellEventArgs(currentCell.ColumnIndex, currentCell.RowIndex));
2240 OnCellLeave(new DataGridViewCellEventArgs(currentCell.ColumnIndex, currentCell.RowIndex));
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));
2253 protected override void OnMouseEnter (EventArgs e) {
2254 base.OnMouseEnter(e);
2257 protected override void OnMouseLeave (EventArgs e) {
2258 base.OnMouseLeave(e);
2261 protected override void OnMouseMove (MouseEventArgs e) {
2262 base.OnMouseMove(e);
2265 protected override void OnMouseUp (MouseEventArgs e) {
2269 protected override void OnMouseWheel (MouseEventArgs e) {
2270 base.OnMouseWheel(e);
2273 protected virtual void OnMultiSelectChanged (EventArgs e) {
2274 if (MultiSelectChanged != null) {
2275 MultiSelectChanged(this, e);
2279 protected virtual void OnNewRowNeeded (DataGridViewRowEventArgs e) {
2280 if (NewRowNeeded != null) {
2281 NewRowNeeded(this, e);
2285 protected override void OnPaint (PaintEventArgs 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);
2293 ArrayList sortedColumns = columns.ColumnDisplayIndexSortedArrayList;
2294 bounds.Y = -verticalScrollingOffset;
2295 bounds.X = -horizontalScrollingOffset;
2297 foreach (DataGridViewColumn col in sortedColumns) {
2298 gridWidth += col.Width;
2300 if (columnHeadersVisible) {
2301 Rectangle headerBounds = bounds;
2302 if (rowHeadersVisible) {
2303 headerBounds.X += rowHeadersWidth;
2305 headerBounds.Height = columnHeadersHeight;
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;
2317 bounds.Y += columnHeadersHeight;
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;
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));
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);
2356 bounds.X += bounds.Width;
2360 bounds.Y += bounds.Height;
2361 bounds.X = -horizontalScrollingOffset;
2364 if (rowHeadersVisible) {
2365 gridWidth += rowHeadersWidth;
2367 if (columnHeadersVisible) {
2368 gridHeight += columnHeadersHeight;
2370 horizontalScrollBar.Visible = false;
2371 verticalScrollBar.Visible = false;
2373 if (gridWidth > Size.Width || gridHeight > Size.Height) {
2374 Size = new Size(gridWidth, gridHeight);
2378 if (gridWidth > Size.Width) {
2379 horizontalScrollBar.Visible = true;
2381 if (gridHeight > Size.Height) {
2382 verticalScrollBar.Visible = true;
2384 if (horizontalScrollBar.Visible && (gridHeight + horizontalScrollBar.Height) > Size.Height) {
2385 verticalScrollBar.Visible = true;
2387 if (verticalScrollBar.Visible && (gridWidth + horizontalScrollBar.Width) > Size.Width) {
2388 horizontalScrollBar.Visible = true;
2390 if (horizontalScrollBar.Visible) {
2391 horizontalScrollBar.Minimum = 0;
2392 if (verticalScrollBar.Visible) {
2393 horizontalScrollBar.Maximum = gridWidth - ClientRectangle.Width + verticalScrollBar.Width;
2396 horizontalScrollBar.Maximum = gridWidth - ClientRectangle.Width;
2398 horizontalScrollBar.LargeChange = horizontalScrollBar.Maximum / 10;
2399 horizontalScrollBar.SmallChange = horizontalScrollBar.Maximum / 20;
2401 if (verticalScrollBar.Visible) {
2402 verticalScrollBar.Minimum = 0;
2403 if (horizontalScrollBar.Visible) {
2404 verticalScrollBar.Maximum = gridHeight - ClientRectangle.Height + horizontalScrollBar.Height;
2407 verticalScrollBar.Maximum = gridHeight - ClientRectangle.Height;
2409 verticalScrollBar.LargeChange = verticalScrollBar.Maximum / 10;
2410 verticalScrollBar.SmallChange = verticalScrollBar.Maximum / 20;
2413 if (horizontalScrollBar.Visible && !this.Controls.Contains(horizontalScrollBar)) {
2414 this.Controls.Add(horizontalScrollBar);
2416 else if (!horizontalScrollBar.Visible && this.Controls.Contains(horizontalScrollBar)) {
2417 this.Controls.Remove(horizontalScrollBar);
2419 if (verticalScrollBar.Visible && !this.Controls.Contains(verticalScrollBar)) {
2420 this.Controls.Add(verticalScrollBar);
2422 else if (!verticalScrollBar.Visible && this.Controls.Contains(verticalScrollBar)) {
2423 this.Controls.Remove(verticalScrollBar);
2427 protected virtual void OnReadOnlyChanged (EventArgs e) {
2428 if (ReadOnlyChanged != null) {
2429 ReadOnlyChanged(this, e);
2433 protected override void OnResize (EventArgs e) {
2435 horizontalScrollingOffset = ((gridWidth - Size.Width) > 0)? (gridWidth - Size.Width) : 0;
2436 verticalScrollingOffset = ((gridHeight - Size.Height) > 0)? (gridHeight - Size.Height) : 0;
2440 protected override void OnRightToLeftChanged (EventArgs e) {
2441 base.OnRightToLeftChanged(e);
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);
2451 protected virtual void OnRowContextMenuStripNeeded (DataGridViewRowContextMenuStripNeededEventArgs e) {
2452 if (RowContextMenuStripNeeded != null) {
2453 RowContextMenuStripNeeded(this, e);
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);
2464 protected virtual void OnRowDirtyStateNeeded (QuestionEventArgs e) {
2465 if (RowDirtyStateNeeded != null) {
2466 RowDirtyStateNeeded(this, e);
2470 protected virtual void OnRowDividerDoubleClick (DataGridViewRowDividerDoubleClickEventArgs e) {
2471 if (RowDividerDoubleClick != null) {
2472 RowDividerDoubleClick(this, e);
2476 protected virtual void OnRowDividerHeightChanged (DataGridViewRowEventArgs e) {
2477 if (RowDividerHeightChanged != null) {
2478 RowDividerHeightChanged(this, e);
2482 protected virtual void OnRowEnter (DataGridViewCellEventArgs e) {
2483 if (RowEnter != null) {
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);
2495 protected virtual void OnRowErrorTextNeeded (DataGridViewRowErrorTextNeededEventArgs e) {
2496 if (RowErrorTextNeeded != null) {
2497 RowErrorTextNeeded(this, e);
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);
2508 protected virtual void OnRowHeaderMouseClick (DataGridViewCellMouseEventArgs e) {
2509 if (RowHeaderMouseClick != null) {
2510 RowHeaderMouseClick(this, e);
2514 protected virtual void OnRowHeaderMouseDoubleClick (DataGridViewCellMouseEventArgs e) {
2515 if (RowHeaderMouseDoubleClick != null) {
2516 RowHeaderMouseDoubleClick(this, e);
2520 protected virtual void OnRowHeadersBorderStyleChanged (EventArgs e) {
2521 if (RowHeadersBorderStyleChanged != null) {
2522 RowHeadersBorderStyleChanged(this, e);
2526 protected virtual void OnRowHeadersDefaultCellStyleChanged (EventArgs e) {
2527 if (RowHeadersDefaultCellStyleChanged != null) {
2528 RowHeadersDefaultCellStyleChanged(this, e);
2532 protected virtual void OnRowHeadersWidthChanged (EventArgs e) {
2533 if (RowHeadersWidthChanged != null) {
2534 RowHeadersWidthChanged(this, e);
2538 protected virtual void OnRowHeadersWidthSizeModeChanged (DataGridViewAutoSizeModeEventArgs e) {
2539 if (RowHeadersWidthSizeModeChanged != null) {
2540 RowHeadersWidthSizeModeChanged(this, e);
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);
2551 protected virtual void OnRowHeightInfoNeeded (DataGridViewRowHeightInfoNeededEventArgs e) {
2552 if (RowHeightInfoNeeded != null) {
2553 RowHeightInfoNeeded(this, e);
2557 protected virtual void OnRowHeightInfoPushed (DataGridViewRowHeightInfoPushedEventArgs e) {
2558 if (RowHeightInfoPushed != null) {
2559 RowHeightInfoPushed(this, e);
2563 protected virtual void OnRowLeave (DataGridViewCellEventArgs e) {
2564 if (RowLeave != null) {
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);
2576 protected internal virtual void OnRowPostPaint (DataGridViewRowPostPaintEventArgs e) {
2577 if (RowPostPaint != null) {
2578 RowPostPaint(this, e);
2582 protected internal virtual void OnRowPrePaint (DataGridViewRowPrePaintEventArgs e) {
2583 if (RowPrePaint != null) {
2584 RowPrePaint(this, e);
2588 // In MSDN2 documentation there's no internal here
2589 protected internal virtual void OnRowsAdded (DataGridViewRowsAddedEventArgs e) {
2590 if (RowsAdded != null) {
2595 protected virtual void OnRowsDefaultCellStyleChanged (EventArgs e) {
2596 if (RowsDefaultCellStyleChanged != null) {
2597 RowsDefaultCellStyleChanged(this, e);
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);
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);
2615 protected virtual void OnRowUnshared (DataGridViewRowEventArgs e) {
2616 if (RowUnshared != null) {
2617 RowUnshared(this, e);
2621 protected virtual void OnRowValidated (DataGridViewCellEventArgs e) {
2622 if (RowValidated != null) {
2623 RowValidated(this, e);
2627 protected virtual void OnRowValidating (DataGridViewCellCancelEventArgs e) {
2628 if (RowValidating != null) {
2629 RowValidating(this, e);
2633 protected virtual void OnScroll (ScrollEventArgs e) {
2634 if (Scroll != null) {
2639 protected virtual void OnSelectionChanged (EventArgs e) {
2640 if (SelectionChanged != null) {
2641 SelectionChanged(this, e);
2645 protected virtual void OnSortCompare (DataGridViewSortCompareEventArgs e) {
2646 if (SortCompare != null) {
2647 SortCompare(this, e);
2651 protected virtual void OnSorted (EventArgs e) {
2652 if (Sorted != null) {
2657 protected virtual void OnUserAddedRow (DataGridViewRowEventArgs e) {
2658 if (UserAddedRow != null) {
2659 UserAddedRow(this, e);
2663 protected virtual void OnUserDeletedRow (DataGridViewRowEventArgs e) {
2664 if (UserDeletedRow != null) {
2665 UserDeletedRow(this, e);
2669 protected virtual void OnUserDeletingRow (DataGridViewRowCancelEventArgs e) {
2670 if (UserDeletingRow != null) {
2671 UserDeletingRow(this, e);
2675 protected override void OnValidating (CancelEventArgs e) {
2676 base.OnValidating(e);
2679 protected override void OnVisibleChanged (EventArgs e) {
2680 base.OnVisibleChanged(e);
2683 protected virtual void PaintBackground (Graphics graphics, Rectangle clipBounds, Rectangle gridBounds) {
2686 protected bool ProcessAKey (Keys keyData) {
2687 throw new NotImplementedException();
2690 protected bool ProcessDataGridViewKey (KeyEventArgs e) {
2691 throw new NotImplementedException();
2694 protected bool ProcessDeleteKey (Keys keyData) {
2695 throw new NotImplementedException();
2698 protected override bool ProcessDialogKey (Keys keyData) {
2699 return base.ProcessDialogKey(keyData);
2700 //throw new NotImplementedException();
2703 protected bool ProcessDownKey (Keys keyData) {
2704 throw new NotImplementedException();
2707 protected bool ProcessEndKey (Keys keyData) {
2708 throw new NotImplementedException();
2711 protected bool ProcessEnterKey (Keys keyData) {
2712 throw new NotImplementedException();
2715 protected bool ProcessEscapeKey (Keys keyData) {
2716 throw new NotImplementedException();
2719 protected bool ProcessF2Key (Keys keyData) {
2720 throw new NotImplementedException();
2723 protected bool ProcessHomeKey (Keys keyData) {
2724 throw new NotImplementedException();
2727 protected bool ProcessInsertKey (Keys keyData) {
2728 throw new NotImplementedException();
2731 protected override bool ProcessKeyEventArgs (ref Message m) {
2732 return base.ProcessKeyEventArgs(ref m);
2733 //throw new NotImplementedException();
2736 protected override bool ProcessKeyPreview (ref Message m) {
2737 return base.ProcessKeyPreview(ref m);
2738 //throw new NotImplementedException();
2741 protected bool ProcessLeftKey (Keys keyData) {
2742 throw new NotImplementedException();
2745 protected bool ProcessNextKey (Keys keyData) {
2747 throw new NotImplementedException();
2750 protected bool ProcessPriorKey (Keys keyData) {
2752 throw new NotImplementedException();
2755 protected bool ProcessRightKey (Keys keyData) {
2756 throw new NotImplementedException();
2759 protected bool ProcessSpaceKey (Keys keyData) {
2760 throw new NotImplementedException();
2763 protected bool ProcessTabKey (Keys keyData) {
2764 throw new NotImplementedException();
2767 protected bool ProcessUpKey (Keys keyData) {
2768 throw new NotImplementedException();
2771 protected bool ProcessZeroKey (Keys keyData) {
2772 throw new NotImplementedException();
2775 protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified) {
2776 base.SetBoundsCore(x, y, width, height, specified);
2779 protected virtual bool SetCurrentCellAddressCore (int columnIndex, int rowIndex, bool setAnchorCellAddress, bool validateCurrentCell, bool throughMouseClick) {
2780 throw new NotImplementedException();
2783 protected virtual void SetSelectedCellCore (int columnIndex, int rowIndex, bool selected) {
2784 throw new NotImplementedException();
2787 protected virtual void SetSelectedColumnCore (int columnIndex, bool selected) {
2788 throw new NotImplementedException();
2791 protected virtual void SetSelectedRowCore (int rowIndex, bool selected) {
2792 throw new NotImplementedException();
2795 protected override void WndProc (ref Message m) {
2796 base.WndProc(ref m);
2799 internal void InternalOnCellClick (DataGridViewCellEventArgs e) {
2803 internal void InternalOnCellContentClick (DataGridViewCellEventArgs e) {
2804 OnCellContentClick(e);
2807 internal void InternalOnCellContentDoubleClick (DataGridViewCellEventArgs e) {
2808 OnCellContentDoubleClick(e);
2811 internal void InternalOnCellValueChanged (DataGridViewCellEventArgs e) {
2812 OnCellValueChanged(e);
2815 internal void InternalOnDataError (DataGridViewDataErrorEventArgs e) {
2816 /////////////// false? ////////////
2817 OnDataError(false, e);
2820 internal void InternalOnMouseWheel (MouseEventArgs e) {
2824 internal void OnHScrollBarScroll (object sender, ScrollEventArgs e) {
2825 horizontalScrollingOffset = e.NewValue;
2830 internal void OnVScrollBarScroll (object sender, ScrollEventArgs e) {
2831 verticalScrollingOffset = e.NewValue;
2836 internal void RaiseCellStyleChanged (DataGridViewCellEventArgs e) {
2837 OnCellStyleChanged(e);
2840 internal void OnColumnCollectionChanged (object sender, CollectionChangeEventArgs e) {
2842 case CollectionChangeAction.Add:
2843 OnColumnAdded(new DataGridViewColumnEventArgs(e.Element as DataGridViewColumn));
2845 case CollectionChangeAction.Remove:
2846 OnColumnRemoved(new DataGridViewColumnEventArgs(e.Element as DataGridViewColumn));
2848 case CollectionChangeAction.Refresh:
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;
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);
2875 private void BindIListSource (IListSource list) {
2876 BindIList(list.GetList());
2879 private void BindIBindingList (IBindingList list) {
2883 private void BindIBindingListView (IBindingListView list) {
2887 public sealed class HitTestInfo {
2889 public static readonly HitTestInfo Nowhere = new HitTestInfo(-1, -1, -1, -1, DataGridViewHitTestType.None);
2891 private int columnIndex;
2892 private int columnX;
2893 private int rowIndex;
2895 private DataGridViewHitTestType type;
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;
2905 public int ColumnIndex {
2906 get { return columnIndex; }
2909 public int ColumnX {
2910 get { return columnX; }
2913 public int RowIndex {
2914 get { return rowIndex; }
2918 get { return rowY; }
2921 public DataGridViewHitTestType Type {
2922 get { return type; }
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) {
2935 public override int GetHashCode () {
2936 return base.GetHashCode();
2939 public override string ToString () {
2940 return GetType().Name;
2945 [ComVisibleAttribute(true)]
2946 protected class DataGridViewAccessibleObject : ControlAccessibleObject {
2948 public DataGridViewAccessibleObject (DataGridView owner) : base (owner){
2951 public override AccessibleRole Role {
2952 get { return base.Role; }
2955 public override AccessibleObject GetChild (int index) {
2956 return base.GetChild(index);
2959 public override int GetChildCount () {
2960 return base.GetChildCount();
2963 public override AccessibleObject GetFocused () {
2964 return base.GetFocused();
2967 public override AccessibleObject GetSelected () {
2968 return base.GetSelected();
2971 public override AccessibleObject HitTest (int x, int y) {
2972 return base.HitTest(x, y);
2975 public override AccessibleObject Navigate( AccessibleNavigation navigationDirection) {
2976 return base.Navigate(navigationDirection);