首页 > Windows开发 > 详细

System.Windows.Forms

时间:2015-02-05 00:44:06      阅读:688      评论:0      收藏:0      [点我收藏+]
技术分享
   1 File: winforms\Managed\System\WinForms\DataGridView.cs
   2 Project: ndp\fx\src\System.Windows.Forms.csproj (System.Windows.Forms)    
   3 
   4 //------------------------------------------------------------------------------
   5 // <copyright file="DataGridView.cs" company="Microsoft">
   6 //     Copyright (c) Microsoft Corporation.  All rights reserved.
   7 // </copyright>            
   8 //------------------------------------------------------------------------------
   9  
  10 namespace System.Windows.Forms
  11 {
  12     using System.Text;
  13     using System.Runtime.InteropServices;
  14     using System.Runtime.Remoting;
  15     using System.ComponentModel;
  16     using System;
  17     using System.Diagnostics.CodeAnalysis;
  18     using System.Security;
  19     using System.Security.Permissions;
  20     using System.Collections;
  21     using System.Windows.Forms;
  22     using System.Windows.Forms.Design;    
  23     using System.ComponentModel.Design;
  24     using System.Drawing;
  25     using System.Windows.Forms.ComponentModel;
  26     using System.Windows.Forms.Layout;
  27     using System.Globalization;
  28     using System.Diagnostics;
  29     using System.Windows.Forms.VisualStyles;
  30     using Microsoft.Win32;
  31     using System.Collections.Specialized;
  32  
  33     /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView"]/*‘ />
  34     [
  35         ComVisible(true),
  36         ClassInterface(ClassInterfaceType.AutoDispatch),
  37         Designer("System.Windows.Forms.Design.DataGridViewDesigner, " + AssemblyRef.SystemDesign),
  38         //DefaultProperty("DataSource"),
  39         DefaultEvent("CellContentClick"),
  40         ComplexBindingProperties("DataSource", "DataMember"),
  41         Docking(DockingBehavior.Ask),
  42         Editor("System.Windows.Forms.Design.DataGridViewComponentEditor, " + AssemblyRef.SystemDesign, typeof(ComponentEditor)),
  43         SRDescription(SR.DescriptionDataGridView)
  44     ]
  45     public partial class DataGridView : Control, ISupportInitialize
  46     {
  47         private static readonly object EVENT_DATAGRIDVIEWALLOWUSERTOADDROWSCHANGED = new object();
  48         private static readonly object EVENT_DATAGRIDVIEWALLOWUSERTODELETEROWSCHANGED = new object();
  49         private static readonly object EVENT_DATAGRIDVIEWALLOWUSERTOORDERCOLUMNSCHANGED = new object();
  50         private static readonly object EVENT_DATAGRIDVIEWALLOWUSERTORESIZECOLUMNSCHANGED = new object();
  51         private static readonly object EVENT_DATAGRIDVIEWALLOWUSERTORESIZEROWSCHANGED = new object();
  52         private static readonly object EVENT_DATAGRIDVIEWALTERNATINGROWSDEFAULTCELLSTYLECHANGED = new object();
  53         private static readonly object EVENT_DATAGRIDVIEWAUTOGENERATECOLUMNSCHANGED = new object();
  54         private static readonly object EVENT_DATAGRIDVIEWAUTOSIZECOLUMNMODECHANGED = new object();
  55         private static readonly object EVENT_DATAGRIDVIEWAUTOSIZECOLUMNSMODECHANGED = new object();
  56         private static readonly object EVENT_DATAGRIDVIEWAUTOSIZEROWSMODECHANGED = new object();
  57         private static readonly object EVENT_DATAGRIDVIEWBACKGROUNDCOLORCHANGED = new object();
  58         private static readonly object EVENT_DATAGRIDVIEWBORDERSTYLECHANGED = new object();
  59         private static readonly object EVENT_DATAGRIDVIEWCANCELROWEDIT = new object();
  60         private static readonly object EVENT_DATAGRIDVIEWCELLBEGINEDIT = new object();
  61         private static readonly object EVENT_DATAGRIDVIEWCELLBORDERSTYLECHANGED = new object();
  62         private static readonly object EVENT_DATAGRIDVIEWCELLCLICK = new object();
  63         private static readonly object EVENT_DATAGRIDVIEWCELLCONTENTCLICK = new object();
  64         private static readonly object EVENT_DATAGRIDVIEWCELLCONTENTDOUBLECLICK = new object();
  65         private static readonly object EVENT_DATAGRIDVIEWCELLCONTEXTMENUSTRIPCHANGED = new object();
  66         private static readonly object EVENT_DATAGRIDVIEWCELLCONTEXTMENUSTRIPNEEDED = new object();
  67         private static readonly object EVENT_DATAGRIDVIEWCELLDOUBLECLICK = new object();
  68         private static readonly object EVENT_DATAGRIDVIEWCELLENDEDIT = new object();
  69         private static readonly object EVENT_DATAGRIDVIEWCELLENTER = new object();
  70         private static readonly object EVENT_DATAGRIDVIEWCELLERRORTEXTCHANGED = new object();
  71         private static readonly object EVENT_DATAGRIDVIEWCELLERRORTEXTNEEDED = new object();
  72         private static readonly object EVENT_DATAGRIDVIEWCELLFORMATTING = new object();
  73         private static readonly object EVENT_DATAGRIDVIEWCELLLEAVE = new object();
  74         private static readonly object EVENT_DATAGRIDVIEWCELLMOUSECLICK = new object();
  75         private static readonly object EVENT_DATAGRIDVIEWCELLMOUSEDOUBLECLICK = new object();
  76         private static readonly object EVENT_DATAGRIDVIEWCELLMOUSEDOWN = new object();
  77         private static readonly object EVENT_DATAGRIDVIEWCELLMOUSEENTER = new object();
  78         private static readonly object EVENT_DATAGRIDVIEWCELLMOUSELEAVE = new object();
  79         private static readonly object EVENT_DATAGRIDVIEWCELLMOUSEMOVE = new object();
  80         private static readonly object EVENT_DATAGRIDVIEWCELLMOUSEUP = new object();
  81         private static readonly object EVENT_DATAGRIDVIEWCELLPAINTING = new object();
  82         private static readonly object EVENT_DATAGRIDVIEWCELLPARSING = new object();
  83         private static readonly object EVENT_DATAGRIDVIEWCELLSTATECHANGED = new object();
  84         private static readonly object EVENT_DATAGRIDVIEWCELLSTYLECHANGED = new object();
  85         private static readonly object EVENT_DATAGRIDVIEWCELLSTYLECONTENTCHANGED = new object();
  86         private static readonly object EVENT_DATAGRIDVIEWCELLTOOLTIPTEXTCHANGED = new object();
  87         private static readonly object EVENT_DATAGRIDVIEWCELLTOOLTIPTEXTNEEDED = new object();
  88         private static readonly object EVENT_DATAGRIDVIEWCELLVALIDATING = new object();
  89         private static readonly object EVENT_DATAGRIDVIEWCELLVALIDATED = new object();
  90         private static readonly object EVENT_DATAGRIDVIEWCELLVALUECHANGED = new object();
  91         private static readonly object EVENT_DATAGRIDVIEWCELLVALUENEEDED = new object();
  92         private static readonly object EVENT_DATAGRIDVIEWCELLVALUEPUSHED = new object();
  93         private static readonly object EVENT_DATAGRIDVIEWCOLUMNADDED = new object();
  94         private static readonly object EVENT_DATAGRIDVIEWCOLUMNCONTEXTMENUSTRIPCHANGED = new object();
  95         private static readonly object EVENT_DATAGRIDVIEWCOLUMNDATAPROPERTYNAMECHANGED = new object();
  96         private static readonly object EVENT_DATAGRIDVIEWCOLUMNDEFAULTCELLSTYLECHANGED = new object();
  97         private static readonly object EVENT_DATAGRIDVIEWCOLUMNDISPLAYINDEXCHANGED = new object();
  98         private static readonly object EVENT_DATAGRIDVIEWCOLUMNDIVIDERWIDTHCHANGED = new object();
  99         private static readonly object EVENT_DATAGRIDVIEWCOLUMNHEADERCELLCHANGED = new object();
 100         private static readonly object EVENT_DATAGRIDVIEWCOLUMNDIVIDERDOUBLECLICK = new object();
 101         private static readonly object EVENT_DATAGRIDVIEWCOLUMNHEADERMOUSECLICK = new object();
 102         private static readonly object EVENT_DATAGRIDVIEWCOLUMNHEADERMOUSEDOUBLECLICK = new object();
 103         private static readonly object EVENT_DATAGRIDVIEWCOLUMNHEADERSBORDERSTYLECHANGED = new object();
 104         private static readonly object EVENT_DATAGRIDVIEWCOLUMNHEADERSDEFAULTCELLSTYLECHANGED = new object();
 105         private static readonly object EVENT_DATAGRIDVIEWCOLUMNHEADERSHEIGHTCHANGED = new object();
 106         private static readonly object EVENT_DATAGRIDVIEWCOLUMNHEADERSHEIGHTSIZEMODECHANGED = new object();
 107         private static readonly object EVENT_DATAGRIDVIEWCOLUMNMINIMUMWIDTHCHANGED = new object();
 108         private static readonly object EVENT_DATAGRIDVIEWCOLUMNNAMECHANGED = new object();
 109         private static readonly object EVENT_DATAGRIDVIEWCOLUMNREMOVED = new object();
 110         private static readonly object EVENT_DATAGRIDVIEWCOLUMNSORTMODECHANGED = new object();
 111         private static readonly object EVENT_DATAGRIDVIEWCOLUMNSTATECHANGED = new object();
 112         private static readonly object EVENT_DATAGRIDVIEWCOLUMNTOOLTIPTEXTCHANGED = new object();
 113         private static readonly object EVENT_DATAGRIDVIEWCOLUMNWIDTHCHANGED = new object();
 114         private static readonly object EVENT_DATAGRIDVIEWCURRENTCELLCHANGED = new object();
 115         private static readonly object EVENT_DATAGRIDVIEWCURRENTCELLDIRTYSTATECHANGED = new object();
 116         private static readonly object EVENT_DATAGRIDVIEWDATABINDINGCOMPLETE = new object();
 117         private static readonly object EVENT_DATAGRIDVIEWDATAERROR = new object();
 118         private static readonly object EVENT_DATAGRIDVIEWDATAMEMBERCHANGED = new object();
 119         private static readonly object EVENT_DATAGRIDVIEWDATASOURCECHANGED = new object();
 120         private static readonly object EVENT_DATAGRIDVIEWDEFAULTCELLSTYLECHANGED = new object();
 121         private static readonly object EVENT_DATAGRIDVIEWDEFAULTVALUESNEEDED = new object();
 122         private static readonly object EVENT_DATAGRIDVIEWEDITINGCONTROLSHOWING = new object();
 123         private static readonly object EVENT_DATAGRIDVIEWEDITMODECHANGED = new object();
 124         private static readonly object EVENT_DATAGRIDVIEWGRIDCOLORCHANGED = new object();
 125         private static readonly object EVENT_DATAGRIDVIEWMULTISELECTCHANGED = new object();
 126         private static readonly object EVENT_DATAGRIDVIEWNEWROWNEEDED = new object();
 127         private static readonly object EVENT_DATAGRIDVIEWREADONLYCHANGED = new object();
 128         private static readonly object EVENT_DATAGRIDVIEWROWCONTEXTMENUSTRIPCHANGED = new object();
 129         private static readonly object EVENT_DATAGRIDVIEWROWCONTEXTMENUSTRIPNEEDED = new object();
 130         private static readonly object EVENT_DATAGRIDVIEWROWDEFAULTCELLSTYLECHANGED = new object();
 131         private static readonly object EVENT_DATAGRIDVIEWROWDIRTYSTATENEEDED = new Object();
 132         private static readonly object EVENT_DATAGRIDVIEWROWDIVIDERHEIGHTCHANGED = new object();
 133         private static readonly object EVENT_DATAGRIDVIEWROWENTER = new object();
 134         private static readonly object EVENT_DATAGRIDVIEWROWERRORTEXTCHANGED = new object();
 135         private static readonly object EVENT_DATAGRIDVIEWROWERRORTEXTNEEDED = new object();
 136         private static readonly object EVENT_DATAGRIDVIEWROWHEADERCELLCHANGED = new object();
 137         private static readonly object EVENT_DATAGRIDVIEWROWDIVIDERDOUBLECLICK = new object();
 138         private static readonly object EVENT_DATAGRIDVIEWROWHEADERMOUSECLICK = new object();
 139         private static readonly object EVENT_DATAGRIDVIEWROWHEADERMOUSEDOUBLECLICK = new object();
 140         private static readonly object EVENT_DATAGRIDVIEWROWHEADERSBORDERSTYLECHANGED = new object();
 141         private static readonly object EVENT_DATAGRIDVIEWROWHEADERSDEFAULTCELLSTYLECHANGED = new object();
 142         private static readonly object EVENT_DATAGRIDVIEWROWHEADERSWIDTHCHANGED = new object();
 143         private static readonly object EVENT_DATAGRIDVIEWROWHEADERSWIDTHSIZEMODECHANGED = new object();
 144         private static readonly object EVENT_DATAGRIDVIEWROWHEIGHTCHANGED = new object();
 145         private static readonly object EVENT_DATAGRIDVIEWROWHEIGHTINFONEEDED = new object();
 146         private static readonly object EVENT_DATAGRIDVIEWROWHEIGHTINFOPUSHED = new object();
 147         private static readonly object EVENT_DATAGRIDVIEWROWLEAVE = new object();
 148         private static readonly object EVENT_DATAGRIDVIEWROWMINIMUMHEIGHTCHANGED = new object();
 149         private static readonly object EVENT_DATAGRIDVIEWROWPOSTPAINT = new object();
 150         private static readonly object EVENT_DATAGRIDVIEWROWPREPAINT = new object();
 151         private static readonly object EVENT_DATAGRIDVIEWROWSADDED = new object();
 152         private static readonly object EVENT_DATAGRIDVIEWROWSDEFAULTCELLSTYLECHANGED = new object();
 153         private static readonly object EVENT_DATAGRIDVIEWROWSREMOVED = new object();
 154         private static readonly object EVENT_DATAGRIDVIEWROWSTATECHANGED = new object();
 155         private static readonly object EVENT_DATAGRIDVIEWROWUNSHARED = new object();
 156         private static readonly object EVENT_DATAGRIDVIEWROWVALIDATED = new object();
 157         private static readonly object EVENT_DATAGRIDVIEWROWVALIDATING = new object();
 158         private static readonly object EVENT_DATAGRIDVIEWSCROLL = new object();
 159         private static readonly object EVENT_DATAGRIDVIEWSELECTIONCHANGED = new object();
 160         private static readonly object EVENT_DATAGRIDVIEWSORTCOMPARE = new object();
 161         private static readonly object EVENT_DATAGRIDVIEWSORTED = new object();
 162         private static readonly object EVENT_DATAGRIDVIEWUSERADDEDROW = new object();
 163         private static readonly object EVENT_DATAGRIDVIEWUSERDELETEDROW = new object();
 164         private static readonly object EVENT_DATAGRIDVIEWUSERDELETINGROW = new object();
 165  
 166         private const int DATAGRIDVIEWSTATE1_allowUserToAddRows           = 0x00000001;
 167         private const int DATAGRIDVIEWSTATE1_allowUserToDeleteRows        = 0x00000002;
 168         private const int DATAGRIDVIEWSTATE1_allowUserToOrderColumns      = 0x00000004;
 169         private const int DATAGRIDVIEWSTATE1_columnHeadersVisible         = 0x00000008;
 170         private const int DATAGRIDVIEWSTATE1_rowHeadersVisible            = 0x00000010;
 171         private const int DATAGRIDVIEWSTATE1_forwardCharMessage           = 0x00000020;
 172         private const int DATAGRIDVIEWSTATE1_leavingWithTabKey            = 0x00000040;
 173         private const int DATAGRIDVIEWSTATE1_multiSelect                  = 0x00000080;
 174         private const int DATAGRIDVIEWSTATE1_ignoringEditingChanges       = 0x00000200;
 175         private const int DATAGRIDVIEWSTATE1_ambientForeColor             = 0x00000400;
 176         private const int DATAGRIDVIEWSTATE1_scrolledSinceMouseDown       = 0x00000800;
 177         private const int DATAGRIDVIEWSTATE1_editingControlHidden         = 0x00001000;
 178         private const int DATAGRIDVIEWSTATE1_standardTab                  = 0x00002000;
 179         private const int DATAGRIDVIEWSTATE1_editingControlChanging       = 0x00004000;
 180         private const int DATAGRIDVIEWSTATE1_currentCellInEditMode        = 0x00008000;
 181         private const int DATAGRIDVIEWSTATE1_virtualMode                  = 0x00010000;
 182         private const int DATAGRIDVIEWSTATE1_editedCellChanged            = 0x00020000;
 183         private const int DATAGRIDVIEWSTATE1_editedRowChanged             = 0x00040000;
 184         private const int DATAGRIDVIEWSTATE1_newRowEdited                 = 0x00080000;
 185         private const int DATAGRIDVIEWSTATE1_readOnly                     = 0x00100000;
 186         private const int DATAGRIDVIEWSTATE1_newRowCreatedByEditing       = 0x00200000;
 187         private const int DATAGRIDVIEWSTATE1_temporarilyResetCurrentCell  = 0x00400000;
 188         private const int DATAGRIDVIEWSTATE1_autoGenerateColumns          = 0x00800000;
 189         private const int DATAGRIDVIEWSTATE1_customCursorSet              = 0x01000000;
 190         private const int DATAGRIDVIEWSTATE1_ambientFont                  = 0x02000000;
 191         private const int DATAGRIDVIEWSTATE1_ambientColumnHeadersFont     = 0x04000000;
 192         private const int DATAGRIDVIEWSTATE1_ambientRowHeadersFont        = 0x08000000;
 193         private const int DATAGRIDVIEWSTATE1_isRestrictedChecked          = 0x10000000;
 194         private const int DATAGRIDVIEWSTATE1_isRestricted                 = 0x20000000;
 195         private const int DATAGRIDVIEWSTATE1_isAutoSized                  = 0x40000000;
 196  
 197         // DATAGRIDVIEWSTATE2_
 198         private const int DATAGRIDVIEWSTATE2_showEditingIcon               = 0x00000001;
 199         private const int DATAGRIDVIEWSTATE2_allowUserToResizeColumns      = 0x00000002;
 200         private const int DATAGRIDVIEWSTATE2_allowUserToResizeRows         = 0x00000004;
 201         private const int DATAGRIDVIEWSTATE2_mouseOverRemovedEditingCtrl   = 0x00000008;
 202         private const int DATAGRIDVIEWSTATE2_mouseOverRemovedEditingPanel  = 0x00000010;
 203         private const int DATAGRIDVIEWSTATE2_mouseEnterExpected            = 0x00000020;
 204         private const int DATAGRIDVIEWSTATE2_enableHeadersVisualStyles     = 0x00000040;
 205         private const int DATAGRIDVIEWSTATE2_showCellErrors                = 0x00000080;
 206         private const int DATAGRIDVIEWSTATE2_showCellToolTips              = 0x00000100;
 207         private const int DATAGRIDVIEWSTATE2_showRowErrors                 = 0x00000200;
 208         private const int DATAGRIDVIEWSTATE2_showColumnRelocationInsertion = 0x00000400;
 209         private const int DATAGRIDVIEWSTATE2_rightToLeftMode               = 0x00000800;
 210         private const int DATAGRIDVIEWSTATE2_rightToLeftValid              = 0x00001000;
 211         private const int DATAGRIDVIEWSTATE2_currentCellWantsInputKey      = 0x00002000;
 212         private const int DATAGRIDVIEWSTATE2_stopRaisingVerticalScroll     = 0x00004000;
 213         private const int DATAGRIDVIEWSTATE2_stopRaisingHorizontalScroll   = 0x00008000;
 214         private const int DATAGRIDVIEWSTATE2_replacedCellSelected          = 0x00010000;
 215         private const int DATAGRIDVIEWSTATE2_replacedCellReadOnly          = 0x00020000;
 216         private const int DATAGRIDVIEWSTATE2_raiseSelectionChanged         = 0x00040000;
 217         private const int DATAGRIDVIEWSTATE2_initializing                  = 0x00080000;
 218         private const int DATAGRIDVIEWSTATE2_autoSizedWithoutHandle        = 0x00100000;
 219         private const int DATAGRIDVIEWSTATE2_ignoreCursorChange            = 0x00200000;
 220         private const int DATAGRIDVIEWSTATE2_rowsCollectionClearedInSetCell= 0x00400000;
 221         private const int DATAGRIDVIEWSTATE2_nextMouseUpIsDouble           = 0x00800000;
 222         private const int DATAGRIDVIEWSTATE2_inBindingContextChanged       = 0x01000000;
 223         private const int DATAGRIDVIEWSTATE2_allowHorizontalScrollbar      = 0x02000000;
 224         private const int DATAGRIDVIEWSTATE2_usedFillWeightsDirty          = 0x04000000;
 225         private const int DATAGRIDVIEWSTATE2_messageFromEditingCtrls       = 0x08000000;
 226         private const int DATAGRIDVIEWSTATE2_cellMouseDownInContentBounds  = 0x10000000;
 227         private const int DATAGRIDVIEWSTATE2_discardEditingControl         = 0x20000000;
 228  
 229         // DATAGRIDVIEWOPER_
 230         private const int DATAGRIDVIEWOPER_trackColResize                = 0x00000001;
 231         private const int DATAGRIDVIEWOPER_trackRowResize                = 0x00000002;
 232         private const int DATAGRIDVIEWOPER_trackColSelect                = 0x00000004;
 233         private const int DATAGRIDVIEWOPER_trackRowSelect                = 0x00000008;
 234         private const int DATAGRIDVIEWOPER_trackCellSelect               = 0x00000010;
 235         private const int DATAGRIDVIEWOPER_trackColRelocation            = 0x00000020;
 236         private const int DATAGRIDVIEWOPER_inSort                        = 0x00000040;
 237         private const int DATAGRIDVIEWOPER_trackColHeadersResize         = 0x00000080;
 238         private const int DATAGRIDVIEWOPER_trackRowHeadersResize         = 0x00000100;
 239         private const int DATAGRIDVIEWOPER_trackMouseMoves               = 0x00000200;
 240         private const int DATAGRIDVIEWOPER_inRefreshColumns              = 0x00000400;
 241         private const int DATAGRIDVIEWOPER_inDisplayIndexAdjustments     = 0x00000800;
 242         private const int DATAGRIDVIEWOPER_lastEditCtrlClickDoubled      = 0x00001000;
 243         private const int DATAGRIDVIEWOPER_inMouseDown                   = 0x00002000;
 244         private const int DATAGRIDVIEWOPER_inReadOnlyChange              = 0x00004000;
 245         private const int DATAGRIDVIEWOPER_inCellValidating              = 0x00008000;
 246         private const int DATAGRIDVIEWOPER_inBorderStyleChange           = 0x00010000;
 247         private const int DATAGRIDVIEWOPER_inCurrentCellChange           = 0x00020000;
 248         private const int DATAGRIDVIEWOPER_inAdjustFillingColumns        = 0x00040000;
 249         private const int DATAGRIDVIEWOPER_inAdjustFillingColumn         = 0x00080000;
 250         private const int DATAGRIDVIEWOPER_inDispose                     = 0x00100000;
 251         private const int DATAGRIDVIEWOPER_inBeginEdit                   = 0x00200000;
 252         private const int DATAGRIDVIEWOPER_inEndEdit                     = 0x00400000;
 253         private const int DATAGRIDVIEWOPER_resizingOperationAboutToStart = 0x00800000;
 254  
 255         private static Size DragSize = SystemInformation.DragSize;
 256  
 257         private const byte DATAGRIDVIEW_columnSizingHotZone = 6;
 258         private const byte DATAGRIDVIEW_rowSizingHotZone = 5;
 259         private const byte DATAGRIDVIEW_insertionBarWidth = 3;
 260         private const byte DATAGRIDVIEW_bulkPaintThreshold = 8;
 261  
 262         private const string DATAGRIDVIEW_htmlPrefix = "Version:1.0\r\nStartHTML:00000097\r\nEndHTML:{0}\r\nStartFragment:00000133\r\nEndFragment:{1}\r\n";
 263         private const string DATAGRIDVIEW_htmlStartFragment = "<HTML>\r\n<BODY>\r\n<!--StartFragment-->";
 264         private const string DATAGRIDVIEW_htmlEndFragment = "\r\n<!--EndFragment-->\r\n</BODY>\r\n</HTML>";
 265  
 266         private System.Collections.Specialized.BitVector32 dataGridViewState1;  // see DATAGRIDVIEWSTATE1_ consts above
 267         private System.Collections.Specialized.BitVector32 dataGridViewState2;  // see DATAGRIDVIEWSTATE2_ consts above
 268         private System.Collections.Specialized.BitVector32 dataGridViewOper;   // see DATAGRIDVIEWOPER_ consts above
 269  
 270         private const BorderStyle defaultBorderStyle = BorderStyle.FixedSingle;
 271         private const DataGridViewAdvancedCellBorderStyle defaultAdvancedCellBorderStyle = DataGridViewAdvancedCellBorderStyle.Single;
 272         private const DataGridViewAdvancedCellBorderStyle defaultAdvancedRowHeadersBorderStyle = DataGridViewAdvancedCellBorderStyle.OutsetPartial;
 273         private const DataGridViewAdvancedCellBorderStyle defaultAdvancedColumnHeadersBorderStyle = DataGridViewAdvancedCellBorderStyle.OutsetPartial;
 274  
 275         private const DataGridViewSelectionMode defaultSelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
 276         private const DataGridViewEditMode defaultEditMode = DataGridViewEditMode.EditOnKeystrokeOrF2;
 277  
 278         private const DataGridViewAutoSizeRowCriteriaInternal invalidDataGridViewAutoSizeRowCriteriaInternalMask = ~(DataGridViewAutoSizeRowCriteriaInternal.Header | DataGridViewAutoSizeRowCriteriaInternal.AllColumns);
 279  
 280         private SolidBrush backgroundBrush = DefaultBackgroundBrush;
 281         private Pen gridPen;
 282         private Cursor oldCursor;
 283  
 284         private HScrollBar horizScrollBar = new HScrollBar();
 285         private VScrollBar vertScrollBar = new VScrollBar();
 286         private DataGridViewHeaderCell topLeftHeaderCell;
 287  
 288         private DataGridViewRow rowTemplate;
 289         private DataGridViewRowCollection dataGridViewRows;
 290         private DataGridViewColumnCollection dataGridViewColumns;
 291  
 292         private DataGridViewCellStyle placeholderCellStyle;
 293         private StringFormat placeholderStringFormat;
 294  
 295         private DataGridViewColumn sortedColumn;
 296         private SortOrder sortOrder;
 297  
 298         private object uneditedFormattedValue;
 299         private Control editingControl, latestEditingControl, cachedEditingControl;
 300         private Panel editingPanel;
 301         private Point ptCurrentCell, ptCurrentCellCache = Point.Empty, ptAnchorCell, ptMouseDownCell, ptMouseEnteredCell, ptToolTipCell, ptMouseDownGridCoord;
 302  
 303         private DataGridViewSelectionMode selectionMode;
 304         private DataGridViewEditMode editMode;
 305  
 306         // Note that a cell can only be in one bag but not both at the same time.
 307         private DataGridViewCellLinkedList individualSelectedCells;
 308         private DataGridViewCellLinkedList individualReadOnlyCells;
 309         private DataGridViewIntLinkedList selectedBandIndexes;
 310         private DataGridViewIntLinkedList selectedBandSnapshotIndexes;
 311  
 312         private DataGridViewCellStyle defaultCellStyle, columnHeadersDefaultCellStyle, rowHeadersDefaultCellStyle;
 313         private DataGridViewCellStyle rowsDefaultCellStyle, alternatingRowsDefaultCellStyle;
 314         private ScrollBars scrollBars;
 315         private LayoutData layout;
 316         private DisplayedBandsData displayedBandsInfo;
 317         private Rectangle normalClientRectangle;
 318         private ArrayList lstRows;
 319         private int availableWidthForFillColumns;
 320  
 321         private BorderStyle borderStyle;
 322         private DataGridViewAdvancedBorderStyle advancedCellBorderStyle;
 323         private DataGridViewAdvancedBorderStyle advancedRowHeadersBorderStyle;
 324         private DataGridViewAdvancedBorderStyle advancedColumnHeadersBorderStyle;
 325  
 326         private DataGridViewClipboardCopyMode clipboardCopyMode;
 327  
 328         private const int minimumRowHeadersWidth = 4;
 329         private const int minimumColumnHeadersHeight = 4;
 330         private const int defaultRowHeadersWidth = 41;
 331         private const int maxHeadersThickness = 32768;
 332         private const int upperSize = 0x007FFFFF;
 333         private int rowHeadersWidth = defaultRowHeadersWidth;
 334         private int cachedRowHeadersWidth;
 335         private const int defaultColumnHeadersHeight = 23;
 336         private int columnHeadersHeight = defaultColumnHeadersHeight;
 337         private int cachedColumnHeadersHeight;
 338         private DataGridViewAutoSizeRowsMode autoSizeRowsMode;
 339         private DataGridViewAutoSizeColumnsMode autoSizeColumnsMode;
 340         private DataGridViewColumnHeadersHeightSizeMode columnHeadersHeightSizeMode;
 341         private DataGridViewRowHeadersWidthSizeMode rowHeadersWidthSizeMode;
 342  
 343         private DataGridViewCellStyleChangedEventArgs dgvcsce;
 344         private DataGridViewCellPaintingEventArgs dgvcpe;
 345         private DataGridViewCellValueEventArgs dgvcve;
 346         private DataGridViewRowHeightInfoNeededEventArgs dgvrhine;
 347         private DataGridViewRowPostPaintEventArgs dgvrpope;
 348         private DataGridViewRowPrePaintEventArgs dgvrprpe;
 349  
 350         // the sum of the widths in pixels of the scrolling columns preceding 
 351         // the first visible scrolling column
 352         private int horizontalOffset;
 353  
 354         // the sum of the heights in pixels of the scrolling rows preceding 
 355         // the first visible scrolling row
 356         private int verticalOffset;
 357  
 358         // the number of pixels of the firstDisplayedScrollingCol which are not visible
 359         private int negOffset;
 360  
 361         // the index of the potential ‘new‘ row. -1 if there is no ‘new‘ row.
 362         private int newRowIndex = -1;
 363  
 364         // residual fraction of WHEEL_DELTA (120) for wheel scrolling
 365         private int cumulativeVerticalWheelDelta;
 366         private int cumulativeHorizontalWheelDelta;
 367  
 368         private int trackColAnchor;
 369         private int trackColumn = -1;
 370         private int trackColumnEdge = -1;
 371         private int trackRowAnchor;
 372         private int trackRow = -1;
 373         private int trackRowEdge = -1;
 374         private int lastHeaderShadow = -1;
 375         private int currentColSplitBar = -1, lastColSplitBar = -1;
 376         private int currentRowSplitBar = -1, lastRowSplitBar = -1;
 377         private int mouseBarOffset;
 378         private int noDimensionChangeCount;
 379         private int noSelectionChangeCount;
 380         private int noAutoSizeCount;
 381         private int inBulkPaintCount;
 382         private int inBulkLayoutCount;
 383         private int inPerformLayoutCount;
 384  
 385         private System.Windows.Forms.Timer vertScrollTimer, horizScrollTimer;
 386  
 387         private Hashtable converters;
 388         private Hashtable pens;
 389         private Hashtable brushes;
 390  
 391         private NativeMethods.RECT[] cachedScrollableRegion;
 392  
 393         // DataBinding
 394         private DataGridViewDataConnection dataConnection;
 395  
 396         // ToolTip
 397         private DataGridViewToolTip toolTipControl;
 398         // the tool tip string we get from cells
 399         private string toolTipCaption = String.Empty;
 400         
 401         private const int maxTTDISPINFOBufferLength = 80;
 402  
 403         // Last Mouse Click Info
 404         private MouseClickInfo lastMouseClickInfo;
 405  
 406 #if DEBUG
 407         // set to false when the grid is not in [....] with the underlying data store
 408         // in virtual mode, and OnCellValueNeeded cannot be called.
 409 // disable csharp compiler warning #0414: field assigned unused value
 410 #pragma warning disable 0414
 411         internal bool dataStoreAccessAllowed = true;
 412 #pragma warning restore 0414
 413 #endif
 414         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.DataGridView"]/*‘ />
 415         /// <devdoc>
 416         /// <para>Initializes a new instance of the <see cref=‘System.Windows.Forms.DataGridView‘/> class.</para>
 417         /// </devdoc>
 418         public DataGridView()
 419         {
 420             SetStyle(ControlStyles.UserPaint | 
 421                      ControlStyles.Opaque | 
 422                      ControlStyles.UserMouse, true);
 423             
 424             SetStyle(ControlStyles.SupportsTransparentBackColor, false);
 425  
 426             // this class overrides GetPreferredSizeCore, let Control automatically cache the result
 427             SetState2(STATE2_USEPREFERREDSIZECACHE, true);  
 428  
 429             this.dataGridViewState1 = new System.Collections.Specialized.BitVector32(0x00000000);
 430             this.dataGridViewState2 = new System.Collections.Specialized.BitVector32(0x00000000);
 431             this.dataGridViewOper   = new System.Collections.Specialized.BitVector32(0x00000000);
 432  
 433             this.dataGridViewState1[  DATAGRIDVIEWSTATE1_columnHeadersVisible 
 434                                     | DATAGRIDVIEWSTATE1_rowHeadersVisible 
 435                                     | DATAGRIDVIEWSTATE1_autoGenerateColumns
 436                                     | DATAGRIDVIEWSTATE1_allowUserToAddRows
 437                                     | DATAGRIDVIEWSTATE1_allowUserToDeleteRows ] = true;
 438  
 439  
 440  
 441             this.dataGridViewState2[  DATAGRIDVIEWSTATE2_showEditingIcon
 442                                     | DATAGRIDVIEWSTATE2_enableHeadersVisualStyles
 443                                     | DATAGRIDVIEWSTATE2_mouseEnterExpected
 444                                     | DATAGRIDVIEWSTATE2_allowUserToResizeColumns
 445                                     | DATAGRIDVIEWSTATE2_allowUserToResizeRows
 446                                     | DATAGRIDVIEWSTATE2_showCellToolTips
 447                                     | DATAGRIDVIEWSTATE2_showCellErrors
 448                                     | DATAGRIDVIEWSTATE2_showRowErrors
 449                                     | DATAGRIDVIEWSTATE2_allowHorizontalScrollbar
 450                                     | DATAGRIDVIEWSTATE2_usedFillWeightsDirty ] = true;
 451  
 452  
 453             this.displayedBandsInfo = new DisplayedBandsData();
 454             this.lstRows = new ArrayList();
 455  
 456             this.converters = new Hashtable(8);
 457             this.pens = new Hashtable(8);
 458             this.brushes = new Hashtable(10);
 459             this.gridPen = new Pen(DefaultGridColor);
 460  
 461             this.selectedBandIndexes = new DataGridViewIntLinkedList();
 462             this.individualSelectedCells = new DataGridViewCellLinkedList();
 463             this.individualReadOnlyCells = new DataGridViewCellLinkedList();
 464  
 465             this.advancedCellBorderStyle = new DataGridViewAdvancedBorderStyle(this, 
 466                 DataGridViewAdvancedCellBorderStyle.OutsetDouble, 
 467                 DataGridViewAdvancedCellBorderStyle.OutsetPartial, 
 468                 DataGridViewAdvancedCellBorderStyle.InsetDouble);
 469             this.advancedRowHeadersBorderStyle = new DataGridViewAdvancedBorderStyle(this);
 470             this.advancedColumnHeadersBorderStyle = new DataGridViewAdvancedBorderStyle(this);
 471             this.advancedCellBorderStyle.All = defaultAdvancedCellBorderStyle;
 472             this.advancedRowHeadersBorderStyle.All = defaultAdvancedRowHeadersBorderStyle;
 473             this.advancedColumnHeadersBorderStyle.All = defaultAdvancedColumnHeadersBorderStyle;
 474             this.borderStyle = defaultBorderStyle;
 475             this.dataGridViewState1[DATAGRIDVIEWSTATE1_multiSelect] = true;
 476             this.selectionMode = defaultSelectionMode;
 477             this.editMode = defaultEditMode;
 478             this.autoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
 479             this.autoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
 480             this.columnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
 481             this.rowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.EnableResizing;
 482  
 483             this.clipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithAutoHeaderText;
 484  
 485             this.layout = new LayoutData();
 486             this.layout.TopLeftHeader        = Rectangle.Empty;
 487             this.layout.ColumnHeaders        = Rectangle.Empty;
 488             this.layout.RowHeaders           = Rectangle.Empty;
 489             this.layout.ColumnHeadersVisible = true;
 490             this.layout.RowHeadersVisible    = true;
 491             this.layout.ClientRectangle      = this.ClientRectangle;
 492  
 493             this.scrollBars = ScrollBars.Both;
 494  
 495             this.horizScrollBar.RightToLeft = RightToLeft.Inherit;
 496             this.horizScrollBar.AccessibleName = SR.GetString(SR.DataGridView_AccHorizontalScrollBarAccName);
 497             this.horizScrollBar.Top = this.ClientRectangle.Height - horizScrollBar.Height;
 498             this.horizScrollBar.Left = 0;
 499             this.horizScrollBar.Visible = false;
 500             this.horizScrollBar.Scroll += new ScrollEventHandler(DataGridViewHScrolled);
 501             this.Controls.Add(this.horizScrollBar);
 502  
 503             this.vertScrollBar.Top = 0;
 504             this.vertScrollBar.AccessibleName = SR.GetString(SR.DataGridView_AccVerticalScrollBarAccName);
 505             this.vertScrollBar.Left = this.ClientRectangle.Width - vertScrollBar.Width;
 506             this.vertScrollBar.Visible = false;
 507             this.vertScrollBar.Scroll += new ScrollEventHandler(DataGridViewVScrolled);
 508             this.Controls.Add(this.vertScrollBar);
 509  
 510             this.ptCurrentCell = new Point(-1, -1);
 511             this.ptAnchorCell = new Point(-1, -1);
 512             this.ptMouseDownCell = new Point(-2, -2);
 513             this.ptMouseEnteredCell = new Point(-2, -2);
 514             this.ptToolTipCell = new Point(-1, -1);
 515             this.ptMouseDownGridCoord = new Point(-1, -1);
 516  
 517             this.sortOrder = SortOrder.None;
 518  
 519             this.lastMouseClickInfo.timeStamp = 0;
 520  
 521             WireScrollBarsEvents();
 522             PerformLayout();
 523  
 524             this.toolTipControl = new DataGridViewToolTip(this);
 525             
 526             Invalidate();
 527         }
 528  
 529         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.AdjustedTopLeftHeaderBorderStyle"]/*‘ />
 530         [
 531             Browsable(false),
 532             EditorBrowsable(EditorBrowsableState.Advanced),
 533             DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
 534         ]
 535         public virtual DataGridViewAdvancedBorderStyle AdjustedTopLeftHeaderBorderStyle
 536         {
 537             get
 538             {
 539                 DataGridViewAdvancedBorderStyle dgvabs;
 540                 if (this.ApplyVisualStylesToHeaderCells)
 541                 {
 542                     switch (this.AdvancedColumnHeadersBorderStyle.All)
 543                     {
 544                         case DataGridViewAdvancedCellBorderStyle.OutsetDouble:
 545                         case DataGridViewAdvancedCellBorderStyle.OutsetPartial:
 546                             dgvabs = new DataGridViewAdvancedBorderStyle();
 547                             if (this.RightToLeftInternal)
 548                             {
 549                                 dgvabs.LeftInternal = DataGridViewAdvancedCellBorderStyle.Outset;
 550                             }
 551                             else
 552                             {
 553                                 dgvabs.LeftInternal = DataGridViewAdvancedCellBorderStyle.OutsetDouble;
 554                             }
 555                             dgvabs.RightInternal = DataGridViewAdvancedCellBorderStyle.Outset;
 556                             dgvabs.TopInternal = DataGridViewAdvancedCellBorderStyle.OutsetDouble;
 557                             dgvabs.BottomInternal = DataGridViewAdvancedCellBorderStyle.Outset;
 558                             break;
 559  
 560                         case DataGridViewAdvancedCellBorderStyle.InsetDouble:
 561                             dgvabs = new DataGridViewAdvancedBorderStyle();
 562                             if (this.RightToLeftInternal)
 563                             {
 564                                 dgvabs.LeftInternal = DataGridViewAdvancedCellBorderStyle.Inset;
 565                             }
 566                             else
 567                             {
 568                                 dgvabs.LeftInternal = DataGridViewAdvancedCellBorderStyle.InsetDouble;
 569                             }
 570                             dgvabs.RightInternal = DataGridViewAdvancedCellBorderStyle.Inset;
 571                             dgvabs.TopInternal = DataGridViewAdvancedCellBorderStyle.InsetDouble;
 572                             dgvabs.BottomInternal = DataGridViewAdvancedCellBorderStyle.Inset;
 573                             break;
 574  
 575                         case DataGridViewAdvancedCellBorderStyle.NotSet:
 576                             // Since the row headers are visible, we should make sure
 577                             // that there is a left/right border for the TopLeftHeaderCell no matter what.
 578                             if ((!this.RightToLeftInternal && this.AdvancedColumnHeadersBorderStyle.Left == DataGridViewAdvancedCellBorderStyle.None) ||
 579                                 (this.RightToLeftInternal && this.AdvancedColumnHeadersBorderStyle.Right == DataGridViewAdvancedCellBorderStyle.None))
 580                             {
 581                                 dgvabs = new DataGridViewAdvancedBorderStyle();
 582                                 if (this.RightToLeftInternal)
 583                                 {
 584                                     dgvabs.LeftInternal = this.AdvancedColumnHeadersBorderStyle.Left;
 585                                     dgvabs.RightInternal = this.AdvancedRowHeadersBorderStyle.Right == DataGridViewAdvancedCellBorderStyle.OutsetDouble ?
 586                                         DataGridViewAdvancedCellBorderStyle.Outset : this.AdvancedRowHeadersBorderStyle.Right;
 587                                 }
 588                                 else
 589                                 {
 590                                     dgvabs.LeftInternal = this.AdvancedRowHeadersBorderStyle.Left;
 591                                     dgvabs.RightInternal = this.AdvancedColumnHeadersBorderStyle.Right;
 592                                 }
 593                                 dgvabs.TopInternal = this.AdvancedColumnHeadersBorderStyle.Top;
 594                                 dgvabs.BottomInternal = this.AdvancedColumnHeadersBorderStyle.Bottom;
 595                             }
 596                             else
 597                             {
 598                                 dgvabs = this.AdvancedColumnHeadersBorderStyle;
 599                             }
 600                             break;
 601  
 602                         default:
 603                             dgvabs = this.AdvancedColumnHeadersBorderStyle;
 604                             break;
 605                     }
 606                 }
 607                 else
 608                 {
 609                     switch (this.AdvancedColumnHeadersBorderStyle.All)
 610                     {
 611                         case DataGridViewAdvancedCellBorderStyle.OutsetDouble:
 612                         case DataGridViewAdvancedCellBorderStyle.OutsetPartial:
 613                             dgvabs = new DataGridViewAdvancedBorderStyle();
 614                             dgvabs.LeftInternal = this.RightToLeftInternal ? DataGridViewAdvancedCellBorderStyle.Outset : DataGridViewAdvancedCellBorderStyle.OutsetDouble;
 615                             dgvabs.RightInternal = this.RightToLeftInternal ? DataGridViewAdvancedCellBorderStyle.OutsetDouble : DataGridViewAdvancedCellBorderStyle.Outset;
 616                             dgvabs.TopInternal = DataGridViewAdvancedCellBorderStyle.OutsetDouble;
 617                             dgvabs.BottomInternal = DataGridViewAdvancedCellBorderStyle.Outset;
 618                             break;
 619  
 620                         case DataGridViewAdvancedCellBorderStyle.InsetDouble:
 621                             dgvabs = new DataGridViewAdvancedBorderStyle();
 622                             dgvabs.LeftInternal = this.RightToLeftInternal ? DataGridViewAdvancedCellBorderStyle.Inset : DataGridViewAdvancedCellBorderStyle.InsetDouble;
 623                             dgvabs.RightInternal = this.RightToLeftInternal ? DataGridViewAdvancedCellBorderStyle.InsetDouble : DataGridViewAdvancedCellBorderStyle.Inset;
 624                             dgvabs.TopInternal = DataGridViewAdvancedCellBorderStyle.InsetDouble;
 625                             dgvabs.BottomInternal = DataGridViewAdvancedCellBorderStyle.Inset;
 626                             break;
 627  
 628                         case DataGridViewAdvancedCellBorderStyle.NotSet:
 629                             // Since the row headers are visible, we should make sure
 630                             // that there is a left/right border for the TopLeftHeaderCell no matter what.
 631                             if ((!this.RightToLeftInternal && this.AdvancedColumnHeadersBorderStyle.Left == DataGridViewAdvancedCellBorderStyle.None) ||
 632                                 (this.RightToLeftInternal && this.AdvancedColumnHeadersBorderStyle.Right == DataGridViewAdvancedCellBorderStyle.None))
 633                             {
 634                                 dgvabs = new DataGridViewAdvancedBorderStyle();
 635                                 if (this.RightToLeftInternal)
 636                                 {
 637                                     dgvabs.LeftInternal = this.AdvancedColumnHeadersBorderStyle.Left;
 638                                     dgvabs.RightInternal = this.AdvancedRowHeadersBorderStyle.Right;
 639                                 }
 640                                 else
 641                                 {
 642                                     dgvabs.LeftInternal = this.AdvancedRowHeadersBorderStyle.Left;
 643                                     dgvabs.RightInternal = this.AdvancedColumnHeadersBorderStyle.Right;
 644                                 }
 645                                 dgvabs.TopInternal = this.AdvancedColumnHeadersBorderStyle.Top;
 646                                 dgvabs.BottomInternal = this.AdvancedColumnHeadersBorderStyle.Bottom;
 647                             }
 648                             else
 649                             {
 650                                 dgvabs = this.AdvancedColumnHeadersBorderStyle;
 651                             }
 652                             break;
 653  
 654                         default:
 655                             dgvabs = this.AdvancedColumnHeadersBorderStyle;
 656                             break;
 657                     }
 658                 }
 659                 return dgvabs;
 660             }
 661         }
 662  
 663         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.AdvancedCellBorderStyle"]/*‘ />
 664         [
 665             Browsable(false),
 666             EditorBrowsable(EditorBrowsableState.Advanced)
 667         ]
 668         public DataGridViewAdvancedBorderStyle AdvancedCellBorderStyle
 669         {
 670             get 
 671             {
 672                 return this.advancedCellBorderStyle;
 673             }
 674         }
 675  
 676         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.AdvancedColumnHeadersBorderStyle"]/*‘ />
 677         [
 678             Browsable(false),
 679             EditorBrowsable(EditorBrowsableState.Advanced)
 680         ]
 681         public DataGridViewAdvancedBorderStyle AdvancedColumnHeadersBorderStyle
 682         {
 683             get
 684             {
 685                 return this.advancedColumnHeadersBorderStyle;
 686             }
 687         }
 688  
 689         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.AdvancedRowHeadersBorderStyle"]/*‘ />
 690         [
 691             Browsable(false),
 692             EditorBrowsable(EditorBrowsableState.Advanced)
 693         ]
 694         public DataGridViewAdvancedBorderStyle AdvancedRowHeadersBorderStyle
 695         {
 696             get
 697             {
 698                 return this.advancedRowHeadersBorderStyle;
 699             }
 700         }
 701  
 702         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.AllowUserToAddRows"]/*‘ />
 703         [
 704             DefaultValue(true),
 705             SRCategory(SR.CatBehavior),
 706             SRDescription(SR.DataGridView_AllowUserToAddRowsDescr)
 707         ]
 708         public bool AllowUserToAddRows
 709         {
 710             get
 711             {
 712                 return this.dataGridViewState1[DATAGRIDVIEWSTATE1_allowUserToAddRows];
 713             }
 714             set
 715             {
 716                 if (this.AllowUserToAddRows != value)
 717                 {
 718                     this.dataGridViewState1[DATAGRIDVIEWSTATE1_allowUserToAddRows] = value;
 719                     if (this.DataSource != null)
 720                     {
 721                         this.dataConnection.ResetCachedAllowUserToAddRowsInternal();
 722                     }
 723                     OnAllowUserToAddRowsChanged(EventArgs.Empty);
 724                 }
 725             }
 726         }
 727  
 728         internal bool AllowUserToAddRowsInternal
 729         {
 730             get
 731             {
 732                 if (this.DataSource == null)
 733                 {
 734                     return this.AllowUserToAddRows;
 735                 }
 736                 else
 737                 {
 738                     return this.AllowUserToAddRows && this.dataConnection.AllowAdd;
 739                 }
 740             }
 741         }
 742  
 743         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.AllowUserToAddRowsChanged"]/*‘ />
 744         [
 745             SRCategory(SR.CatPropertyChanged), 
 746             SRDescription(SR.DataGridViewOnAllowUserToAddRowsChangedDescr)
 747         ]
 748         public event EventHandler AllowUserToAddRowsChanged
 749         {
 750             add
 751             {
 752                 this.Events.AddHandler(EVENT_DATAGRIDVIEWALLOWUSERTOADDROWSCHANGED, value);
 753             }
 754             remove
 755             {
 756                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWALLOWUSERTOADDROWSCHANGED, value);
 757             }
 758         }
 759  
 760         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.AllowUserToDeleteRows"]/*‘ />
 761         [
 762             DefaultValue(true),
 763             SRCategory(SR.CatBehavior),
 764             SRDescription(SR.DataGridView_AllowUserToDeleteRowsDescr)
 765         ]
 766         public bool AllowUserToDeleteRows
 767         {
 768             get
 769             {
 770                 return this.dataGridViewState1[DATAGRIDVIEWSTATE1_allowUserToDeleteRows];
 771             }
 772             set
 773             {
 774                 if (this.AllowUserToDeleteRows != value)
 775                 {
 776                     this.dataGridViewState1[DATAGRIDVIEWSTATE1_allowUserToDeleteRows] = value;
 777                     OnAllowUserToDeleteRowsChanged(EventArgs.Empty);
 778                 }
 779             }
 780         }
 781  
 782         internal bool AllowUserToDeleteRowsInternal
 783         {
 784             get
 785             {
 786                 if (this.DataSource == null)
 787                 {
 788                     return this.AllowUserToDeleteRows;
 789                 }
 790                 else
 791                 {
 792                     return this.AllowUserToDeleteRows && this.dataConnection.AllowRemove;
 793                 }
 794             }
 795         }
 796  
 797         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.AllowUserToDeleteRowsChanged"]/*‘ />
 798         [
 799             SRCategory(SR.CatPropertyChanged), 
 800             SRDescription(SR.DataGridViewOnAllowUserToDeleteRowsChangedDescr)
 801         ]
 802         public event EventHandler AllowUserToDeleteRowsChanged
 803         {
 804             add
 805             {
 806                 this.Events.AddHandler(EVENT_DATAGRIDVIEWALLOWUSERTODELETEROWSCHANGED, value);
 807             }
 808             remove
 809             {
 810                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWALLOWUSERTODELETEROWSCHANGED, value);
 811             }
 812         }
 813  
 814         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.AllowUserToOrderColumns"]/*‘ />
 815         [
 816             DefaultValue(false),
 817             SRCategory(SR.CatBehavior),
 818             SRDescription(SR.DataGridView_AllowUserToOrderColumnsDescr)
 819         ]
 820         public bool AllowUserToOrderColumns
 821         {
 822             get
 823             {
 824                 return this.dataGridViewState1[DATAGRIDVIEWSTATE1_allowUserToOrderColumns];
 825             }
 826             set
 827             {
 828                 if (this.AllowUserToOrderColumns != value)
 829                 {
 830                     this.dataGridViewState1[DATAGRIDVIEWSTATE1_allowUserToOrderColumns] = value;
 831                     OnAllowUserToOrderColumnsChanged(EventArgs.Empty);
 832                 }
 833             }
 834         }
 835  
 836         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.AllowUserToOrderColumnsChanged"]/*‘ />
 837         [
 838             SRCategory(SR.CatPropertyChanged), 
 839             SRDescription(SR.DataGridViewOnAllowUserToOrderColumnsChangedDescr)
 840         ]
 841         public event EventHandler AllowUserToOrderColumnsChanged
 842         {
 843             add
 844             {
 845                 this.Events.AddHandler(EVENT_DATAGRIDVIEWALLOWUSERTOORDERCOLUMNSCHANGED, value);
 846             }
 847             remove
 848             {
 849                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWALLOWUSERTOORDERCOLUMNSCHANGED, value);
 850             }
 851         }
 852  
 853         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.AllowUserToResizeColumns"]/*‘ />
 854         /// <devdoc>
 855         ///    <para>
 856         ///       Gets or sets a global value indicating if the dataGridView‘s columns are resizable with the mouse.
 857         ///       The resizable aspect of a column can be overridden by DataGridViewColumn.Resizable.
 858         ///    </para>
 859         /// </devdoc>
 860         [
 861             DefaultValue(true),
 862             SRCategory(SR.CatBehavior),
 863             SRDescription(SR.DataGridView_AllowUserToResizeColumnsDescr)
 864         ]
 865         public bool AllowUserToResizeColumns
 866         {
 867             get
 868             {
 869                 return this.dataGridViewState2[DATAGRIDVIEWSTATE2_allowUserToResizeColumns];
 870             }
 871             set
 872             {
 873                 if (this.AllowUserToResizeColumns != value)
 874                 {
 875                     this.dataGridViewState2[DATAGRIDVIEWSTATE2_allowUserToResizeColumns] = value;
 876                     OnAllowUserToResizeColumnsChanged(EventArgs.Empty);
 877                 }
 878             }
 879         }
 880  
 881         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.AllowUserToResizeColumnsChanged"]/*‘ />
 882         [
 883             SRCategory(SR.CatPropertyChanged), 
 884             SRDescription(SR.DataGridViewOnAllowUserToResizeColumnsChangedDescr)
 885         ]
 886         public event EventHandler AllowUserToResizeColumnsChanged
 887         {
 888             add
 889             {
 890                 this.Events.AddHandler(EVENT_DATAGRIDVIEWALLOWUSERTORESIZECOLUMNSCHANGED, value);
 891             }
 892             remove
 893             {
 894                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWALLOWUSERTORESIZECOLUMNSCHANGED, value);
 895             }
 896         }
 897  
 898         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.AllowUserToResizeRows"]/*‘ />
 899         /// <devdoc>
 900         ///    <para>
 901         ///       Gets or sets a global value indicating if the dataGridView‘s rows are resizable with the mouse.
 902         ///       The resizable aspect of a row can be overridden by DataGridViewRow.Resizable.
 903         ///    </para>
 904         /// </devdoc>
 905         [
 906             DefaultValue(true),
 907             SRCategory(SR.CatBehavior),
 908             SRDescription(SR.DataGridView_AllowUserToResizeRowsDescr)
 909         ]
 910         public bool AllowUserToResizeRows
 911         {
 912             get
 913             {
 914                 return this.dataGridViewState2[DATAGRIDVIEWSTATE2_allowUserToResizeRows];
 915             }
 916             set
 917             {
 918                 if (this.AllowUserToResizeRows != value)
 919                 {
 920                     this.dataGridViewState2[DATAGRIDVIEWSTATE2_allowUserToResizeRows] = value;
 921                     OnAllowUserToResizeRowsChanged(EventArgs.Empty);
 922                 }
 923             }
 924         }
 925  
 926         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.AllowUserToResizeRowsChanged"]/*‘ />
 927         [
 928             SRCategory(SR.CatPropertyChanged), 
 929             SRDescription(SR.DataGridViewOnAllowUserToResizeRowsChangedDescr)
 930         ]
 931         public event EventHandler AllowUserToResizeRowsChanged
 932         {
 933             add
 934             {
 935                 this.Events.AddHandler(EVENT_DATAGRIDVIEWALLOWUSERTORESIZEROWSCHANGED, value);
 936             }
 937             remove
 938             {
 939                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWALLOWUSERTORESIZEROWSCHANGED, value);
 940             }
 941         }
 942  
 943         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.AlternatingRowsDefaultCellStyle"]/*‘ />        
 944         [
 945             SRCategory(SR.CatAppearance),
 946             SRDescription(SR.DataGridView_AlternatingRowsDefaultCellStyleDescr)
 947         ]
 948         public DataGridViewCellStyle AlternatingRowsDefaultCellStyle
 949         {
 950             get
 951             {
 952                 if (this.alternatingRowsDefaultCellStyle == null)
 953                 {
 954                     this.alternatingRowsDefaultCellStyle = new DataGridViewCellStyle();
 955                     this.alternatingRowsDefaultCellStyle.AddScope(this, DataGridViewCellStyleScopes.AlternatingRows);
 956                 }
 957                 return this.alternatingRowsDefaultCellStyle;
 958             }
 959             set
 960             {
 961                 DataGridViewCellStyle cs = this.AlternatingRowsDefaultCellStyle;
 962                 cs.RemoveScope(DataGridViewCellStyleScopes.AlternatingRows);
 963                 this.alternatingRowsDefaultCellStyle = value;
 964                 if (value != null)
 965                 {
 966                     this.alternatingRowsDefaultCellStyle.AddScope(this, DataGridViewCellStyleScopes.AlternatingRows);
 967                 }
 968                 DataGridViewCellStyleDifferences dgvcsc = cs.GetDifferencesFrom(this.AlternatingRowsDefaultCellStyle);
 969                 if (dgvcsc != DataGridViewCellStyleDifferences.None)
 970                 {
 971                     this.CellStyleChangedEventArgs.ChangeAffectsPreferredSize = (dgvcsc == DataGridViewCellStyleDifferences.AffectPreferredSize);
 972                     OnAlternatingRowsDefaultCellStyleChanged(this.CellStyleChangedEventArgs);
 973                 }
 974             }
 975         }
 976  
 977         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.AlternatingRowsDefaultCellStyleChanged"]/*‘ />
 978         [
 979             SRCategory(SR.CatPropertyChanged), 
 980             SRDescription(SR.DataGridViewAlternatingRowsDefaultCellStyleChangedDescr)
 981         ]
 982         public event EventHandler AlternatingRowsDefaultCellStyleChanged
 983         {
 984             add
 985             {
 986                 this.Events.AddHandler(EVENT_DATAGRIDVIEWALTERNATINGROWSDEFAULTCELLSTYLECHANGED, value);
 987             }
 988             remove
 989             {
 990                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWALTERNATINGROWSDEFAULTCELLSTYLECHANGED, value);
 991             }
 992         }
 993  
 994         internal bool ApplyVisualStylesToInnerCells
 995         {
 996             get
 997             {
 998                 return Application.RenderWithVisualStyles;
 999             }
1000         }
1001  
1002         internal bool ApplyVisualStylesToHeaderCells
1003         {
1004             get
1005             {
1006                 return Application.RenderWithVisualStyles && this.EnableHeadersVisualStyles;
1007             }
1008         }
1009  
1010         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.AutoGenerateColumns"]/*‘ />
1011         /// <devdoc>
1012         ///    <para>
1013         ///    </para>
1014         /// </devdoc>
1015         [
1016             Browsable(false),
1017             EditorBrowsable(EditorBrowsableState.Advanced),
1018             DefaultValue(true)
1019         ]
1020         public bool AutoGenerateColumns
1021         {
1022             get
1023             {
1024                 return this.dataGridViewState1[DATAGRIDVIEWSTATE1_autoGenerateColumns];
1025             }
1026             set{
1027                 if (this.dataGridViewState1[DATAGRIDVIEWSTATE1_autoGenerateColumns] != value)
1028                 {
1029                     this.dataGridViewState1[DATAGRIDVIEWSTATE1_autoGenerateColumns] = value;
1030                     OnAutoGenerateColumnsChanged(EventArgs.Empty);
1031                 }
1032             }
1033         }
1034  
1035         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.AutoGenerateColumnsChanged"]/*‘ />
1036         [
1037             Browsable(false),
1038             EditorBrowsable(EditorBrowsableState.Advanced)
1039         ]
1040         public event EventHandler AutoGenerateColumnsChanged
1041         {
1042             add
1043             {
1044                 this.Events.AddHandler(EVENT_DATAGRIDVIEWAUTOGENERATECOLUMNSCHANGED, value);
1045             }
1046             remove
1047             {
1048                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWAUTOGENERATECOLUMNSCHANGED, value);
1049             }
1050         }
1051  
1052         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.AutoSize"]/*‘ />
1053         /// <devdoc>
1054         ///    <para> Overriding base implementation for perf gains. </para>
1055         /// </devdoc>
1056         public override bool AutoSize
1057         {
1058             get
1059             {
1060                 return this.dataGridViewState1[DATAGRIDVIEWSTATE1_isAutoSized];
1061             }
1062             set
1063             {
1064                 base.AutoSize = value;
1065                 this.dataGridViewState1[DATAGRIDVIEWSTATE1_isAutoSized] = value;
1066             }
1067         }
1068  
1069         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.AutoSizeColumnsMode"]/*‘ />
1070         /// <devdoc>
1071         ///    <para> Gets or sets the columns‘ autosizing mode. Standard inheritance model is used:
1072         ///           Columns with AutoSizeMode property set to NotSet will use this auto size mode.
1073         ///    </para>
1074         /// </devdoc>
1075         [
1076             DefaultValue(DataGridViewAutoSizeColumnsMode.None),
1077             SRCategory(SR.CatLayout),
1078             SRDescription(SR.DataGridView_AutoSizeColumnsModeDescr)
1079         ]
1080         public DataGridViewAutoSizeColumnsMode AutoSizeColumnsMode
1081         {
1082             get
1083             {
1084                 return this.autoSizeColumnsMode;
1085             }
1086         
1087             set
1088             {
1089                 switch (value) 
1090                 { 
1091                     case DataGridViewAutoSizeColumnsMode.None:
1092                     case DataGridViewAutoSizeColumnsMode.ColumnHeader:
1093                     case DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader:
1094                     case DataGridViewAutoSizeColumnsMode.AllCells:
1095                     case DataGridViewAutoSizeColumnsMode.DisplayedCellsExceptHeader:
1096                     case DataGridViewAutoSizeColumnsMode.DisplayedCells:
1097                     case DataGridViewAutoSizeColumnsMode.Fill:
1098                         break;
1099                     default: 
1100                         throw new InvalidEnumArgumentException("value", (int)value, typeof(DataGridViewAutoSizeColumnsMode)); 
1101                  }
1102  
1103  
1104                 if (this.autoSizeColumnsMode != value)
1105                 {
1106                     foreach (DataGridViewColumn dataGridViewColumn in this.Columns)
1107                     {
1108                         if (dataGridViewColumn.AutoSizeMode == DataGridViewAutoSizeColumnMode.NotSet && dataGridViewColumn.Visible)
1109                         {
1110                             // Make sure there is no visible column which would have an inherited autosize mode based on the header only.
1111                             if (value == DataGridViewAutoSizeColumnsMode.ColumnHeader && !this.ColumnHeadersVisible)
1112                             {
1113                                 throw new InvalidOperationException(SR.GetString(SR.DataGridView_CannotAutoSizeColumnsInvisibleColumnHeaders));
1114                             }
1115                             // Make sure there is no visible frozen column which would have a Fill inherited autosize mode.
1116                             if (value == DataGridViewAutoSizeColumnsMode.Fill && dataGridViewColumn.Frozen)
1117                             {
1118                                 throw new InvalidOperationException(SR.GetString(SR.DataGridView_CannotAutoFillFrozenColumns));
1119                             }
1120                         }
1121                     }
1122                     DataGridViewAutoSizeColumnMode[] previousModes = new DataGridViewAutoSizeColumnMode[this.Columns.Count];
1123                     foreach (DataGridViewColumn dataGridViewColumn in this.Columns)
1124                     {
1125                         /*DataGridViewAutoSizeColumnMode previousInheritedMode = dataGridViewColumn.InheritedAutoSizeMode;
1126                         bool previousInheritedModeAutoSized = previousInheritedMode != DataGridViewAutoSizeColumnMode.Fill &&
1127                                                               previousInheritedMode != DataGridViewAutoSizeColumnMode.None &&
1128                                                               previousInheritedMode != DataGridViewAutoSizeColumnMode.NotSet;*/
1129                         previousModes[dataGridViewColumn.Index] = dataGridViewColumn.InheritedAutoSizeMode;
1130                     }
1131                     DataGridViewAutoSizeColumnsModeEventArgs dgvcasme = new DataGridViewAutoSizeColumnsModeEventArgs(previousModes);
1132                     this.autoSizeColumnsMode = value;
1133                     OnAutoSizeColumnsModeChanged(dgvcasme);
1134                 }
1135             }
1136         }
1137  
1138         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.AutoSizeColumnsModeChanged"]/*‘ />
1139         [
1140             SRCategory(SR.CatPropertyChanged), 
1141             SRDescription(SR.DataGridViewAutoSizeColumnsModeChangedDescr)
1142         ]
1143         public event DataGridViewAutoSizeColumnsModeEventHandler AutoSizeColumnsModeChanged
1144         {
1145             add
1146             {
1147                 this.Events.AddHandler(EVENT_DATAGRIDVIEWAUTOSIZECOLUMNSMODECHANGED, value);
1148             }
1149             remove
1150             {
1151                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWAUTOSIZECOLUMNSMODECHANGED, value);
1152             }
1153         }
1154  
1155         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.AutoSizeRowsMode"]/*‘ />
1156         /// <devdoc>
1157         ///    <para> Gets or sets the rows‘ autosizing mode. </para>
1158         /// </devdoc>
1159         [
1160             DefaultValue(DataGridViewAutoSizeRowsMode.None),
1161             SRCategory(SR.CatLayout),
1162             SRDescription(SR.DataGridView_AutoSizeRowsModeDescr)
1163         ]
1164         public DataGridViewAutoSizeRowsMode AutoSizeRowsMode
1165         {
1166             get
1167             {
1168                 return this.autoSizeRowsMode;
1169             }
1170             set
1171             {
1172                 switch (value) 
1173                 { 
1174                    case DataGridViewAutoSizeRowsMode.None:
1175                    case DataGridViewAutoSizeRowsMode.AllHeaders:
1176                    case DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders:
1177                    case DataGridViewAutoSizeRowsMode.AllCells:
1178                    case DataGridViewAutoSizeRowsMode.DisplayedHeaders:
1179                    case DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders:
1180                    case DataGridViewAutoSizeRowsMode.DisplayedCells:
1181                        break;
1182                    default: 
1183                        throw new InvalidEnumArgumentException("value", (int)value, typeof(DataGridViewAutoSizeRowsMode)); 
1184                 }
1185                 if ((value == DataGridViewAutoSizeRowsMode.AllHeaders || value == DataGridViewAutoSizeRowsMode.DisplayedHeaders) && 
1186                     !this.RowHeadersVisible)
1187                 {
1188                     throw new InvalidOperationException(SR.GetString(SR.DataGridView_CannotAutoSizeRowsInvisibleRowHeader));
1189                 }
1190                 if (this.autoSizeRowsMode != value)
1191                 {
1192                     DataGridViewAutoSizeModeEventArgs dgvasme = new DataGridViewAutoSizeModeEventArgs(this.autoSizeRowsMode != DataGridViewAutoSizeRowsMode.None);
1193                     this.autoSizeRowsMode = value;
1194                     OnAutoSizeRowsModeChanged(dgvasme);
1195                 }
1196             }
1197         }
1198  
1199         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.AutoSizeRowsModeChanged"]/*‘ />
1200         [
1201             SRCategory(SR.CatPropertyChanged), 
1202             SRDescription(SR.DataGridViewAutoSizeRowsModeChangedDescr)
1203         ]
1204         public event DataGridViewAutoSizeModeEventHandler AutoSizeRowsModeChanged
1205         {
1206             add 
1207             {
1208                 this.Events.AddHandler(EVENT_DATAGRIDVIEWAUTOSIZEROWSMODECHANGED, value);
1209             }
1210             remove 
1211             {
1212                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWAUTOSIZEROWSMODECHANGED, value);
1213             }
1214         }
1215         
1216         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.BackColor"]/*‘ />
1217         /// <internalonly/>
1218         [
1219             Browsable(false), 
1220             EditorBrowsable(EditorBrowsableState.Never),
1221             DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
1222         ]
1223         public override Color BackColor
1224         {
1225             get 
1226             {
1227                 return base.BackColor;
1228             }
1229             set 
1230             {
1231                 base.BackColor = value;
1232             }
1233         }
1234  
1235         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.BackColorChanged"]/*‘ />
1236         /// <internalonly/>
1237         [
1238             Browsable(false),
1239             EditorBrowsable(EditorBrowsableState.Never)
1240         ]
1241         new public event EventHandler BackColorChanged
1242         {
1243             add
1244             {
1245                 base.BackColorChanged += value;
1246             }
1247             remove
1248             {
1249                 base.BackColorChanged -= value;
1250             }
1251         }
1252  
1253         internal SolidBrush BackgroundBrush 
1254         {
1255             get 
1256             {
1257                 return this.backgroundBrush;
1258             }
1259         }
1260  
1261         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.BackgroundColor"]/*‘ />
1262         /// <devdoc>
1263         ///    <para>Gets or sets the background color of the dataGridView.</para>
1264         /// </devdoc>
1265         [
1266             SRCategory(SR.CatAppearance),
1267             SRDescription(SR.DataGridViewBackgroundColorDescr)
1268         ]
1269         public Color BackgroundColor
1270         {
1271             get
1272             {
1273                 return this.backgroundBrush.Color;
1274             }
1275             set
1276             {
1277                 if (value.IsEmpty)
1278                 {
1279                     throw new ArgumentException(SR.GetString(SR.DataGridView_EmptyColor, "BackgroundColor"));
1280                 }
1281                 if (value.A < 255)
1282                 {
1283                     throw new ArgumentException(SR.GetString(SR.DataGridView_TransparentColor, "BackgroundColor"));
1284                 }
1285                 if (!value.Equals(this.backgroundBrush.Color)) 
1286                 {
1287                     this.backgroundBrush = new SolidBrush(value);
1288                     OnBackgroundColorChanged(EventArgs.Empty);
1289                 }
1290             }
1291         }
1292  
1293         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.BackgroundColorChanged"]/*‘ />
1294         [
1295             SRCategory(SR.CatPropertyChanged), 
1296             SRDescription(SR.DataGridViewBackgroundColorChangedDescr)
1297         ]
1298         public event EventHandler BackgroundColorChanged 
1299         {
1300             add 
1301             {
1302                 this.Events.AddHandler(EVENT_DATAGRIDVIEWBACKGROUNDCOLORCHANGED, value);
1303             }
1304             remove 
1305             {
1306                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWBACKGROUNDCOLORCHANGED, value);
1307             }
1308         }
1309  
1310         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.BackgroundImage"]/*‘ />
1311         [
1312             Browsable(false),
1313             EditorBrowsable(EditorBrowsableState.Never)
1314         ]
1315         public override Image BackgroundImage
1316         {
1317             get
1318             {
1319                 return base.BackgroundImage;
1320             }
1321             set
1322             {
1323                 base.BackgroundImage = value;
1324             }
1325         }
1326  
1327         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.BackgroundImageLayout"]/*‘ />
1328         [
1329             Browsable(false),
1330             EditorBrowsable(EditorBrowsableState.Never)
1331         ]
1332         public override ImageLayout BackgroundImageLayout
1333         {
1334             get
1335             {
1336                 return base.BackgroundImageLayout;
1337             }
1338             set
1339             {
1340                 base.BackgroundImageLayout = value;
1341             }
1342         }
1343  
1344         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.BackgroundImageChanged"]/*‘ />
1345         [
1346             Browsable(false),
1347             EditorBrowsable(EditorBrowsableState.Never)
1348         ]
1349         new public event EventHandler BackgroundImageChanged
1350         {
1351             add
1352             {
1353                 base.BackgroundImageChanged += value;
1354             }
1355             remove
1356             {
1357                 base.BackgroundImageChanged -= value;
1358             }
1359         }
1360  
1361         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.BackgroundImageLayoutChanged"]/*‘ />
1362         [
1363             Browsable(false),
1364             EditorBrowsable(EditorBrowsableState.Never)
1365         ]
1366         new public event EventHandler BackgroundImageLayoutChanged
1367         {
1368             add
1369             {
1370                 base.BackgroundImageLayoutChanged += value;
1371             }
1372             remove
1373             {
1374                 base.BackgroundImageLayoutChanged -= value;
1375             }
1376         }
1377  
1378         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ShouldSerializeBackgroundColor"]/*‘ />
1379         private bool ShouldSerializeBackgroundColor()
1380         {
1381             return !this.BackgroundColor.Equals(DefaultBackgroundBrush.Color);
1382         }
1383  
1384         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.BorderStyle"]/*‘ />
1385         [
1386             DefaultValue(BorderStyle.FixedSingle),
1387             SRCategory(SR.CatAppearance),
1388             SRDescription(SR.DataGridView_BorderStyleDescr)
1389         ]
1390         public BorderStyle BorderStyle
1391         {
1392             get 
1393             {
1394                 return this.borderStyle;
1395             }
1396             set 
1397             {
1398                 // Sequential enum.  Valid values are 0x0 to 0x2
1399                 if (!ClientUtils.IsEnumValid(value, (int)value, (int)BorderStyle.None, (int)BorderStyle.Fixed3D)){
1400                     throw new InvalidEnumArgumentException("value", (int)value, typeof(BorderStyle)); 
1401                 }
1402                 if (this.borderStyle != value) 
1403                 {
1404                     using (LayoutTransaction.CreateTransactionIf(this.AutoSize, this.ParentInternal, this, PropertyNames.BorderStyle))
1405                     {
1406                         this.borderStyle = value;
1407                         if (!this.AutoSize)
1408                         {
1409                             PerformLayoutPrivate(false /*useRowShortcut*/, false /*computeVisibleRows*/, true /*invalidInAdjustFillingColumns*/, true /*repositionEditingControl*/);
1410                         }
1411                         Invalidate();
1412                         OnBorderStyleChanged(EventArgs.Empty);
1413                     }
1414                 }
1415             }
1416         }
1417  
1418         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.BorderStyleChanged"]/*‘ />
1419         [
1420             SRCategory(SR.CatPropertyChanged), 
1421             SRDescription(SR.DataGridViewBorderStyleChangedDescr)
1422         ]
1423         public event EventHandler BorderStyleChanged
1424         {
1425             add
1426             {
1427                 this.Events.AddHandler(EVENT_DATAGRIDVIEWBORDERSTYLECHANGED, value);
1428             }
1429             remove
1430             {
1431                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWBORDERSTYLECHANGED, value);
1432             }
1433         }
1434  
1435         private int BorderWidth 
1436         {
1437             get 
1438             {
1439                 if (this.BorderStyle == BorderStyle.Fixed3D) 
1440                 {
1441                     return Application.RenderWithVisualStyles ? 1 : SystemInformation.Border3DSize.Width;
1442                 }
1443                 else if (this.BorderStyle == BorderStyle.FixedSingle) 
1444                 {
1445                     return 1;
1446                 }
1447                 else 
1448                 {
1449                     return 0;
1450                 }
1451             }
1452         }
1453  
1454         // Ime can be shown when there is a read-write current cell.
1455         protected override bool CanEnableIme
1456         {
1457             get
1458             {
1459                 bool canEnable = false;
1460  
1461                 Debug.WriteLineIf( CompModSwitches.ImeMode.Level >= TraceLevel.Info, "Inside get_CanEnableIme(), this = " + this );
1462                 Debug.Indent();
1463  
1464                 if (this.ptCurrentCell.X != -1 /*&& !this.IsCurrentCellInEditMode*/ && ColumnEditable(this.ptCurrentCell.X))
1465                 {
1466                     DataGridViewCell dataGridViewCell = this.CurrentCellInternal;
1467                     Debug.Assert(dataGridViewCell != null);
1468  
1469                     if (!IsSharedCellReadOnly(dataGridViewCell, this.ptCurrentCell.Y))
1470                     {
1471                         canEnable = base.CanEnableIme;
1472                     }
1473                 }
1474  
1475                 Debug.WriteLineIf( CompModSwitches.ImeMode.Level >= TraceLevel.Info, "Value = " + canEnable );
1476                 Debug.Unindent();
1477  
1478                 return canEnable;
1479             }
1480         }
1481  
1482         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.AdvancedCellBorderStyle"]/*‘ />
1483         [
1484             SRCategory(SR.CatAppearance),
1485             SRDescription(SR.DataGridView_CellBorderStyleDescr),
1486             Browsable(true),
1487             DefaultValue(DataGridViewCellBorderStyle.Single)
1488         ]
1489         public DataGridViewCellBorderStyle CellBorderStyle
1490         {
1491             get 
1492             {
1493                 switch (this.advancedCellBorderStyle.All)
1494                 {
1495                     case DataGridViewAdvancedCellBorderStyle.NotSet:
1496                         if (this.advancedCellBorderStyle.Top == DataGridViewAdvancedCellBorderStyle.None &&
1497                             this.advancedCellBorderStyle.Bottom == DataGridViewAdvancedCellBorderStyle.None)
1498                         {
1499                             if (this.RightToLeftInternal)
1500                             {
1501                                 if (this.advancedCellBorderStyle.Right == DataGridViewAdvancedCellBorderStyle.None &&
1502                                     this.advancedCellBorderStyle.Left == DataGridViewAdvancedCellBorderStyle.Single)
1503                                 {
1504                                     return DataGridViewCellBorderStyle.SingleVertical;
1505                                 }
1506                             }
1507                             else
1508                             {
1509                                 if (this.advancedCellBorderStyle.Left == DataGridViewAdvancedCellBorderStyle.None &&
1510                                     this.advancedCellBorderStyle.Right == DataGridViewAdvancedCellBorderStyle.Single)
1511                                 {
1512                                     return DataGridViewCellBorderStyle.SingleVertical;
1513                                 }
1514                             }
1515                             if (this.advancedCellBorderStyle.Right == DataGridViewAdvancedCellBorderStyle.Outset && 
1516                                 this.advancedCellBorderStyle.Left == DataGridViewAdvancedCellBorderStyle.Outset)
1517                             {
1518                                 return DataGridViewCellBorderStyle.RaisedVertical;
1519                             }
1520                             if (this.advancedCellBorderStyle.Right == DataGridViewAdvancedCellBorderStyle.Inset && 
1521                                 this.advancedCellBorderStyle.Left == DataGridViewAdvancedCellBorderStyle.Inset)
1522                             {
1523                                 return DataGridViewCellBorderStyle.SunkenVertical;
1524                             }
1525                         }
1526                         if (this.advancedCellBorderStyle.Left == DataGridViewAdvancedCellBorderStyle.None &&
1527                             this.advancedCellBorderStyle.Right == DataGridViewAdvancedCellBorderStyle.None)
1528                         {
1529                             if (this.advancedCellBorderStyle.Top == DataGridViewAdvancedCellBorderStyle.None &&
1530                                 this.advancedCellBorderStyle.Bottom == DataGridViewAdvancedCellBorderStyle.Single)
1531                             {
1532                                 return DataGridViewCellBorderStyle.SingleHorizontal;
1533                             }
1534                             if (this.advancedCellBorderStyle.Top == DataGridViewAdvancedCellBorderStyle.Outset && 
1535                                 this.advancedCellBorderStyle.Bottom == DataGridViewAdvancedCellBorderStyle.Outset)
1536                             {
1537                                 return DataGridViewCellBorderStyle.RaisedHorizontal;
1538                             }
1539                             if (this.advancedCellBorderStyle.Top == DataGridViewAdvancedCellBorderStyle.Inset && 
1540                                 this.advancedCellBorderStyle.Bottom == DataGridViewAdvancedCellBorderStyle.Inset)
1541                             {
1542                                 return DataGridViewCellBorderStyle.SunkenHorizontal;
1543                             }
1544                         }
1545                         return DataGridViewCellBorderStyle.Custom;
1546  
1547                     case DataGridViewAdvancedCellBorderStyle.None:
1548                         return DataGridViewCellBorderStyle.None;
1549  
1550                     case DataGridViewAdvancedCellBorderStyle.Single:
1551                         return DataGridViewCellBorderStyle.Single;
1552  
1553                     case DataGridViewAdvancedCellBorderStyle.Inset:
1554                         return DataGridViewCellBorderStyle.Sunken;
1555  
1556                     case DataGridViewAdvancedCellBorderStyle.Outset:
1557                         return DataGridViewCellBorderStyle.Raised;
1558  
1559                     default:
1560                         Debug.Fail("Unexpected this.advancedCellBorderStyle.All value in CellBorderStyle.get");
1561                         return DataGridViewCellBorderStyle.Custom;
1562                 }
1563             }
1564             set
1565             {
1566                 // Sequential enum.  Valid values are 0x0 to 0xa
1567                 if (!ClientUtils.IsEnumValid(value, (int)value, (int)DataGridViewCellBorderStyle.Custom, (int)DataGridViewCellBorderStyle.SunkenHorizontal))
1568                 {
1569                      throw new InvalidEnumArgumentException("value", (int)value, typeof(DataGridViewCellBorderStyle)); 
1570                 }
1571  
1572                 if (value != this.CellBorderStyle)
1573                 {
1574                     if (value == DataGridViewCellBorderStyle.Custom)
1575                     {
1576                         throw new ArgumentException(SR.GetString(SR.DataGridView_CustomCellBorderStyleInvalid, "CellBorderStyle"));
1577                     }
1578                     this.dataGridViewOper[DATAGRIDVIEWOPER_inBorderStyleChange] = true;
1579                     try
1580                     {
1581                         switch (value)
1582                         {
1583                             case DataGridViewCellBorderStyle.Single:
1584                                 this.advancedCellBorderStyle.All = DataGridViewAdvancedCellBorderStyle.Single;
1585                                 break;
1586  
1587                             case DataGridViewCellBorderStyle.Raised:
1588                                 this.advancedCellBorderStyle.All = DataGridViewAdvancedCellBorderStyle.Outset;
1589                                 break;
1590  
1591                             case DataGridViewCellBorderStyle.Sunken:
1592                                 this.advancedCellBorderStyle.All = DataGridViewAdvancedCellBorderStyle.Inset;
1593                                 break;
1594  
1595                             case DataGridViewCellBorderStyle.None:
1596                                 this.advancedCellBorderStyle.All = DataGridViewAdvancedCellBorderStyle.None;
1597                                 break;
1598  
1599                             case DataGridViewCellBorderStyle.SingleVertical:
1600                                 this.advancedCellBorderStyle.All = DataGridViewAdvancedCellBorderStyle.None;
1601                                 if (this.RightToLeftInternal)
1602                                 {
1603                                     this.advancedCellBorderStyle.LeftInternal = DataGridViewAdvancedCellBorderStyle.Single;
1604                                 }
1605                                 else
1606                                 {
1607                                     this.advancedCellBorderStyle.RightInternal = DataGridViewAdvancedCellBorderStyle.Single;
1608                                 }
1609                                 break;
1610  
1611                             case DataGridViewCellBorderStyle.RaisedVertical:
1612                                 this.advancedCellBorderStyle.All = DataGridViewAdvancedCellBorderStyle.None;
1613                                 this.advancedCellBorderStyle.RightInternal = DataGridViewAdvancedCellBorderStyle.Outset;
1614                                 this.advancedCellBorderStyle.LeftInternal = DataGridViewAdvancedCellBorderStyle.Outset;
1615                                 break;
1616  
1617                             case DataGridViewCellBorderStyle.SunkenVertical:
1618                                 this.advancedCellBorderStyle.All = DataGridViewAdvancedCellBorderStyle.None;
1619                                 this.advancedCellBorderStyle.RightInternal = DataGridViewAdvancedCellBorderStyle.Inset;
1620                                 this.advancedCellBorderStyle.LeftInternal = DataGridViewAdvancedCellBorderStyle.Inset;
1621                                 break;
1622  
1623                             case DataGridViewCellBorderStyle.SingleHorizontal:
1624                                 this.advancedCellBorderStyle.All = DataGridViewAdvancedCellBorderStyle.None;
1625                                 this.advancedCellBorderStyle.BottomInternal = DataGridViewAdvancedCellBorderStyle.Single;
1626                                 break;
1627  
1628                             case DataGridViewCellBorderStyle.RaisedHorizontal:
1629                                 this.advancedCellBorderStyle.All = DataGridViewAdvancedCellBorderStyle.None;
1630                                 this.advancedCellBorderStyle.TopInternal = DataGridViewAdvancedCellBorderStyle.Outset;
1631                                 this.advancedCellBorderStyle.BottomInternal = DataGridViewAdvancedCellBorderStyle.Outset;
1632                                 break;
1633  
1634                             case DataGridViewCellBorderStyle.SunkenHorizontal:
1635                                 this.advancedCellBorderStyle.All = DataGridViewAdvancedCellBorderStyle.None;
1636                                 this.advancedCellBorderStyle.TopInternal = DataGridViewAdvancedCellBorderStyle.Inset;
1637                                 this.advancedCellBorderStyle.BottomInternal = DataGridViewAdvancedCellBorderStyle.Inset;
1638                                 break;
1639                         }
1640                     }
1641                     finally
1642                     {
1643                         this.dataGridViewOper[DATAGRIDVIEWOPER_inBorderStyleChange] = false;
1644                     }
1645                     OnCellBorderStyleChanged(EventArgs.Empty);
1646                 }
1647             }
1648         }
1649  
1650         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellBorderStyleChanged"]/*‘ />
1651         [
1652             SRCategory(SR.CatPropertyChanged), 
1653             SRDescription(SR.DataGridView_CellBorderStyleChangedDescr)
1654         ]
1655         public event EventHandler CellBorderStyleChanged
1656         {
1657             add
1658             {
1659                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLBORDERSTYLECHANGED, value);
1660             }
1661             remove
1662             {
1663                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLBORDERSTYLECHANGED, value);
1664             }
1665         }
1666  
1667         internal bool CellMouseDownInContentBounds
1668         {
1669             get
1670             {
1671                 return this.dataGridViewState2[DATAGRIDVIEWSTATE2_cellMouseDownInContentBounds];
1672             }
1673             set
1674             {
1675                 this.dataGridViewState2[DATAGRIDVIEWSTATE2_cellMouseDownInContentBounds] = value;
1676             }
1677         }
1678  
1679         internal DataGridViewCellPaintingEventArgs CellPaintingEventArgs
1680         {
1681             get
1682             {
1683                 if (this.dgvcpe == null)
1684                 {
1685                     this.dgvcpe = new DataGridViewCellPaintingEventArgs(this);
1686                 }
1687                 return this.dgvcpe;
1688             }
1689         }
1690  
1691         private DataGridViewCellStyleChangedEventArgs CellStyleChangedEventArgs
1692         {
1693             get
1694             {
1695                 if (this.dgvcsce == null)
1696                 {
1697                     this.dgvcsce = new DataGridViewCellStyleChangedEventArgs();
1698                 }
1699                 return this.dgvcsce;
1700             }
1701         }        
1702  
1703         internal DataGridViewCellValueEventArgs CellValueEventArgs
1704         {
1705             get
1706             {
1707                 if (this.dgvcve == null)
1708                 {
1709                     this.dgvcve = new DataGridViewCellValueEventArgs();
1710                 }
1711                 return this.dgvcve;
1712             }
1713         }
1714  
1715         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ClipboardCopyMode"]/*‘ />
1716         [
1717             Browsable(true),
1718             DefaultValue(DataGridViewClipboardCopyMode.EnableWithAutoHeaderText),
1719             SRCategory(SR.CatBehavior),
1720             SRDescription(SR.DataGridView_ClipboardCopyModeDescr)
1721         ]
1722         public DataGridViewClipboardCopyMode ClipboardCopyMode
1723         {
1724             get
1725             {
1726                 return this.clipboardCopyMode;
1727             }
1728             set
1729             {
1730                 // Sequential enum.  Valid values are 0x0 to 0x3
1731                 if (!ClientUtils.IsEnumValid(value, (int)value, (int)DataGridViewClipboardCopyMode.Disable, (int)DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText))
1732                 {
1733                    throw new InvalidEnumArgumentException("value", (int)value, typeof(DataGridViewClipboardCopyMode)); 
1734                 }
1735                 this.clipboardCopyMode = value;
1736             }
1737         }
1738  
1739         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnCount"]/*‘ />
1740         [
1741             Browsable(false),
1742             DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
1743             DefaultValue(0),
1744             EditorBrowsable(EditorBrowsableState.Advanced)
1745         ]
1746         public int ColumnCount
1747         {
1748             get
1749             {
1750                 return this.Columns.Count;
1751             }
1752             set
1753             {
1754                 if (value < 0)
1755                 {
1756                     throw new ArgumentOutOfRangeException("ColumnCount", SR.GetString(SR.InvalidLowBoundArgumentEx, "ColumnCount", value.ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture)));
1757                 }
1758                 if (this.DataSource != null)
1759                 {
1760                     throw new InvalidOperationException(SR.GetString(SR.DataGridView_CannotSetColumnCountOnDataBoundDataGridView));
1761                 }
1762                 if (value != this.Columns.Count)
1763                 {
1764                     if (value == 0)
1765                     {
1766                         // Total removal of the columns. This also clears the rows.
1767                         this.Columns.Clear();
1768                     }
1769                     else if (value < this.Columns.Count)
1770                     {
1771                         // Some columns need to be removed, from the tail of the columns collection
1772                         while (value < this.Columns.Count)
1773                         {
1774                             int currentColumnCount = this.Columns.Count;
1775                             this.Columns.RemoveAt(currentColumnCount - 1);
1776                             if (this.Columns.Count >= currentColumnCount)
1777                             {
1778                                 // Column removal failed. We stop the loop.
1779                                 break;
1780                             }
1781                         }
1782                     }
1783                     else
1784                     {
1785                         // Some DataGridViewTextBoxColumn columns need to be appened.
1786                         while (value > this.Columns.Count)
1787                         {
1788                             int currentColumnCount = this.Columns.Count;
1789                             this.Columns.Add(null /*columnName*/, null /*headerText*/);
1790                             if (this.Columns.Count <= currentColumnCount)
1791                             {
1792                                 // Column addition failed. We stop the loop.
1793                                 break;
1794                             }
1795                         }
1796                     }
1797                 }
1798             }
1799         }
1800  
1801         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnHeadersBorderStyle"]/*‘ />
1802         [
1803             SRCategory(SR.CatAppearance),
1804             SRDescription(SR.DataGridView_ColumnHeadersBorderStyleDescr),
1805             Browsable(true),
1806             DefaultValue(DataGridViewHeaderBorderStyle.Raised)
1807         ]
1808         public DataGridViewHeaderBorderStyle ColumnHeadersBorderStyle
1809         {
1810             get 
1811             {
1812                 switch (this.advancedColumnHeadersBorderStyle.All)
1813                 {
1814                     case DataGridViewAdvancedCellBorderStyle.NotSet:
1815                         return DataGridViewHeaderBorderStyle.Custom;
1816  
1817                     case DataGridViewAdvancedCellBorderStyle.None:
1818                         return DataGridViewHeaderBorderStyle.None;
1819  
1820                     case DataGridViewAdvancedCellBorderStyle.Single:
1821                         return DataGridViewHeaderBorderStyle.Single;
1822  
1823                     case DataGridViewAdvancedCellBorderStyle.InsetDouble:
1824                         return DataGridViewHeaderBorderStyle.Sunken;
1825  
1826                     case DataGridViewAdvancedCellBorderStyle.OutsetPartial:
1827                         return DataGridViewHeaderBorderStyle.Raised;
1828  
1829                     default:
1830                         return DataGridViewHeaderBorderStyle.Custom;
1831                 }
1832             }
1833             set
1834             {
1835                 // Sequential enum.  Valid values are 0x0 to 0x4
1836                 if (!ClientUtils.IsEnumValid(value, (int)value, (int)DataGridViewHeaderBorderStyle.Custom, (int)DataGridViewHeaderBorderStyle.None))
1837                 {
1838                     throw new InvalidEnumArgumentException("value", (int)value, typeof(DataGridViewHeaderBorderStyle)); 
1839                 }
1840                 if (value != this.ColumnHeadersBorderStyle)
1841                 {
1842                     if (value == DataGridViewHeaderBorderStyle.Custom)
1843                     {
1844                         throw new ArgumentException(SR.GetString(SR.DataGridView_CustomCellBorderStyleInvalid, "ColumnHeadersBorderStyle"));
1845                     }
1846                     this.dataGridViewOper[DATAGRIDVIEWOPER_inBorderStyleChange] = true;
1847                     try
1848                     {
1849                         switch (value)
1850                         {
1851                             case DataGridViewHeaderBorderStyle.Single:
1852                                 this.advancedColumnHeadersBorderStyle.All = DataGridViewAdvancedCellBorderStyle.Single;
1853                                 break;
1854  
1855                             case DataGridViewHeaderBorderStyle.Raised:
1856                                 this.advancedColumnHeadersBorderStyle.All = DataGridViewAdvancedCellBorderStyle.OutsetPartial;
1857                                 break;
1858  
1859                             case DataGridViewHeaderBorderStyle.Sunken:
1860                                 this.advancedColumnHeadersBorderStyle.All = DataGridViewAdvancedCellBorderStyle.InsetDouble;
1861                                 break;
1862  
1863                             case DataGridViewHeaderBorderStyle.None:
1864                                 this.advancedColumnHeadersBorderStyle.All = DataGridViewAdvancedCellBorderStyle.None;
1865                                 break;
1866                         }
1867                     }
1868                     finally
1869                     {
1870                         this.dataGridViewOper[DATAGRIDVIEWOPER_inBorderStyleChange] = false;
1871                     }
1872                     OnColumnHeadersBorderStyleChanged(EventArgs.Empty);
1873                 }
1874             }
1875         }
1876  
1877         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnHeadersBorderStyleChanged"]/*‘ />
1878         [
1879             SRCategory(SR.CatPropertyChanged), 
1880             SRDescription(SR.DataGridView_ColumnHeadersBorderStyleChangedDescr)
1881         ]
1882         public event EventHandler ColumnHeadersBorderStyleChanged
1883         {
1884             add
1885             {
1886                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCOLUMNHEADERSBORDERSTYLECHANGED, value);
1887             }
1888             remove
1889             {
1890                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCOLUMNHEADERSBORDERSTYLECHANGED, value);
1891             }
1892         }
1893  
1894         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnHeadersDefaultCellStyle"]/*‘ />
1895         [
1896             SRCategory(SR.CatAppearance),
1897             SRDescription(SR.DataGridView_ColumnHeadersDefaultCellStyleDescr),
1898             AmbientValue(null)
1899         ]
1900         public DataGridViewCellStyle ColumnHeadersDefaultCellStyle
1901         {
1902             get 
1903             {
1904                 if (this.columnHeadersDefaultCellStyle == null)
1905                 {
1906                     this.columnHeadersDefaultCellStyle = this.DefaultColumnHeadersDefaultCellStyle;
1907                 }
1908                 return this.columnHeadersDefaultCellStyle;
1909             }
1910             set 
1911             {
1912                 DataGridViewCellStyle cs = this.ColumnHeadersDefaultCellStyle;
1913                 cs.RemoveScope(DataGridViewCellStyleScopes.ColumnHeaders);
1914                 this.columnHeadersDefaultCellStyle = value;
1915                 if (value != null)
1916                 {
1917                     this.columnHeadersDefaultCellStyle.AddScope(this, DataGridViewCellStyleScopes.ColumnHeaders);
1918                 }
1919                 DataGridViewCellStyleDifferences dgvcsc = cs.GetDifferencesFrom(this.ColumnHeadersDefaultCellStyle);
1920                 if (dgvcsc != DataGridViewCellStyleDifferences.None)
1921                 {
1922                     this.CellStyleChangedEventArgs.ChangeAffectsPreferredSize = (dgvcsc == DataGridViewCellStyleDifferences.AffectPreferredSize);
1923                     OnColumnHeadersDefaultCellStyleChanged(this.CellStyleChangedEventArgs);
1924                 }
1925             }
1926         }
1927  
1928         private DataGridViewCellStyle DefaultColumnHeadersDefaultCellStyle {
1929             get
1930             {
1931                 DataGridViewCellStyle defaultStyle = new DataGridViewCellStyle();
1932                 defaultStyle.BackColor = DefaultHeadersBackBrush.Color;
1933                 defaultStyle.ForeColor = DefaultForeBrush.Color;
1934                 defaultStyle.SelectionBackColor = DefaultSelectionBackBrush.Color;
1935                 defaultStyle.SelectionForeColor = DefaultSelectionForeBrush.Color;
1936                 defaultStyle.Font = base.Font;
1937                 defaultStyle.AlignmentInternal = DataGridViewContentAlignment.MiddleLeft;
1938                 defaultStyle.WrapModeInternal = DataGridViewTriState.True;
1939                 defaultStyle.AddScope(this, DataGridViewCellStyleScopes.ColumnHeaders);
1940  
1941                 this.dataGridViewState1[DATAGRIDVIEWSTATE1_ambientColumnHeadersFont] = true;
1942  
1943                 return defaultStyle;
1944             }
1945         }
1946  
1947         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnHeadersDefaultCellStyleChanged"]/*‘ />
1948         [
1949             SRCategory(SR.CatPropertyChanged), 
1950             SRDescription(SR.DataGridViewColumnHeadersDefaultCellStyleChangedDescr)
1951         ]
1952         public event EventHandler ColumnHeadersDefaultCellStyleChanged
1953         {
1954             add 
1955             {
1956                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCOLUMNHEADERSDEFAULTCELLSTYLECHANGED, value);
1957             }
1958             remove 
1959             {
1960                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCOLUMNHEADERSDEFAULTCELLSTYLECHANGED, value);
1961             }
1962         }
1963  
1964         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnHeadersHeight"]/*‘ />
1965         [
1966             SRCategory(SR.CatAppearance),
1967             Localizable(true), 
1968             SRDescription(SR.DataGridView_ColumnHeadersHeightDescr)
1969         ]
1970         public int ColumnHeadersHeight
1971         {
1972             get 
1973             {
1974                 return this.columnHeadersHeight;
1975             }
1976             set 
1977             {
1978                 if (value < minimumColumnHeadersHeight)
1979                 {
1980                     throw new ArgumentOutOfRangeException("ColumnHeadersHeight", SR.GetString(SR.InvalidLowBoundArgumentEx, "ColumnHeadersHeight", (value).ToString(CultureInfo.CurrentCulture), (minimumColumnHeadersHeight).ToString(CultureInfo.CurrentCulture)));
1981                 }
1982                 if (value > maxHeadersThickness)
1983                 {
1984                     throw new ArgumentOutOfRangeException("ColumnHeadersHeight", SR.GetString(SR.InvalidHighBoundArgumentEx, "ColumnHeadersHeight", (value).ToString(CultureInfo.CurrentCulture), (maxHeadersThickness).ToString(CultureInfo.CurrentCulture)));
1985                 }
1986                 if (this.ColumnHeadersHeightSizeMode == DataGridViewColumnHeadersHeightSizeMode.AutoSize)
1987                 {
1988                     this.cachedColumnHeadersHeight = value;
1989                 }
1990                 else if (this.columnHeadersHeight != value)
1991                 {
1992                     SetColumnHeadersHeightInternal(value, true /*invalidInAdjustFillingColumns*/);
1993                 }
1994             }
1995         }
1996  
1997         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnHeadersHeightChanged"]/*‘ />
1998         [
1999             SRCategory(SR.CatPropertyChanged), 
2000             SRDescription(SR.DataGridViewColumnHeadersHeightChangedDescr)
2001         ]
2002         public event EventHandler ColumnHeadersHeightChanged
2003         {
2004             add 
2005             {
2006                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCOLUMNHEADERSHEIGHTCHANGED, value);
2007             }
2008             remove 
2009             {
2010                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCOLUMNHEADERSHEIGHTCHANGED, value);
2011             }
2012         }
2013  
2014         private bool ShouldSerializeColumnHeadersHeight()
2015         {
2016             return this.ColumnHeadersHeightSizeMode != DataGridViewColumnHeadersHeightSizeMode.AutoSize && defaultColumnHeadersHeight != this.ColumnHeadersHeight;
2017         }
2018  
2019         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnHeadersHeightSizeMode"]/*‘ />
2020         /// <devdoc>
2021         ///    <para>
2022         ///       Gets or sets a value that determines the behavior for adjusting the column headers height.
2023         ///    </para>
2024         /// </devdoc>
2025         [
2026             DefaultValue(DataGridViewColumnHeadersHeightSizeMode.EnableResizing),
2027             RefreshProperties(RefreshProperties.All),
2028             SRCategory(SR.CatBehavior),
2029             SRDescription(SR.DataGridView_ColumnHeadersHeightSizeModeDescr)
2030         ]
2031         public DataGridViewColumnHeadersHeightSizeMode ColumnHeadersHeightSizeMode
2032         {
2033             get
2034             {
2035                 return this.columnHeadersHeightSizeMode;
2036             }
2037             set
2038             {
2039                // Sequential enum.  Valid values are 0x0 to 0x2
2040                 if (!ClientUtils.IsEnumValid(value, (int)value, (int)DataGridViewColumnHeadersHeightSizeMode.EnableResizing, (int)DataGridViewColumnHeadersHeightSizeMode.AutoSize))
2041                 {
2042                      throw new InvalidEnumArgumentException("value", (int)value, typeof(DataGridViewColumnHeadersHeightSizeMode)); 
2043                 }
2044                 if (this.columnHeadersHeightSizeMode != value)
2045                 {
2046                     /*if (value == DataGridViewColumnHeadersHeightSizeMode.AutoSize && !this.ColumnHeadersVisible)
2047                     {
2048                         We intentionally don‘t throw an error because of designer code spit order.
2049                     }*/
2050                     DataGridViewAutoSizeModeEventArgs dgvasme = new DataGridViewAutoSizeModeEventArgs(this.columnHeadersHeightSizeMode == DataGridViewColumnHeadersHeightSizeMode.AutoSize);
2051                     this.columnHeadersHeightSizeMode = value;
2052                     OnColumnHeadersHeightSizeModeChanged(dgvasme);
2053                 }
2054             }
2055         }
2056  
2057         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnHeadersHeightSizeModeChanged"]/*‘ />
2058         [
2059             SRCategory(SR.CatPropertyChanged), 
2060             SRDescription(SR.DataGridView_ColumnHeadersHeightSizeModeChangedDescr)
2061         ]
2062         public event DataGridViewAutoSizeModeEventHandler ColumnHeadersHeightSizeModeChanged
2063         {
2064             add
2065             {
2066                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCOLUMNHEADERSHEIGHTSIZEMODECHANGED, value);
2067             }
2068             remove
2069             {
2070                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCOLUMNHEADERSHEIGHTSIZEMODECHANGED, value);
2071             }
2072         }
2073  
2074         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnHeadersVisible"]/*‘ />
2075         /// <devdoc>
2076         ///    <para>
2077         ///       Gets
2078         ///       or sets a value indicating if the dataGridView‘s column headers are visible.
2079         ///    </para>
2080         /// </devdoc>
2081         [
2082             SRCategory(SR.CatAppearance),
2083             DefaultValue(true),
2084             SRDescription(SR.DataGridViewColumnHeadersVisibleDescr)
2085         ]
2086         public bool ColumnHeadersVisible 
2087         {
2088             get 
2089             {
2090                 return this.dataGridViewState1[DATAGRIDVIEWSTATE1_columnHeadersVisible];
2091             }
2092             set 
2093             {
2094                 if (this.ColumnHeadersVisible != value)
2095                 {
2096                     if (!value)
2097                     {
2098                         // Make sure that there is no visible column that only counts on the column headers to autosize
2099                         DataGridViewColumn dataGridViewColumn = this.Columns.GetFirstColumn(DataGridViewElementStates.Visible);
2100                         while (dataGridViewColumn != null)
2101                         {
2102                             if (dataGridViewColumn.InheritedAutoSizeMode == DataGridViewAutoSizeColumnMode.ColumnHeader)
2103                             {
2104                                 throw new InvalidOperationException(SR.GetString(SR.DataGridView_ColumnHeadersCannotBeInvisible));
2105                             }
2106                             dataGridViewColumn = this.Columns.GetNextColumn(dataGridViewColumn,
2107                                 DataGridViewElementStates.Visible,
2108                                 DataGridViewElementStates.None);
2109                         }
2110                     }
2111                     using (LayoutTransaction.CreateTransactionIf(this.AutoSize, this.ParentInternal, this, PropertyNames.ColumnHeadersVisible))
2112                     {
2113                         this.dataGridViewState1[DATAGRIDVIEWSTATE1_columnHeadersVisible] = value;
2114                         this.layout.ColumnHeadersVisible = value;
2115                         this.displayedBandsInfo.EnsureDirtyState();
2116                         if (!this.AutoSize)
2117                         {
2118                             PerformLayoutPrivate(false /*useRowShortcut*/, false /*computeVisibleRows*/, true /*invalidInAdjustFillingColumns*/, true /*repositionEditingControl*/);
2119                         }
2120                         InvalidateInside();
2121                         OnColumnHeadersGlobalAutoSize();
2122                     }
2123                 }
2124             }
2125         }
2126  
2127         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.Columns"]/*‘ />
2128         [
2129             Editor("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, " + AssemblyRef.SystemDesign, typeof(System.Drawing.Design.UITypeEditor)),
2130             DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
2131             MergableProperty(false)
2132         ]
2133         public DataGridViewColumnCollection Columns
2134         {
2135             get
2136             {
2137                 if (this.dataGridViewColumns == null)
2138                 {
2139                     this.dataGridViewColumns = CreateColumnsInstance();
2140                 }
2141                 return this.dataGridViewColumns;
2142             }
2143         }
2144  
2145         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CurrentCell"]/*‘ />
2146         [
2147             Browsable(false),
2148             DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
2149         ]
2150         public DataGridViewCell CurrentCell
2151         {
2152             get
2153             {
2154                 if (this.ptCurrentCell.X == -1 && this.ptCurrentCell.Y == -1)
2155                 {
2156                     return null;
2157                 }
2158                 Debug.Assert(this.ptCurrentCell.X >= 0 && ptCurrentCell.Y >= 0);
2159                 Debug.Assert(this.ptCurrentCell.X < this.Columns.Count);
2160                 Debug.Assert(this.ptCurrentCell.Y < this.Rows.Count);
2161                 DataGridViewRow dataGridViewRow = (DataGridViewRow) this.Rows[this.ptCurrentCell.Y]; // unsharing row
2162                 return dataGridViewRow.Cells[this.ptCurrentCell.X];
2163             }
2164             set
2165             {
2166                 if ((value != null && (value.RowIndex != this.ptCurrentCell.Y || value.ColumnIndex != this.ptCurrentCell.X)) ||
2167                     (value == null && this.ptCurrentCell.X != -1))
2168                 {
2169                     if (value == null)
2170                     {
2171                         ClearSelection();
2172                         if (!SetCurrentCellAddressCore(-1, -1, true /*setAnchorCellAddress*/, true /*validateCurrentCell*/, false /*throughMouseClick*/))
2173                         {
2174                             // Edited value couldn‘t be committed or aborted
2175                             throw new InvalidOperationException(SR.GetString(SR.DataGridView_CellChangeCannotBeCommittedOrAborted));
2176                         }
2177                     }
2178                     else
2179                     {
2180                         if (value.DataGridView != this)
2181                         {
2182                             throw new ArgumentException(SR.GetString(SR.DataGridView_CellDoesNotBelongToDataGridView));
2183                         }
2184                         if (!this.Columns[value.ColumnIndex].Visible ||
2185                             (this.Rows.GetRowState(value.RowIndex) & DataGridViewElementStates.Visible) == 0)
2186                         {
2187                             throw new InvalidOperationException(SR.GetString(SR.DataGridView_CurrentCellCannotBeInvisible));
2188                         }
2189                         if (!ScrollIntoView(value.ColumnIndex, value.RowIndex, true))
2190                         {
2191                             throw new InvalidOperationException(SR.GetString(SR.DataGridView_CellChangeCannotBeCommittedOrAborted));
2192                         }
2193                         if (IsInnerCellOutOfBounds(value.ColumnIndex, value.RowIndex))
2194                         {
2195                             return;
2196                         }
2197                         ClearSelection(value.ColumnIndex, value.RowIndex, true /*selectExceptionElement*/);
2198                         if (!SetCurrentCellAddressCore(value.ColumnIndex, value.RowIndex, true, false, false))
2199                         {
2200                             throw new InvalidOperationException(SR.GetString(SR.DataGridView_CellChangeCannotBeCommittedOrAborted));
2201                         }
2202                     }
2203                 }
2204             }
2205         }
2206  
2207         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CurrentCellAddress"]/*‘ />
2208         [
2209             Browsable(false)
2210         ]
2211         public Point CurrentCellAddress
2212         {
2213             get
2214             {
2215                 return this.ptCurrentCell;
2216             }
2217         }
2218  
2219         private DataGridViewCell CurrentCellInternal
2220         {
2221             get
2222             {
2223                 Debug.Assert(this.ptCurrentCell.X >= 0 && this.ptCurrentCell.X < this.Columns.Count);
2224                 Debug.Assert(this.ptCurrentCell.Y >= 0 && this.ptCurrentCell.Y < this.Rows.Count);
2225                 DataGridViewRow dataGridViewRow = this.Rows.SharedRow(this.ptCurrentCell.Y);
2226                 Debug.Assert(dataGridViewRow != null);
2227                 DataGridViewCell dataGridViewCell = dataGridViewRow.Cells[this.ptCurrentCell.X];
2228                 Debug.Assert(this.IsSharedCellVisible(dataGridViewCell, this.ptCurrentCell.Y));
2229                 return dataGridViewCell;
2230             }
2231         }
2232  
2233         private bool CurrentCellIsFirstVisibleCell
2234         {
2235             get
2236             {
2237                 if (this.ptCurrentCell.X == -1)
2238                 {
2239                     return false;
2240                 }
2241                 Debug.Assert(this.ptCurrentCell.Y != -1);
2242  
2243                 bool previousVisibleColumnExists = (null != this.Columns.GetPreviousColumn(this.Columns[this.ptCurrentCell.X], DataGridViewElementStates.Visible, DataGridViewElementStates.None));
2244                 bool previousVisibleRowExists = (-1 != this.Rows.GetPreviousRow(this.ptCurrentCell.Y, DataGridViewElementStates.Visible));
2245  
2246                 return !previousVisibleColumnExists && !previousVisibleRowExists;
2247             }
2248         }
2249  
2250         private bool CurrentCellIsLastVisibleCell
2251         {
2252             get
2253             {
2254                 if (this.ptCurrentCell.X == -1)
2255                 {
2256                     return false;
2257                 }
2258  
2259                 Debug.Assert(this.ptCurrentCell.Y != -1);
2260  
2261                 bool nextVisibleColumnExists = (null != this.Columns.GetNextColumn(this.Columns[this.ptCurrentCell.X], DataGridViewElementStates.Visible, DataGridViewElementStates.None));
2262                 bool nextVisibleRowExists = (-1 != this.Rows.GetNextRow(this.ptCurrentCell.Y, DataGridViewElementStates.Visible));
2263  
2264                 return !nextVisibleColumnExists && !nextVisibleRowExists;
2265             }
2266         }
2267  
2268         private bool CurrentCellIsEditedAndOnlySelectedCell
2269         {
2270             get
2271             {
2272                 if (this.ptCurrentCell.X == -1)
2273                 {
2274                     return false;
2275                 }
2276  
2277                 Debug.Assert(this.ptCurrentCell.Y != -1);
2278  
2279                 return this.editingControl != null &&
2280                        GetCellCount(DataGridViewElementStates.Selected) == 1 &&
2281                        this.CurrentCellInternal.Selected;
2282             }
2283         }
2284  
2285         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CurrentRow"]/*‘ />
2286         [
2287             Browsable(false)
2288         ]
2289         public DataGridViewRow CurrentRow 
2290         {
2291             get
2292             {
2293                 if (this.ptCurrentCell.X == -1)
2294                 {
2295                     return null;
2296                 }
2297  
2298                 Debug.Assert(this.ptCurrentCell.Y >= 0);
2299                 Debug.Assert(this.ptCurrentCell.Y < this.Rows.Count);
2300  
2301                 return this.Rows[this.ptCurrentCell.Y];
2302             }
2303         }
2304  
2305         internal Cursor CursorInternal
2306         {
2307             set
2308             {
2309                 this.dataGridViewState2[DATAGRIDVIEWSTATE2_ignoreCursorChange] = true;
2310                 try
2311                 {
2312                     this.Cursor = value;
2313                 }
2314                 finally
2315                 {
2316                     this.dataGridViewState2[DATAGRIDVIEWSTATE2_ignoreCursorChange] = false;
2317                 }
2318             }
2319         }
2320  
2321         internal DataGridViewDataConnection DataConnection
2322         {
2323             get
2324             {
2325                 return this.dataConnection;
2326             }
2327         }
2328  
2329         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.DataMember"]/*‘ />
2330         [
2331          DefaultValue(""),
2332          SRCategory(SR.CatData),
2333          Editor("System.Windows.Forms.Design.DataMemberListEditor, " + AssemblyRef.SystemDesign, typeof(System.Drawing.Design.UITypeEditor)),
2334          SRDescription(SR.DataGridViewDataMemberDescr)
2335         ]
2336         public string DataMember
2337         {
2338             get
2339             {
2340                 if (this.dataConnection == null)
2341                 {
2342                     return String.Empty;
2343                 }
2344                 else
2345                 {
2346                     return this.dataConnection.DataMember;
2347                 }
2348             }
2349             set
2350             {
2351                 if (value != this.DataMember)
2352                 {
2353                     this.CurrentCell = null;
2354                     if (this.dataConnection == null)
2355                     {
2356                         this.dataConnection = new DataGridViewDataConnection(this);
2357                     }
2358                     this.dataConnection.SetDataConnection(this.DataSource, value);
2359                     OnDataMemberChanged(EventArgs.Empty);
2360                 }
2361             }
2362         }
2363  
2364         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.DataMemberChanged"]/*‘ />
2365         [
2366             SRCategory(SR.CatPropertyChanged), 
2367             SRDescription(SR.DataGridViewDataMemberChangedDescr)
2368         ]
2369         public event EventHandler DataMemberChanged
2370         {
2371             add
2372             {
2373                 this.Events.AddHandler(EVENT_DATAGRIDVIEWDATAMEMBERCHANGED, value);
2374             }
2375             remove
2376             {
2377                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWDATAMEMBERCHANGED, value);
2378             }
2379         }
2380  
2381         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.DataSource"]/*‘ />
2382         [
2383          DefaultValue(null),
2384          SRCategory(SR.CatData),
2385          RefreshProperties(RefreshProperties.Repaint),
2386          AttributeProvider(typeof(IListSource)),
2387          SRDescription(SR.DataGridViewDataSourceDescr)
2388         ]
2389         public object DataSource
2390         {
2391             get
2392             {
2393                 if (this.dataConnection == null)
2394                 {
2395                     return null;
2396                 }
2397                 else
2398                 {
2399                     return this.dataConnection.DataSource;
2400                 }
2401             }
2402             set
2403             {
2404                 if (value != this.DataSource)
2405                 {
2406                     this.CurrentCell = null;
2407                     if (this.dataConnection == null)
2408                     {
2409                         this.dataConnection = new DataGridViewDataConnection(this);
2410                         this.dataConnection.SetDataConnection(value, this.DataMember);
2411                     }
2412                     else
2413                     {
2414                         if (this.dataConnection.ShouldChangeDataMember(value))
2415                         {
2416                             // we fire DataMemberChanged event
2417                             this.DataMember = "";
2418                         }
2419                         this.dataConnection.SetDataConnection(value, this.DataMember);
2420                         if (value == null)
2421                         {
2422                             this.dataConnection = null;
2423                         }
2424                     }
2425                     OnDataSourceChanged(EventArgs.Empty);
2426                 }
2427             }
2428         }
2429  
2430         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.DataSourceChanged"]/*‘ />
2431         [
2432             SRCategory(SR.CatPropertyChanged), 
2433             SRDescription(SR.DataGridViewDataSourceChangedDescr)
2434         ]
2435         public event EventHandler DataSourceChanged
2436         {
2437             add
2438             {
2439                 this.Events.AddHandler(EVENT_DATAGRIDVIEWDATASOURCECHANGED, value);
2440             }
2441             remove
2442             {
2443                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWDATASOURCECHANGED, value);
2444             }
2445         }
2446  
2447         private static SolidBrush DefaultBackBrush 
2448         {
2449             get 
2450             {
2451                 return (SolidBrush) SystemBrushes.Window;
2452             }
2453         }
2454  
2455         private static SolidBrush DefaultBackgroundBrush 
2456         {
2457             get 
2458             {
2459                 return (SolidBrush) SystemBrushes.AppWorkspace;
2460             }
2461         }
2462  
2463         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.DefaultCellStyle"]/*‘ />
2464         [
2465             SRCategory(SR.CatAppearance),
2466             SRDescription(SR.DataGridView_DefaultCellStyleDescr),
2467             AmbientValue(null)
2468         ]
2469         public DataGridViewCellStyle DefaultCellStyle 
2470         {
2471             get 
2472             {
2473                 if (this.defaultCellStyle == null)
2474                 {
2475                     this.defaultCellStyle = this.DefaultDefaultCellStyle;                    
2476                     return this.defaultCellStyle;
2477                 }
2478                 else if (this.defaultCellStyle.BackColor == Color.Empty || 
2479                     this.defaultCellStyle.ForeColor == Color.Empty || 
2480                     this.defaultCellStyle.SelectionBackColor == Color.Empty || 
2481                     this.defaultCellStyle.SelectionForeColor == Color.Empty || 
2482                     this.defaultCellStyle.Font == null || 
2483                     this.defaultCellStyle.Alignment == DataGridViewContentAlignment.NotSet || 
2484                     this.defaultCellStyle.WrapMode == DataGridViewTriState.NotSet)
2485                 {
2486                     DataGridViewCellStyle defaultCellStyleTmp = new DataGridViewCellStyle(this.defaultCellStyle);
2487                     defaultCellStyleTmp.Scope = DataGridViewCellStyleScopes.None;
2488                     if (this.defaultCellStyle.BackColor == Color.Empty)
2489                     {
2490                         defaultCellStyleTmp.BackColor = DefaultBackBrush.Color;
2491                     }
2492                     if (this.defaultCellStyle.ForeColor == Color.Empty)
2493                     {
2494                         defaultCellStyleTmp.ForeColor = base.ForeColor;
2495                         this.dataGridViewState1[DATAGRIDVIEWSTATE1_ambientForeColor] = true;
2496                     }
2497                     if (this.defaultCellStyle.SelectionBackColor == Color.Empty)
2498                     {
2499                         defaultCellStyleTmp.SelectionBackColor = DefaultSelectionBackBrush.Color;
2500                     }
2501                     if (this.defaultCellStyle.SelectionForeColor == Color.Empty)
2502                     {
2503                         defaultCellStyleTmp.SelectionForeColor = DefaultSelectionForeBrush.Color;
2504                     }
2505                     if (this.defaultCellStyle.Font == null)
2506                     {
2507                         defaultCellStyleTmp.Font = base.Font;
2508                         this.dataGridViewState1[DATAGRIDVIEWSTATE1_ambientFont] = true;
2509                     }
2510                     if (this.defaultCellStyle.Alignment == DataGridViewContentAlignment.NotSet)
2511                     {
2512                         defaultCellStyleTmp.AlignmentInternal = DataGridViewContentAlignment.MiddleLeft;
2513                     }
2514                     if (this.defaultCellStyle.WrapMode == DataGridViewTriState.NotSet)
2515                     {
2516                         defaultCellStyleTmp.WrapModeInternal = DataGridViewTriState.False;
2517                     }
2518                     defaultCellStyleTmp.AddScope(this, DataGridViewCellStyleScopes.DataGridView);
2519                     return defaultCellStyleTmp;
2520                 }
2521                 else
2522                 {
2523                     return this.defaultCellStyle;
2524                 }
2525             }
2526             set 
2527             {
2528                 DataGridViewCellStyle cs = this.DefaultCellStyle;
2529                 cs.RemoveScope(DataGridViewCellStyleScopes.DataGridView);
2530                 this.defaultCellStyle = value;
2531                 if (value != null)
2532                 {
2533                     this.defaultCellStyle.AddScope(this, DataGridViewCellStyleScopes.DataGridView);
2534                 }
2535                 DataGridViewCellStyleDifferences dgvcsc = cs.GetDifferencesFrom(this.DefaultCellStyle);
2536                 if (dgvcsc != DataGridViewCellStyleDifferences.None)
2537                 {
2538                     this.CellStyleChangedEventArgs.ChangeAffectsPreferredSize = (dgvcsc == DataGridViewCellStyleDifferences.AffectPreferredSize);
2539                     OnDefaultCellStyleChanged(this.CellStyleChangedEventArgs);
2540                 }
2541             }
2542         }
2543  
2544         private DataGridViewCellStyle DefaultDefaultCellStyle 
2545         {
2546             get 
2547             {
2548                 DataGridViewCellStyle defaultCellStyle = new DataGridViewCellStyle();
2549                 defaultCellStyle.BackColor = DefaultBackBrush.Color;
2550                 defaultCellStyle.ForeColor = base.ForeColor;
2551                 defaultCellStyle.SelectionBackColor = DefaultSelectionBackBrush.Color;
2552                 defaultCellStyle.SelectionForeColor = DefaultSelectionForeBrush.Color;
2553                 defaultCellStyle.Font = base.Font;
2554                 defaultCellStyle.AlignmentInternal = DataGridViewContentAlignment.MiddleLeft;
2555                 defaultCellStyle.WrapModeInternal = DataGridViewTriState.False;
2556                 defaultCellStyle.AddScope(this, DataGridViewCellStyleScopes.DataGridView);
2557  
2558                 this.dataGridViewState1[DATAGRIDVIEWSTATE1_ambientFont] = true;
2559                 this.dataGridViewState1[DATAGRIDVIEWSTATE1_ambientForeColor] = true;
2560                 
2561                 return defaultCellStyle;
2562             }
2563         }
2564  
2565         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.DefaultCellStyleChanged"]/*‘ />
2566         [
2567             SRCategory(SR.CatPropertyChanged), 
2568             SRDescription(SR.DataGridViewDefaultCellStyleChangedDescr)
2569         ]
2570         public event EventHandler DefaultCellStyleChanged
2571         {
2572             add 
2573             {
2574                 this.Events.AddHandler(EVENT_DATAGRIDVIEWDEFAULTCELLSTYLECHANGED, value);
2575             }
2576             remove 
2577             {
2578                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWDEFAULTCELLSTYLECHANGED, value);
2579             }
2580         }
2581  
2582         private static SolidBrush DefaultForeBrush 
2583         {
2584             get 
2585             {
2586                 return (SolidBrush) SystemBrushes.WindowText;
2587             }
2588         }
2589  
2590         private static Color DefaultGridColor
2591         {
2592             get 
2593             {
2594                 return SystemColors.ControlDark;
2595             }
2596         }
2597  
2598         private static SolidBrush DefaultHeadersBackBrush
2599         {
2600             get 
2601             {
2602                 return (SolidBrush) SystemBrushes.Control;
2603             }
2604         }
2605  
2606         private DataGridViewCellStyle DefaultRowHeadersDefaultCellStyle
2607         {
2608             get 
2609             {
2610                 DataGridViewCellStyle defaultStyle = new DataGridViewCellStyle();
2611                 defaultStyle.BackColor = DefaultHeadersBackBrush.Color;
2612                 defaultStyle.ForeColor = DefaultForeBrush.Color;
2613                 defaultStyle.SelectionBackColor = DefaultSelectionBackBrush.Color;
2614                 defaultStyle.SelectionForeColor = DefaultSelectionForeBrush.Color;
2615                 defaultStyle.Font = base.Font;
2616                 defaultStyle.AlignmentInternal = DataGridViewContentAlignment.MiddleLeft;
2617                 defaultStyle.WrapModeInternal = DataGridViewTriState.True;
2618                 defaultStyle.AddScope(this, DataGridViewCellStyleScopes.RowHeaders);
2619  
2620                 this.dataGridViewState1[DATAGRIDVIEWSTATE1_ambientRowHeadersFont] = true;
2621  
2622                 return defaultStyle;
2623             }
2624         }
2625  
2626         private static SolidBrush DefaultSelectionBackBrush 
2627         {
2628             get 
2629             {
2630                 return (SolidBrush) SystemBrushes.Highlight;
2631             }
2632         }
2633         
2634         private static SolidBrush DefaultSelectionForeBrush 
2635         {
2636             get 
2637             {
2638                 return (SolidBrush) SystemBrushes.HighlightText;
2639             }
2640         }
2641  
2642         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.DefaultSize"]/*‘ />
2643         protected override Size DefaultSize
2644         {
2645             get
2646             {
2647                 return new Size(240, 150);
2648             }
2649         }
2650  
2651         internal DisplayedBandsData DisplayedBandsInfo
2652         {
2653             get
2654             {
2655                 return this.displayedBandsInfo;
2656             }
2657         }
2658  
2659         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.DisplayRectangle"]/*‘ />
2660         /// <devdoc>
2661         ///     Returns the client rect of the display area of the control.
2662         ///     The DataGridView control return its client rectangle minus the potential scrollbars.
2663         /// </devdoc>
2664         public override Rectangle DisplayRectangle {
2665             get {
2666                 Rectangle rectDisplay = this.ClientRectangle;
2667                 if (this.horizScrollBar != null && this.horizScrollBar.Visible)
2668                 {
2669                     rectDisplay.Height -= this.horizScrollBar.Height;
2670                 }
2671                 if (this.vertScrollBar != null && this.vertScrollBar.Visible)
2672                 {
2673                     rectDisplay.Width -= this.vertScrollBar.Width;
2674                     if (this.RightToLeftInternal)
2675                     {
2676                         rectDisplay.X = this.vertScrollBar.Width;
2677                     }
2678                 }
2679                 return rectDisplay;
2680             }
2681         }
2682  
2683         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.EditMode"]/*‘ />
2684         [
2685             SRCategory(SR.CatBehavior),
2686             DefaultValue(DataGridViewEditMode.EditOnKeystrokeOrF2),
2687             SRDescription(SR.DataGridView_EditModeDescr)
2688         ]
2689         public DataGridViewEditMode EditMode
2690         {
2691             get
2692             {
2693                 return this.editMode;
2694             }
2695             set
2696             {
2697                 // Sequential enum.  Valid values are 0x0 to 0x4
2698                 if (!ClientUtils.IsEnumValid(value, (int)value, (int)DataGridViewEditMode.EditOnEnter, (int)DataGridViewEditMode.EditProgrammatically))
2699                 {
2700                      throw new InvalidEnumArgumentException("value", (int)value, typeof(DataGridViewEditMode)); 
2701                 }               
2702                 if (this.editMode != value)
2703                 {
2704                     this.editMode = value;
2705                     OnEditModeChanged(EventArgs.Empty);
2706                 }
2707             }
2708         }
2709  
2710         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.EditModeChanged"]/*‘ />
2711         [
2712             SRCategory(SR.CatPropertyChanged), 
2713             SRDescription(SR.DataGridView_EditModeChangedDescr)
2714         ]
2715         public event EventHandler EditModeChanged
2716         {
2717             add
2718             {
2719                 this.Events.AddHandler(EVENT_DATAGRIDVIEWEDITMODECHANGED, value);
2720             }
2721             remove
2722             {
2723                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWEDITMODECHANGED, value);
2724             }
2725         }
2726  
2727         internal Point MouseEnteredCellAddress
2728         {
2729             get
2730             {
2731                 return this.ptMouseEnteredCell;
2732             }
2733         }
2734  
2735         private bool MouseOverEditingControl
2736         {
2737             get
2738             {
2739                 if (this.editingControl != null)
2740                 {
2741                     Point ptMouse = PointToClient(Control.MousePosition);
2742                     return this.editingControl.Bounds.Contains(ptMouse);
2743                 }
2744                 return false;
2745             }
2746         }
2747  
2748         private bool MouseOverEditingPanel
2749         {
2750             get
2751             {
2752                 if (this.editingPanel != null)
2753                 {
2754                     Point ptMouse = PointToClient(Control.MousePosition);
2755                     return this.editingPanel.Bounds.Contains(ptMouse);
2756                 }
2757                 return false;
2758             }
2759         }
2760  
2761         private bool MouseOverScrollBar
2762         {
2763             get
2764             {
2765                 Point ptMouse = PointToClient(Control.MousePosition);
2766                 if (this.vertScrollBar != null && this.vertScrollBar.Visible)
2767                 {
2768                     if (this.vertScrollBar.Bounds.Contains(ptMouse))
2769                     {
2770                         return true;
2771                     }
2772                 }
2773                 if (this.horizScrollBar != null && this.horizScrollBar.Visible)
2774                 {
2775                     return this.horizScrollBar.Bounds.Contains(ptMouse);
2776                 }
2777                 return false;
2778             }
2779         }
2780  
2781         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.EditingControl"]/*‘ />
2782         [
2783             Browsable(false),
2784             EditorBrowsable(EditorBrowsableState.Advanced)
2785         ]
2786         public Control EditingControl
2787         {
2788             get
2789             {
2790                 return this.editingControl;
2791             }
2792         }
2793  
2794         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.EditingPanel"]/*‘ />
2795         [
2796             Browsable(false),
2797             EditorBrowsable(EditorBrowsableState.Advanced)
2798         ]
2799         public Panel EditingPanel
2800         {
2801             get
2802             {
2803                 if (this.editingPanel == null)
2804                 {
2805                     this.editingPanel = new Panel();
2806                     this.editingPanel.AccessibleName = SR.GetString(SR.DataGridView_AccEditingPanelAccName);
2807                 }
2808                 return this.editingPanel;
2809             }
2810         }
2811  
2812         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.EnableHeadersVisualStyles"]/*‘ />
2813         /// <devdoc>
2814         ///    <para>
2815         ///     Determines whether the DataGridView‘s header cells render using XP theming visual styles or not
2816         ///     when visual styles are enabled in the application.
2817         ///    </para>
2818         /// </devdoc>
2819         [
2820             SRCategory(SR.CatAppearance),
2821             DefaultValue(true),
2822             SRDescription(SR.DataGridView_EnableHeadersVisualStylesDescr)
2823         ]
2824         public bool EnableHeadersVisualStyles
2825         {
2826             get
2827             {
2828                 return this.dataGridViewState2[DATAGRIDVIEWSTATE2_enableHeadersVisualStyles];
2829             }
2830             set
2831             {
2832                 if (this.dataGridViewState2[DATAGRIDVIEWSTATE2_enableHeadersVisualStyles] != value)
2833                 {
2834                     this.dataGridViewState2[DATAGRIDVIEWSTATE2_enableHeadersVisualStyles] = value;
2835                     //OnEnableHeadersVisualStylesChanged(EventArgs.Empty);
2836                     // Some autosizing may have to be applied since the margins are potentially changed.
2837                     OnGlobalAutoSize(); // Put this into OnEnableHeadersVisualStylesChanged if created.
2838                 }
2839             }
2840         }
2841  
2842         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.FirstDisplayedCell"]/*‘ />
2843         [
2844             Browsable(false),
2845             DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
2846         ]
2847         public DataGridViewCell FirstDisplayedCell
2848         {
2849             get
2850             {
2851                 Point firstDisplayedCellAddress = this.FirstDisplayedCellAddress;
2852                 if (firstDisplayedCellAddress.X >= 0)
2853                 {
2854                     return this.Rows[firstDisplayedCellAddress.Y].Cells[firstDisplayedCellAddress.X]; // unshares the row of first displayed cell
2855                 }
2856                 return null;
2857             }
2858             set
2859             {
2860                 if (value != null)
2861                 {
2862                     DataGridViewCell firstDisplayedCell = value;
2863                     if (firstDisplayedCell.DataGridView != this)
2864                     {
2865                         throw new ArgumentException(SR.GetString(SR.DataGridView_CellDoesNotBelongToDataGridView));
2866                     }
2867                     if (firstDisplayedCell.RowIndex == -1 || firstDisplayedCell.ColumnIndex == -1)
2868                     {
2869                         throw new InvalidOperationException(SR.GetString(SR.DataGridView_FirstDisplayedCellCannotBeAHeaderOrSharedCell));
2870                     }
2871  
2872                     Debug.Assert(firstDisplayedCell.RowIndex >= 0 &&
2873                         firstDisplayedCell.RowIndex < this.Rows.Count &&
2874                         firstDisplayedCell.ColumnIndex >= 0 &&
2875                         firstDisplayedCell.ColumnIndex < this.Columns.Count);
2876  
2877                     if (!firstDisplayedCell.Visible)
2878                     {
2879                         throw new InvalidOperationException(SR.GetString(SR.DataGridView_FirstDisplayedCellCannotBeInvisible));
2880                     }
2881  
2882                     if (!firstDisplayedCell.Frozen)
2883                     {
2884                         if (!this.Rows[firstDisplayedCell.RowIndex].Frozen)
2885                         {
2886                             this.FirstDisplayedScrollingRowIndex = firstDisplayedCell.RowIndex;
2887                         }
2888  
2889                         if (!this.Columns[firstDisplayedCell.ColumnIndex].Frozen)
2890                         {
2891                             this.FirstDisplayedScrollingColumnIndex = firstDisplayedCell.ColumnIndex;
2892                         }
2893                     }
2894                 }
2895             }
2896         }
2897  
2898         private Point FirstDisplayedCellAddress
2899         {
2900             get
2901             {
2902                 Point ptFirstDisplayedCellAddress = new Point(-1, -1);
2903                 ptFirstDisplayedCellAddress.Y = this.Rows.GetFirstRow(DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen);
2904                 if (ptFirstDisplayedCellAddress.Y == -1)
2905                 {
2906                     Debug.Assert(this.displayedBandsInfo.NumTotallyDisplayedFrozenRows == 0);
2907                     if (this.displayedBandsInfo.FirstDisplayedScrollingRow >= 0)
2908                     {
2909                         ptFirstDisplayedCellAddress.Y = this.displayedBandsInfo.FirstDisplayedScrollingRow;
2910                     }
2911 #if DEBUG
2912                     else
2913                     {
2914                         Debug.Assert(this.displayedBandsInfo.FirstDisplayedScrollingRow == -1);
2915                         Debug.Assert(this.displayedBandsInfo.NumDisplayedScrollingRows == 0);
2916                         Debug.Assert(this.displayedBandsInfo.NumTotallyDisplayedScrollingRows == 0);
2917                     }
2918 #endif
2919                 }
2920                 if (ptFirstDisplayedCellAddress.Y >= 0)
2921                 {
2922                     ptFirstDisplayedCellAddress.X = this.FirstDisplayedColumnIndex;
2923                 }
2924                 return ptFirstDisplayedCellAddress;
2925             }
2926         }
2927  
2928         internal int FirstDisplayedColumnIndex
2929         {
2930             get
2931             {
2932                 if (!this.IsHandleCreated)
2933                 {
2934                     return -1;
2935                 }
2936                 
2937                 int firstDisplayedColumnIndex = -1;
2938                 DataGridViewColumn dataGridViewColumn = this.Columns.GetFirstColumn(DataGridViewElementStates.Visible);
2939                 if (dataGridViewColumn != null)
2940                 {
2941                     if (dataGridViewColumn.Frozen)
2942                     {
2943                         firstDisplayedColumnIndex = dataGridViewColumn.Index;
2944                     }
2945                     else if (this.displayedBandsInfo.FirstDisplayedScrollingCol >= 0)
2946                     {
2947                         firstDisplayedColumnIndex = this.displayedBandsInfo.FirstDisplayedScrollingCol;
2948                     }
2949                 }
2950 #if DEBUG
2951                 DataGridViewColumn dataGridViewColumnDbg1 = this.Columns.GetFirstColumn(DataGridViewElementStates.Displayed);
2952                 int firstDisplayedColumnIndexDbg1 = (dataGridViewColumnDbg1 == null) ? -1 : dataGridViewColumnDbg1.Index;
2953  
2954                 int firstDisplayedColumnIndexDbg2 = -1;
2955                 DataGridViewColumn dataGridViewColumnDbg = this.Columns.GetFirstColumn(DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen);
2956                 if (dataGridViewColumnDbg != null)
2957                 {
2958                     firstDisplayedColumnIndexDbg2 = dataGridViewColumnDbg.Index;
2959                 }
2960                 else if (this.displayedBandsInfo.FirstDisplayedScrollingCol >= 0)
2961                 {
2962                     firstDisplayedColumnIndexDbg2 = this.displayedBandsInfo.FirstDisplayedScrollingCol;
2963                 }
2964                 else
2965                 {
2966                     Debug.Assert(this.displayedBandsInfo.LastTotallyDisplayedScrollingCol == -1);
2967                 }
2968                 Debug.Assert(firstDisplayedColumnIndex == firstDisplayedColumnIndexDbg1 || !this.Visible || this.displayedBandsInfo.Dirty);
2969                 Debug.Assert(firstDisplayedColumnIndex == firstDisplayedColumnIndexDbg2 || this.displayedBandsInfo.Dirty);
2970 #endif
2971                 return firstDisplayedColumnIndex;
2972             }
2973         }
2974  
2975         internal int FirstDisplayedRowIndex
2976         {
2977             get
2978             {
2979                 if (!this.IsHandleCreated)
2980                 {
2981                     return -1;
2982                 }
2983  
2984                 int firstDisplayedRowIndex = this.Rows.GetFirstRow(DataGridViewElementStates.Visible);
2985                 if (firstDisplayedRowIndex != -1)
2986                 {
2987                     if ((this.Rows.GetRowState(firstDisplayedRowIndex) & DataGridViewElementStates.Frozen) == 0 &&
2988                         this.displayedBandsInfo.FirstDisplayedScrollingRow >= 0)
2989                     {
2990                         firstDisplayedRowIndex = this.displayedBandsInfo.FirstDisplayedScrollingRow;
2991                     }
2992                 }
2993 #if FALSE //DEBUG
2994                 int firstDisplayedRowIndexDbg1 = this.Rows.GetFirstRow(DataGridViewElementStates.Displayed);
2995  
2996                 int firstDisplayedRowIndexDbg2 = this.Rows.GetFirstRow(DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen);
2997                 if (firstDisplayedRowIndexDbg2 == -1)
2998                 {
2999                     if (this.displayedBandsInfo.FirstDisplayedScrollingRow >= 0)
3000                     {
3001                         firstDisplayedRowIndexDbg2 = this.displayedBandsInfo.FirstDisplayedScrollingRow;
3002                     }
3003                 }
3004  
3005                 Debug.Assert(firstDisplayedRowIndex == firstDisplayedRowIndexDbg1 || !this.Visible || this.displayedBandsInfo.Dirty, "firstDisplayedRowIndex =" + firstDisplayedRowIndex.ToString() + ", firstDisplayedRowIndexDbg1=" + firstDisplayedRowIndexDbg1.ToString());
3006                 Debug.Assert(firstDisplayedRowIndex == firstDisplayedRowIndexDbg2 || this.displayedBandsInfo.Dirty, "firstDisplayedRowIndex =" + firstDisplayedRowIndex.ToString() + ", firstDisplayedRowIndexDbg2=" + firstDisplayedRowIndexDbg2.ToString());
3007 #endif
3008                 return firstDisplayedRowIndex;
3009             }
3010         }
3011  
3012         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.FirstDisplayedScrollingColumnHiddenWidth"]/*‘ />
3013         [
3014             Browsable(false),
3015             EditorBrowsable(EditorBrowsableState.Advanced),
3016             DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
3017         ]
3018         public int FirstDisplayedScrollingColumnHiddenWidth
3019         {
3020             get
3021             {
3022                 return this.negOffset;
3023             }
3024         }
3025  
3026         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.FirstDisplayedScrollingColumnIndex"]/*‘ />
3027         [
3028             Browsable(false),
3029             DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
3030         ]
3031         public int FirstDisplayedScrollingColumnIndex
3032         {
3033             get
3034             {
3035                 return this.displayedBandsInfo.FirstDisplayedScrollingCol;
3036             }
3037             set
3038             {
3039                 if (value < 0 || value >= this.Columns.Count)
3040                 {
3041                     throw new ArgumentOutOfRangeException("value");
3042                 }
3043                 if (!this.Columns[value].Visible)
3044                 {
3045                     throw new InvalidOperationException(SR.GetString(SR.DataGridView_FirstDisplayedScrollingColumnCannotBeInvisible));
3046                 }
3047                 if (this.Columns[value].Frozen)
3048                 {
3049                     throw new InvalidOperationException(SR.GetString(SR.DataGridView_FirstDisplayedScrollingColumnCannotBeFrozen));
3050                 }
3051  
3052                 if (!this.IsHandleCreated)
3053                 {
3054                     CreateHandle();
3055                 }
3056  
3057                 int displayWidth = this.layout.Data.Width;
3058                 if (displayWidth <= 0)
3059                 {
3060                     throw new InvalidOperationException(SR.GetString(SR.DataGridView_NoRoomForDisplayedColumns));
3061                 }
3062  
3063                 int totalVisibleFrozenWidth = this.Columns.GetColumnsWidth(DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen);
3064                 if (totalVisibleFrozenWidth >= displayWidth)
3065                 {
3066                     Debug.Assert(totalVisibleFrozenWidth > 0);
3067                     throw new InvalidOperationException(SR.GetString(SR.DataGridView_FrozenColumnsPreventFirstDisplayedScrollingColumn));
3068                 }
3069  
3070                 if (value == this.displayedBandsInfo.FirstDisplayedScrollingCol)
3071                 {
3072                     return;
3073                 }
3074  
3075                 if (this.ptCurrentCell.X >= 0 && 
3076                     !CommitEdit(DataGridViewDataErrorContexts.Parsing | DataGridViewDataErrorContexts.Commit | DataGridViewDataErrorContexts.Scroll, 
3077                                 false /*forCurrentCellChange*/, false /*forCurrentRowChange*/))
3078                 {
3079                     // Could not commit edited cell value - return silently
3080                     // [....]: should we throw an error here?
3081                     return;
3082                 }
3083                 if (IsColumnOutOfBounds(value))
3084                 {
3085                     return;
3086                 }
3087                 bool success = ScrollColumnIntoView(value, -1, /*committed*/ true, false /*forCurrentCellChange*/);
3088                 Debug.Assert(success);
3089  
3090                 Debug.Assert(this.displayedBandsInfo.FirstDisplayedScrollingCol >= 0);
3091                 Debug.Assert(this.displayedBandsInfo.FirstDisplayedScrollingCol == value ||
3092                              this.Columns.DisplayInOrder(this.displayedBandsInfo.FirstDisplayedScrollingCol, value));
3093                 int maxHorizontalOffset = this.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - displayWidth;
3094                 while (this.displayedBandsInfo.FirstDisplayedScrollingCol != value &&
3095                         this.HorizontalOffset < maxHorizontalOffset)
3096                 {
3097                     ScrollColumns(1);
3098                 }
3099             }
3100         }
3101  
3102         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.FirstDisplayedScrollingRowIndex"]/*‘ />
3103         [
3104             Browsable(false),
3105             DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
3106         ]
3107         public int FirstDisplayedScrollingRowIndex
3108         {
3109             get
3110             {
3111                 return this.displayedBandsInfo.FirstDisplayedScrollingRow;
3112             }
3113             set
3114             {
3115                 if (value < 0 || value >= this.Rows.Count)
3116                 {
3117                     throw new ArgumentOutOfRangeException("value");
3118                 }
3119                 if ((this.Rows.GetRowState(value) & DataGridViewElementStates.Visible) == 0)
3120                 {
3121                     throw new InvalidOperationException(SR.GetString(SR.DataGridView_FirstDisplayedScrollingRowCannotBeInvisible));
3122                 }
3123                 if ((this.Rows.GetRowState(value) & DataGridViewElementStates.Frozen) != 0)
3124                 {
3125                     throw new InvalidOperationException(SR.GetString(SR.DataGridView_FirstDisplayedScrollingRowCannotBeFrozen));
3126                 }
3127  
3128                 if (!this.IsHandleCreated)
3129                 {
3130                     CreateHandle();
3131                 }
3132  
3133                 int displayHeight = this.layout.Data.Height;
3134                 if (displayHeight <= 0)
3135                 {
3136                     throw new InvalidOperationException(SR.GetString(SR.DataGridView_NoRoomForDisplayedRows));
3137                 }
3138  
3139                 int totalVisibleFrozenHeight = this.Rows.GetRowsHeight(DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen);
3140                 if (totalVisibleFrozenHeight >= displayHeight)
3141                 {
3142                     Debug.Assert(totalVisibleFrozenHeight > 0);
3143                     throw new InvalidOperationException(SR.GetString(SR.DataGridView_FrozenRowsPreventFirstDisplayedScrollingRow));
3144                 }
3145  
3146                 if (value == this.displayedBandsInfo.FirstDisplayedScrollingRow)
3147                 {
3148                     return;
3149                 }
3150  
3151                 if (this.ptCurrentCell.X >= 0 &&
3152                     !CommitEdit(DataGridViewDataErrorContexts.Parsing | DataGridViewDataErrorContexts.Commit | DataGridViewDataErrorContexts.Scroll, 
3153                                 false /*forCurrentCellChange*/, false /*forCurrentRowChange*/))
3154                 {
3155                     // Could not commit edited cell value - return silently
3156                     // [....]: should we throw an error here?
3157                     return;
3158                 }
3159                 if (IsRowOutOfBounds(value))
3160                 {
3161                     return;
3162                 }
3163  
3164                 Debug.Assert(this.displayedBandsInfo.FirstDisplayedScrollingRow >= 0);
3165  
3166                 if (value > this.displayedBandsInfo.FirstDisplayedScrollingRow)
3167                 {
3168                     int rowsToScroll = this.Rows.GetRowCount(DataGridViewElementStates.Visible, this.displayedBandsInfo.FirstDisplayedScrollingRow, value);
3169                     Debug.Assert(rowsToScroll != 0);
3170                     ScrollRowsByCount(rowsToScroll, rowsToScroll > 1 ? ScrollEventType.LargeIncrement : ScrollEventType.SmallIncrement);
3171                 }
3172                 else
3173                 {
3174                     bool success = ScrollRowIntoView(-1, value, /*committed*/ true, false /*forCurrentCellChange*/);
3175                     Debug.Assert(success);
3176                 }
3177             }
3178         }
3179  
3180         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ForeColor"]/*‘ />
3181         /// <internalonly/>
3182         [
3183             Browsable(false),
3184             EditorBrowsable(EditorBrowsableState.Advanced),
3185             DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
3186         ]
3187         public override Color ForeColor
3188         {
3189             get 
3190             {
3191                 return base.ForeColor;
3192             }
3193             set 
3194             {
3195                 base.ForeColor = value;
3196             }
3197         }
3198  
3199         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ForeColorChanged"]/*‘ />
3200         /// <internalonly/>
3201         [
3202             Browsable(false),
3203             EditorBrowsable(EditorBrowsableState.Advanced)
3204         ]
3205         new public event EventHandler ForeColorChanged
3206         {
3207             add
3208             {
3209                 base.ForeColorChanged += value;
3210             }
3211             remove
3212             {
3213                 base.ForeColorChanged -= value;
3214             }
3215         }
3216  
3217         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.Font"]/*‘ />
3218         /// <internalonly/>
3219         [
3220             Browsable(false), 
3221             EditorBrowsable(EditorBrowsableState.Advanced)
3222         ]
3223         public override Font Font
3224         {
3225             get 
3226             {
3227                 return base.Font;
3228             }
3229             set 
3230             {
3231                 base.Font = value;
3232             }
3233         }
3234  
3235         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.FontChanged"]/*‘ />
3236         /// <internalonly/>
3237         [
3238             Browsable(false),
3239             EditorBrowsable(EditorBrowsableState.Advanced)
3240         ]
3241         new public event EventHandler FontChanged
3242         {
3243             add
3244             {
3245                 base.FontChanged += value;
3246             }
3247             remove
3248             {
3249                 base.FontChanged -= value;
3250             }
3251         }
3252  
3253         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.GridColor"]/*‘ />
3254         /// <devdoc>
3255         ///    <para>Gets or sets the grid color of the dataGridView (when Single mode is used).</para>
3256         /// </devdoc>
3257         [
3258             SRCategory(SR.CatAppearance),
3259             SRDescription(SR.DataGridViewGridColorDescr)
3260         ]
3261         public Color GridColor
3262         {
3263             get
3264             {
3265                 return this.gridPen.Color;
3266             }
3267             set
3268             {
3269                 if (value.IsEmpty)
3270                 {
3271                     throw new ArgumentException(SR.GetString(SR.DataGridView_EmptyColor, "GridColor"));
3272                 }
3273                 if (value.A < 255)
3274                 {
3275                     throw new ArgumentException(SR.GetString(SR.DataGridView_TransparentColor, "GridColor"));
3276                 }
3277                 if (!value.Equals(this.gridPen.Color)) 
3278                 {
3279                     if (this.gridPen != null)
3280                     {
3281                         this.gridPen.Dispose();
3282                     }
3283  
3284                     this.gridPen = new Pen(value);
3285                     OnGridColorChanged(EventArgs.Empty);
3286                 }
3287             }
3288         }
3289  
3290         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.GridColorChanged"]/*‘ />
3291         [
3292             SRCategory(SR.CatPropertyChanged), 
3293             SRDescription(SR.DataGridViewOnGridColorChangedDescr)
3294         ]
3295         public event EventHandler GridColorChanged 
3296         {
3297             add 
3298             {
3299                 this.Events.AddHandler(EVENT_DATAGRIDVIEWGRIDCOLORCHANGED, value);
3300             }
3301             remove 
3302             {
3303                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWGRIDCOLORCHANGED, value);
3304             }
3305         }
3306  
3307         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ShouldSerializeGridColor"]/*‘ />
3308         private bool ShouldSerializeGridColor()
3309         {
3310             return !this.GridPen.Color.Equals(DefaultGridColor);
3311         }
3312  
3313         internal Pen GridPen
3314         {
3315             get
3316             {
3317                 return this.gridPen;
3318             }
3319         }
3320  
3321         internal int HorizontalOffset 
3322         {
3323             get 
3324             {
3325                 return this.horizontalOffset;
3326             }
3327             set 
3328             {
3329                 if (value < 0)
3330                 {
3331                     value = 0;
3332                 }
3333                 int widthNotVisible = this.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - this.layout.Data.Width;
3334                 if (value > widthNotVisible && widthNotVisible > 0)
3335                 {
3336                     value = widthNotVisible;
3337                 }
3338                 if (value == this.horizontalOffset)
3339                 {
3340                     return;
3341                 }
3342  
3343                 ScrollEventType scrollEventType;
3344                 int oldFirstVisibleScrollingCol = this.displayedBandsInfo.FirstDisplayedScrollingCol;
3345                 int change = this.horizontalOffset - value;
3346                 if (this.horizScrollBar.Enabled)
3347                 {
3348                     this.horizScrollBar.Value = value;
3349                 }
3350                 this.horizontalOffset = value;
3351  
3352                 int totalVisibleFrozenWidth = this.Columns.GetColumnsWidth(DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen);
3353  
3354                 Rectangle rectTmp = this.layout.Data;
3355                 if (this.layout.ColumnHeadersVisible)
3356                 {
3357                     // column headers must scroll as well
3358                     rectTmp = Rectangle.Union(rectTmp, this.layout.ColumnHeaders);
3359                 }
3360                 else if (this.SingleVerticalBorderAdded)
3361                 {
3362                     if (!this.RightToLeftInternal)
3363                     {
3364                         rectTmp.X--;
3365                     }
3366                     rectTmp.Width++;
3367                 }
3368  
3369                 if (this.SingleVerticalBorderAdded &&
3370                     totalVisibleFrozenWidth > 0)
3371                 {
3372                     if (!this.RightToLeftInternal)
3373                     {
3374                         rectTmp.X++;
3375                     }
3376                     rectTmp.Width--;
3377                 }
3378  
3379                 if (!this.RightToLeftInternal)
3380                 {
3381                     rectTmp.X += totalVisibleFrozenWidth;
3382                 }
3383                 rectTmp.Width -= totalVisibleFrozenWidth;
3384  
3385                 this.displayedBandsInfo.FirstDisplayedScrollingCol = ComputeFirstVisibleScrollingColumn();
3386                 // update the lastTotallyDisplayedScrollingCol
3387                 ComputeVisibleColumns();
3388  
3389                 if (this.editingControl != null && 
3390                     !this.Columns[this.ptCurrentCell.X].Frozen &&
3391                     this.displayedBandsInfo.FirstDisplayedScrollingCol > -1)
3392                 {
3393                     PositionEditingControl(true /*setLocation*/, false /*setSize*/, false /*setFocus*/);
3394                 }
3395  
3396                 // The mouse probably is not over the same cell after the scroll.
3397                 UpdateMouseEnteredCell(null /*HitTestInfo*/, null /*MouseEventArgs*/);
3398  
3399                 if (oldFirstVisibleScrollingCol == this.displayedBandsInfo.FirstDisplayedScrollingCol)
3400                 {
3401                     scrollEventType = change > 0 ? ScrollEventType.SmallIncrement : ScrollEventType.SmallDecrement;
3402                 }
3403                 else if (this.Columns.DisplayInOrder(oldFirstVisibleScrollingCol, this.displayedBandsInfo.FirstDisplayedScrollingCol))
3404                 {
3405                     scrollEventType = this.Columns.GetColumnCount(DataGridViewElementStates.Visible, oldFirstVisibleScrollingCol, this.displayedBandsInfo.FirstDisplayedScrollingCol) > 1 ? ScrollEventType.LargeIncrement : ScrollEventType.SmallIncrement;
3406                 }
3407                 else
3408                 {
3409                     Debug.Assert(this.Columns.DisplayInOrder(this.displayedBandsInfo.FirstDisplayedScrollingCol, oldFirstVisibleScrollingCol));
3410                     scrollEventType = this.Columns.GetColumnCount(DataGridViewElementStates.Visible, this.displayedBandsInfo.FirstDisplayedScrollingCol, oldFirstVisibleScrollingCol) > 1 ? ScrollEventType.LargeDecrement : ScrollEventType.SmallDecrement;
3411                 }
3412  
3413                 NativeMethods.RECT[] rects = CreateScrollableRegion(rectTmp);
3414                 if (this.RightToLeftInternal)
3415                 {
3416                     change = -change;
3417                 }
3418                 ScrollRectangles(rects, change);
3419                 if (!this.dataGridViewState2[DATAGRIDVIEWSTATE2_stopRaisingHorizontalScroll])
3420                 {
3421                     OnScroll(scrollEventType, this.horizontalOffset + change, this.horizontalOffset, ScrollOrientation.HorizontalScroll);
3422                 }
3423                 FlushDisplayedChanged();
3424             }
3425         }
3426  
3427         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.HorizontalScrollBar"]/*‘ />
3428         protected ScrollBar HorizontalScrollBar
3429         {
3430             get
3431             {
3432                 return this.horizScrollBar;
3433             }
3434         }
3435  
3436         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.HorizontalScrollingOffset"]/*‘ />
3437         [
3438             Browsable(false),
3439             DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
3440         ]
3441         public int HorizontalScrollingOffset
3442         {
3443             get
3444             {
3445                 return this.horizontalOffset;
3446             }
3447             set
3448             {
3449                 // int widthNotVisible = this.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - this.layout.Data.Width;
3450                 if (value < 0)
3451                 {
3452                     throw new ArgumentOutOfRangeException("HorizontalScrollingOffset", SR.GetString(SR.InvalidLowBoundArgumentEx, "HorizontalScrollingOffset", (value).ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture)));
3453                 }
3454                 // Intentionally ignoring the out of range situation. 
3455                 // else if (value > widthNotVisible && widthNotVisible > 0)
3456                 //{
3457                 //    throw new ArgumentOutOfRangeException(SR.GetString(SR.DataGridView_PropertyTooLarge, "HorizontalScrollingOffset", (widthNotVisible).ToString()));
3458                 //}
3459                 else if (value > 0 && (this.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - this.layout.Data.Width) <= 0)
3460                 {
3461                     // Intentionally ignoring the case where dev tries to set value while there is no horizontal scrolling possible.
3462                     // throw new ArgumentOutOfRangeException("HorizontalScrollingOffset", SR.GetString(SR.DataGridView_PropertyMustBeZero));
3463                     Debug.Assert(this.horizontalOffset == 0);
3464                     return;
3465                 }
3466                 if (value == this.horizontalOffset)
3467                 {
3468                     return;
3469                 }
3470                 this.HorizontalOffset = value;
3471             }
3472         }
3473  
3474         private System.Windows.Forms.Timer HorizScrollTimer
3475         {
3476             get
3477             {
3478                 if (this.horizScrollTimer == null)
3479                 {
3480                     this.horizScrollTimer = new System.Windows.Forms.Timer();
3481                     this.horizScrollTimer.Tick += new System.EventHandler(HorizScrollTimer_Tick);
3482                 }
3483                 return this.horizScrollTimer;
3484             }
3485         }
3486  
3487         private bool InAdjustFillingColumns
3488         {
3489             get
3490             {
3491                 return this.dataGridViewOper[DATAGRIDVIEWOPER_inAdjustFillingColumn] || this.dataGridViewOper[DATAGRIDVIEWOPER_inAdjustFillingColumns];
3492             }
3493         }
3494  
3495         internal bool InBeginEdit
3496         {
3497             get
3498             {
3499                 return this.dataGridViewOper[DATAGRIDVIEWOPER_inBeginEdit];
3500             }
3501         }
3502  
3503         internal bool InDisplayIndexAdjustments
3504         {
3505             get
3506             {
3507                 return this.dataGridViewOper[DATAGRIDVIEWOPER_inDisplayIndexAdjustments];
3508             }
3509             set
3510             {
3511                 this.dataGridViewOper[DATAGRIDVIEWOPER_inDisplayIndexAdjustments] = value;
3512             }
3513         }
3514  
3515         internal bool InEndEdit
3516         {
3517             get
3518             {
3519                 return this.dataGridViewOper[DATAGRIDVIEWOPER_inEndEdit];
3520             }
3521         }
3522  
3523         private DataGridViewCellStyle InheritedEditingCellStyle
3524         {
3525             get
3526             {
3527                 if (this.ptCurrentCell.X == -1)
3528                 {
3529                     return null;
3530                 }
3531  
3532                 return this.CurrentCellInternal.GetInheritedStyleInternal(this.ptCurrentCell.Y);
3533             }
3534         }
3535  
3536         internal bool InInitialization
3537         {
3538             get
3539             {
3540                 return this.dataGridViewState2[DATAGRIDVIEWSTATE2_initializing];
3541             }
3542         }
3543  
3544         internal bool InSortOperation
3545         {
3546             get
3547             {
3548                 return this.dataGridViewOper[DATAGRIDVIEWOPER_inSort];
3549             }
3550         }
3551  
3552         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.IsCurrentCellDirty"]/*‘ />
3553         [Browsable(false)]
3554         public bool IsCurrentCellDirty
3555         {
3556             get
3557             {
3558                 return this.dataGridViewState1[DATAGRIDVIEWSTATE1_editedCellChanged];
3559             }
3560         }
3561  
3562         private bool IsCurrentCellDirtyInternal
3563         {
3564             set
3565             {
3566                 if (value != this.dataGridViewState1[DATAGRIDVIEWSTATE1_editedCellChanged])
3567                 {
3568                     this.dataGridViewState1[DATAGRIDVIEWSTATE1_editedCellChanged] = value;
3569                     OnCurrentCellDirtyStateChanged(EventArgs.Empty);
3570                 }
3571             }
3572         }
3573  
3574         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.IsCurrentCellInEditMode"]/*‘ />
3575         [Browsable(false)]
3576         public bool IsCurrentCellInEditMode
3577         {
3578             get
3579             {
3580                 return this.editingControl != null || this.dataGridViewState1[DATAGRIDVIEWSTATE1_currentCellInEditMode];
3581             }
3582         }
3583  
3584         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.IsCurrentRowDirty"]/*‘ />
3585         // Only used in bound scenarios, when binding to a IEditableObject
3586         [Browsable(false)]
3587         public bool IsCurrentRowDirty
3588         {
3589             get
3590             {
3591                 if (!this.VirtualMode)
3592                 {
3593                     return this.dataGridViewState1[DATAGRIDVIEWSTATE1_editedRowChanged] || this.IsCurrentCellDirty;
3594                 }
3595                 else
3596                 {
3597                     QuestionEventArgs qe = new QuestionEventArgs(this.dataGridViewState1[DATAGRIDVIEWSTATE1_editedRowChanged] || this.IsCurrentCellDirty);
3598                     OnRowDirtyStateNeeded(qe);
3599                     return qe.Response;
3600                 }
3601             }
3602         }
3603  
3604         internal bool IsCurrentRowDirtyInternal
3605         {
3606             set
3607             {
3608                 if (value != this.dataGridViewState1[DATAGRIDVIEWSTATE1_editedRowChanged])
3609                 {
3610                     this.dataGridViewState1[DATAGRIDVIEWSTATE1_editedRowChanged] = value;
3611                     if (this.RowHeadersVisible && this.ShowEditingIcon && this.ptCurrentCell.Y >= 0)
3612                     {
3613                         // Force the pencil to appear in the row header
3614                         InvalidateCellPrivate(-1, this.ptCurrentCell.Y);
3615                     }
3616                 }
3617             }
3618         }
3619  
3620         private bool IsEscapeKeyEffective
3621         {
3622             get
3623             {
3624                 return this.dataGridViewOper[DATAGRIDVIEWOPER_trackColResize] ||
3625                        this.dataGridViewOper[DATAGRIDVIEWOPER_trackRowResize] ||
3626                        this.dataGridViewOper[DATAGRIDVIEWOPER_trackColHeadersResize] ||
3627                        this.dataGridViewOper[DATAGRIDVIEWOPER_trackRowHeadersResize] ||
3628                        this.dataGridViewOper[DATAGRIDVIEWOPER_trackColRelocation] ||
3629                        this.IsCurrentCellDirty ||
3630                        ((this.VirtualMode || this.DataSource != null) && this.IsCurrentRowDirty) ||
3631                        (this.EditMode != DataGridViewEditMode.EditOnEnter && this.editingControl != null ||
3632                        this.dataGridViewState1[DATAGRIDVIEWSTATE1_newRowEdited]);
3633             }
3634         }
3635  
3636         private bool IsMinimized
3637         {
3638             get
3639             {
3640                 Form parentForm = this.TopLevelControlInternal as Form;
3641                 return parentForm != null && parentForm.WindowState == FormWindowState.Minimized;
3642             }
3643         }
3644  
3645         internal bool IsRestricted
3646         {
3647             get
3648             {
3649                 if (!this.dataGridViewState1[DATAGRIDVIEWSTATE1_isRestrictedChecked])
3650                 {
3651                     this.dataGridViewState1[DATAGRIDVIEWSTATE1_isRestricted] = false;
3652                     try
3653                     {
3654                         IntSecurity.AllWindows.Demand();
3655                     }
3656                     catch (SecurityException)
3657                     {
3658                         this.dataGridViewState1[DATAGRIDVIEWSTATE1_isRestricted] = true;
3659                     }
3660                     catch
3661                     {
3662                         this.dataGridViewState1[DATAGRIDVIEWSTATE1_isRestricted] = true; // To be on the safe side
3663                         this.dataGridViewState1[DATAGRIDVIEWSTATE1_isRestrictedChecked] = true;
3664                         throw;
3665                     }
3666                     this.dataGridViewState1[DATAGRIDVIEWSTATE1_isRestrictedChecked] = true;
3667                 }
3668                 return this.dataGridViewState1[DATAGRIDVIEWSTATE1_isRestricted];
3669             }
3670         }
3671  
3672         private bool IsSharedCellReadOnly(DataGridViewCell dataGridViewCell, int rowIndex)
3673         {
3674             Debug.Assert(dataGridViewCell != null);
3675             Debug.Assert(rowIndex >= 0);
3676             DataGridViewElementStates rowState = this.Rows.GetRowState(rowIndex); 
3677             return this.ReadOnly ||
3678                    (rowState & DataGridViewElementStates.ReadOnly) != 0 ||
3679                    (dataGridViewCell.OwningColumn != null && dataGridViewCell.OwningColumn.ReadOnly) ||
3680                    dataGridViewCell.StateIncludes(DataGridViewElementStates.ReadOnly);
3681         }
3682  
3683         internal bool IsSharedCellSelected(DataGridViewCell dataGridViewCell, int rowIndex)
3684         {
3685             Debug.Assert(dataGridViewCell != null);
3686             Debug.Assert(rowIndex >= 0);
3687             DataGridViewElementStates rowState = this.Rows.GetRowState(rowIndex);
3688             return (rowState & DataGridViewElementStates.Selected) != 0 ||
3689                    (dataGridViewCell.OwningColumn != null && dataGridViewCell.OwningColumn.Selected) ||
3690                    dataGridViewCell.StateIncludes(DataGridViewElementStates.Selected);
3691         }
3692  
3693         internal bool IsSharedCellVisible(DataGridViewCell dataGridViewCell, int rowIndex)
3694         {
3695             Debug.Assert(dataGridViewCell != null);
3696             Debug.Assert(rowIndex >= 0);
3697             DataGridViewElementStates rowState = this.Rows.GetRowState(rowIndex);
3698             return (rowState & DataGridViewElementStates.Visible) != 0 &&
3699                    (dataGridViewCell.OwningColumn != null && dataGridViewCell.OwningColumn.Visible);
3700         }
3701  
3702         internal LayoutData LayoutInfo
3703         {
3704             get
3705             {
3706                 if (this.layout.dirty && this.IsHandleCreated)
3707                 {
3708                     PerformLayoutPrivate(false /*useRowShortcut*/, true /*computeVisibleRows*/, false /*invalidInAdjustFillingColumns*/, false /*repositionEditingControl*/);
3709                 }
3710                 return this.layout;
3711             }
3712         }
3713  
3714         internal Point MouseDownCellAddress
3715         {
3716             get
3717             {
3718                 return this.ptMouseDownCell;
3719             }
3720         }
3721  
3722         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.MultiSelect"]/*‘ />
3723         [
3724             SRCategory(SR.CatBehavior),
3725             DefaultValue(true),
3726             SRDescription(SR.DataGridView_MultiSelectDescr)
3727         ]
3728         public bool MultiSelect
3729         {
3730             get
3731             {
3732                 return this.dataGridViewState1[DATAGRIDVIEWSTATE1_multiSelect];
3733             }
3734             set
3735             {
3736                 if (this.MultiSelect != value)
3737                 {
3738                     ClearSelection();
3739                     this.dataGridViewState1[DATAGRIDVIEWSTATE1_multiSelect] = value;
3740                     OnMultiSelectChanged(EventArgs.Empty);
3741                 }
3742             }
3743         }
3744  
3745         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.MultiSelectChanged"]/*‘ />
3746         [
3747             SRCategory(SR.CatPropertyChanged), 
3748             SRDescription(SR.DataGridViewOnMultiSelectChangedDescr)
3749         ]
3750         public event EventHandler MultiSelectChanged
3751         {
3752             add
3753             {
3754                 this.Events.AddHandler(EVENT_DATAGRIDVIEWMULTISELECTCHANGED, value);
3755             }
3756             remove
3757             {
3758                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWMULTISELECTCHANGED, value);
3759             }
3760         }
3761  
3762         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.NewRowIndex"]/*‘ />
3763         [
3764             Browsable(false),
3765             DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
3766         ]
3767         public int NewRowIndex
3768         {
3769             get
3770             {
3771                 return this.newRowIndex;
3772             }
3773         }
3774  
3775         internal bool NoDimensionChangeAllowed
3776         {
3777             get
3778             {
3779                 return this.noDimensionChangeCount > 0;
3780             }
3781         }
3782  
3783         private int NoSelectionChangeCount
3784         {
3785             get
3786             {
3787                 return this.noSelectionChangeCount;
3788             }
3789             set
3790             {
3791                 Debug.Assert(value >= 0);
3792                 this.noSelectionChangeCount = value;
3793                 if (value == 0)
3794                 {
3795                     FlushSelectionChanged();
3796                 }
3797             }
3798         }
3799  
3800         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.Padding"]/*‘ />
3801         [
3802             Browsable(false),
3803             EditorBrowsable(EditorBrowsableState.Never),
3804             DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
3805         ]
3806         public new Padding Padding 
3807         {
3808             get 
3809             { 
3810                 return base.Padding; 
3811             }
3812             set 
3813             { 
3814                 base.Padding = value;
3815             }        
3816         }
3817  
3818         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.PaddingChanged"]/*‘ />
3819         [
3820             Browsable(false),
3821             EditorBrowsable(EditorBrowsableState.Never),
3822             DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
3823         ]
3824         public new event EventHandler PaddingChanged
3825         {
3826             add
3827             {
3828                 base.PaddingChanged += value;
3829             }
3830             remove
3831             {
3832                 base.PaddingChanged -= value;
3833             }
3834         }
3835  
3836         internal DataGridViewCellStyle PlaceholderCellStyle
3837         {
3838             get
3839             {
3840                 if (this.placeholderCellStyle == null)
3841                 {
3842                     this.placeholderCellStyle = new DataGridViewCellStyle();
3843                 }
3844                 return this.placeholderCellStyle;
3845             }
3846         }
3847  
3848         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ReadOnly"]/*‘ />
3849         [
3850             Browsable(true),
3851             DefaultValue(false),
3852             SRCategory(SR.CatBehavior),
3853             SRDescription(SR.DataGridView_ReadOnlyDescr)
3854         ]
3855         public bool ReadOnly
3856         {
3857             get
3858             {
3859                 return this.dataGridViewState1[DATAGRIDVIEWSTATE1_readOnly];
3860             }
3861             set
3862             {
3863                 if (value != this.dataGridViewState1[DATAGRIDVIEWSTATE1_readOnly])
3864                 {
3865                     if (value &&
3866                         this.ptCurrentCell.X != -1 &&
3867                         this.IsCurrentCellInEditMode)
3868                     {
3869                         // Current cell becomes read-only. Exit editing mode.
3870                         if (!EndEdit(DataGridViewDataErrorContexts.Parsing | DataGridViewDataErrorContexts.Commit,
3871                                      DataGridViewValidateCellInternal.Always /*validateCell*/, 
3872                                      false /*fireCellLeave*/,
3873                                      false /*fireCellEnter*/,
3874                                      false /*fireRowLeave*/,
3875                                      false /*fireRowEnter*/,
3876                                      false /*fireLeave*/, 
3877                                      true /*keepFocus*/,
3878                                      false /*resetCurrentCell*/,
3879                                      false /*resetAnchorCell*/))
3880                         {
3881                             throw new InvalidOperationException(SR.GetString(SR.DataGridView_CommitFailedCannotCompleteOperation));
3882                         }
3883                     }
3884  
3885                     this.dataGridViewState1[DATAGRIDVIEWSTATE1_readOnly] = value;
3886  
3887                     if (value)
3888                     {
3889                         try
3890                         {
3891                             this.dataGridViewOper[DATAGRIDVIEWOPER_inReadOnlyChange] = true;
3892                             for (int columnIndex = 0; columnIndex < this.Columns.Count; columnIndex++)
3893                             {
3894                                 SetReadOnlyColumnCore(columnIndex, false);
3895                             }
3896                             int rowCount = this.Rows.Count;
3897                             for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
3898                             {
3899                                 SetReadOnlyRowCore(rowIndex, false);
3900                             }
3901                         }
3902                         finally
3903                         {
3904                             this.dataGridViewOper[DATAGRIDVIEWOPER_inReadOnlyChange] = false;
3905                         }
3906                     }
3907 #if DEBUG
3908                     else
3909                     {
3910                         Debug.Assert(this.individualReadOnlyCells.Count == 0);
3911                         for (int columnIndex = 0; columnIndex < this.Columns.Count; columnIndex++)
3912                         {
3913                             Debug.Assert(this.Columns[columnIndex].ReadOnly == false);
3914                         }
3915                         int rowCount = this.Rows.Count;
3916                         for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
3917                         {
3918                             Debug.Assert((this.Rows.GetRowState(rowIndex) & DataGridViewElementStates.ReadOnly) == 0);
3919                         }
3920                     }
3921 #endif
3922                     OnReadOnlyChanged(EventArgs.Empty);
3923                 }
3924             }
3925         }
3926  
3927         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ReadOnlyChanged"]/*‘ />
3928         [
3929             SRCategory(SR.CatPropertyChanged), 
3930             SRDescription(SR.DataGridViewOnReadOnlyChangedDescr)
3931         ]
3932         public event EventHandler ReadOnlyChanged
3933         {
3934             add
3935             {
3936                 this.Events.AddHandler(EVENT_DATAGRIDVIEWREADONLYCHANGED, value);
3937             }
3938             remove
3939             {
3940                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWREADONLYCHANGED, value);
3941             }
3942         }
3943  
3944         private void ResetCurrentCell()
3945         {
3946             if (this.ptCurrentCell.X != -1 &&
3947                 !SetCurrentCellAddressCore(-1, -1, true /*setAnchorCellAddress*/, true /*validateCurrentCell*/, false /*throughMouseClick*/))
3948             {
3949                 // Edited value couldn‘t be committed or aborted
3950                 throw new InvalidOperationException(SR.GetString(SR.DataGridView_CellChangeCannotBeCommittedOrAborted));
3951             }
3952         }
3953  
3954         internal bool ResizingOperationAboutToStart
3955         {
3956             get
3957             {
3958                 return this.dataGridViewOper[DATAGRIDVIEWOPER_resizingOperationAboutToStart];
3959             }
3960         }
3961  
3962         internal bool RightToLeftInternal
3963         {
3964             get
3965             {
3966                 if (this.dataGridViewState2[DATAGRIDVIEWSTATE2_rightToLeftValid])
3967                 {
3968                     return this.dataGridViewState2[DATAGRIDVIEWSTATE2_rightToLeftMode];
3969                 }
3970                 this.dataGridViewState2[DATAGRIDVIEWSTATE2_rightToLeftMode] = (this.RightToLeft == RightToLeft.Yes);
3971                 this.dataGridViewState2[DATAGRIDVIEWSTATE2_rightToLeftValid] = true;
3972                 return this.dataGridViewState2[DATAGRIDVIEWSTATE2_rightToLeftMode];
3973             }
3974         }
3975  
3976         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowCount"]/*‘ />
3977         [
3978             Browsable(false),
3979             DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
3980             EditorBrowsable(EditorBrowsableState.Advanced),
3981             DefaultValue(0)
3982         ]
3983         public int RowCount
3984         {
3985             get
3986             {
3987                 return this.Rows.Count;
3988             }
3989             set
3990             {
3991                 if (this.AllowUserToAddRowsInternal)
3992                 {
3993                     if (value < 1)
3994                     {
3995                         throw new ArgumentOutOfRangeException("RowCount", SR.GetString(SR.InvalidLowBoundArgumentEx, "RowCount", value.ToString(CultureInfo.CurrentCulture), (1).ToString(CultureInfo.CurrentCulture)));
3996                     }
3997                 }
3998                 else
3999                 {
4000                     if (value < 0)
4001                     {
4002                         throw new ArgumentOutOfRangeException("RowCount", SR.GetString(SR.InvalidLowBoundArgumentEx, "RowCount", value.ToString(CultureInfo.CurrentCulture), (0).ToString(CultureInfo.CurrentCulture)));
4003                     }
4004                 }
4005                 if (this.DataSource != null)
4006                 {
4007                     throw new InvalidOperationException(SR.GetString(SR.DataGridView_CannotSetRowCountOnDataBoundDataGridView));
4008                 }
4009                 if (value != this.Rows.Count)
4010                 {
4011                     if (value == 0)
4012                     {
4013                         // Total removal of the rows.
4014                         this.Rows.Clear();
4015                     }
4016                     else if (value < this.Rows.Count)
4017                     {
4018                         // Some rows need to be removed, from the tail of the rows collection
4019                         while (value < this.Rows.Count)
4020                         {
4021                             int currentRowCount = this.Rows.Count;
4022                             this.Rows.RemoveAt(currentRowCount - (this.AllowUserToAddRowsInternal ? 2 :  1));
4023                             if (this.Rows.Count >= currentRowCount)
4024                             {
4025                                 // Row removal failed. We stop the loop.
4026                                 break;
4027                             }
4028                         }
4029                     }
4030                     else
4031                     {
4032                         // Some rows need to be appened.
4033                         if (this.Columns.Count == 0)
4034                         {
4035                             // There are no columns yet, we simply create a single DataGridViewTextBoxColumn.
4036                             DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
4037                             this.Columns.Add(dataGridViewTextBoxColumn);
4038                         }
4039                         int rowsToAdd = value - this.Rows.Count;
4040                         if (rowsToAdd > 0)
4041                         {
4042                             this.Rows.Add(rowsToAdd);
4043                         }
4044                     }
4045                 }
4046             }
4047         }
4048  
4049         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowHeadersBorderStyle"]/*‘ />
4050         [
4051             SRCategory(SR.CatAppearance),
4052             SRDescription(SR.DataGridView_RowHeadersBorderStyleDescr),
4053             Browsable(true),
4054             DefaultValue(DataGridViewHeaderBorderStyle.Raised)
4055         ]
4056         public DataGridViewHeaderBorderStyle RowHeadersBorderStyle
4057         {
4058             get
4059             {
4060                 switch (this.advancedRowHeadersBorderStyle.All)
4061                 {
4062                     case DataGridViewAdvancedCellBorderStyle.NotSet:
4063                         return DataGridViewHeaderBorderStyle.Custom;
4064  
4065                     case DataGridViewAdvancedCellBorderStyle.None:
4066                         return DataGridViewHeaderBorderStyle.None;
4067  
4068                     case DataGridViewAdvancedCellBorderStyle.Single:
4069                         return DataGridViewHeaderBorderStyle.Single;
4070  
4071                     case DataGridViewAdvancedCellBorderStyle.InsetDouble:
4072                         return DataGridViewHeaderBorderStyle.Sunken;
4073  
4074                     case DataGridViewAdvancedCellBorderStyle.OutsetPartial:
4075                         return DataGridViewHeaderBorderStyle.Raised;
4076  
4077                     default:
4078                         return DataGridViewHeaderBorderStyle.Custom;
4079                 }
4080             }
4081             set
4082             {
4083                 // Sequential enum.  Valid values are 0x0 to 0x4
4084                 if (!ClientUtils.IsEnumValid(value, (int)value, (int)DataGridViewHeaderBorderStyle.Custom, (int)DataGridViewHeaderBorderStyle.None))
4085                 {
4086                     throw new InvalidEnumArgumentException("value", (int)value, typeof(DataGridViewHeaderBorderStyle)); 
4087                 }
4088  
4089                 if (value != this.RowHeadersBorderStyle)
4090                 {
4091                     if (value == DataGridViewHeaderBorderStyle.Custom)
4092                     {
4093                         throw new ArgumentException(SR.GetString(SR.DataGridView_CustomCellBorderStyleInvalid, "RowHeadersBorderStyle"));
4094                     }
4095                     this.dataGridViewOper[DATAGRIDVIEWOPER_inBorderStyleChange] = true;
4096                     try
4097                     {
4098                         switch (value)
4099                         {
4100                             case DataGridViewHeaderBorderStyle.Single:
4101                                 this.advancedRowHeadersBorderStyle.All = DataGridViewAdvancedCellBorderStyle.Single;
4102                                 break;
4103  
4104                             case DataGridViewHeaderBorderStyle.Raised:
4105                                 this.advancedRowHeadersBorderStyle.All = DataGridViewAdvancedCellBorderStyle.OutsetPartial;
4106                                 break;
4107  
4108                             case DataGridViewHeaderBorderStyle.Sunken:
4109                                 this.advancedRowHeadersBorderStyle.All = DataGridViewAdvancedCellBorderStyle.InsetDouble;
4110                                 break;
4111  
4112                             case DataGridViewHeaderBorderStyle.None:
4113                                 this.advancedRowHeadersBorderStyle.All = DataGridViewAdvancedCellBorderStyle.None;
4114                                 break;
4115                         }
4116                     }
4117                     finally
4118                     {
4119                         this.dataGridViewOper[DATAGRIDVIEWOPER_inBorderStyleChange] = false;
4120                     }
4121                     OnRowHeadersBorderStyleChanged(EventArgs.Empty);
4122                 }
4123             }
4124         }
4125  
4126         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowHeadersBorderStyleChanged"]/*‘ />
4127         [
4128             SRCategory(SR.CatPropertyChanged), 
4129             SRDescription(SR.DataGridView_RowHeadersBorderStyleChangedDescr)
4130         ]
4131         public event EventHandler RowHeadersBorderStyleChanged
4132         {
4133             add
4134             {
4135                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWHEADERSBORDERSTYLECHANGED, value);
4136             }
4137             remove
4138             {
4139                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWHEADERSBORDERSTYLECHANGED, value);
4140             }
4141         }
4142  
4143         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowHeadersDefaultCellStyle"]/*‘ />
4144         [
4145             SRCategory(SR.CatAppearance),
4146             SRDescription(SR.DataGridView_RowHeadersDefaultCellStyleDescr),
4147             AmbientValue(null)
4148         ]
4149         public DataGridViewCellStyle RowHeadersDefaultCellStyle
4150         {
4151             get 
4152             {
4153                 if (this.rowHeadersDefaultCellStyle == null)
4154                 {
4155                     this.rowHeadersDefaultCellStyle = this.DefaultRowHeadersDefaultCellStyle;
4156                 }
4157                 return this.rowHeadersDefaultCellStyle;
4158             }
4159             set 
4160             {
4161                 DataGridViewCellStyle cs = this.RowHeadersDefaultCellStyle;
4162                 cs.RemoveScope(DataGridViewCellStyleScopes.RowHeaders);
4163                 this.rowHeadersDefaultCellStyle = value;
4164                 if (value != null)
4165                 {
4166                     this.rowHeadersDefaultCellStyle.AddScope(this, DataGridViewCellStyleScopes.RowHeaders);
4167                 }
4168                 DataGridViewCellStyleDifferences dgvcsc = cs.GetDifferencesFrom(this.RowHeadersDefaultCellStyle);
4169                 if (dgvcsc != DataGridViewCellStyleDifferences.None)
4170                 {
4171                     this.CellStyleChangedEventArgs.ChangeAffectsPreferredSize = (dgvcsc == DataGridViewCellStyleDifferences.AffectPreferredSize);
4172                     OnRowHeadersDefaultCellStyleChanged(this.CellStyleChangedEventArgs);
4173                 }
4174             }
4175         }
4176  
4177         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowHeadersDefaultCellStyleChanged"]/*‘ />
4178         [
4179             SRCategory(SR.CatPropertyChanged), 
4180             SRDescription(SR.DataGridViewRowHeadersDefaultCellStyleChangedDescr)
4181         ]
4182         public event EventHandler RowHeadersDefaultCellStyleChanged
4183         {
4184             add 
4185             {
4186                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWHEADERSDEFAULTCELLSTYLECHANGED, value);
4187             }
4188             remove 
4189             {
4190                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWHEADERSDEFAULTCELLSTYLECHANGED, value);
4191             }
4192         }
4193         
4194         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowHeadersVisible"]/*‘ />
4195         /// <devdoc>
4196         ///    <para>
4197         ///       Gets or sets a value indicating whether the dataGridView‘s row headers are
4198         ///       visible.
4199         ///    </para>
4200         /// </devdoc>
4201         [
4202             SRCategory(SR.CatAppearance),
4203             DefaultValue(true),
4204             SRDescription(SR.DataGridViewRowHeadersVisibleDescr)
4205         ]
4206         public bool RowHeadersVisible
4207         {
4208             get 
4209             {
4210                 return this.dataGridViewState1[DATAGRIDVIEWSTATE1_rowHeadersVisible];
4211             }
4212             set 
4213             {
4214                 if (this.RowHeadersVisible != value)
4215                 {
4216                     if (!value &&
4217                         (this.autoSizeRowsMode == DataGridViewAutoSizeRowsMode.AllHeaders || this.autoSizeRowsMode == DataGridViewAutoSizeRowsMode.DisplayedHeaders))
4218                     {
4219                         throw new InvalidOperationException(SR.GetString(SR.DataGridView_RowHeadersCannotBeInvisible));
4220                     }
4221                     using (LayoutTransaction.CreateTransactionIf(this.AutoSize, this.ParentInternal, this, PropertyNames.RowHeadersVisible))
4222                     {
4223                         this.dataGridViewState1[DATAGRIDVIEWSTATE1_rowHeadersVisible] = value;
4224                         this.layout.RowHeadersVisible = value;
4225                         this.displayedBandsInfo.EnsureDirtyState();
4226                         if (!this.AutoSize)
4227                         {
4228                             PerformLayoutPrivate(false /*useRowShortcut*/, false /*computeVisibleRows*/, true /*invalidInAdjustFillingColumns*/, true /*repositionEditingControl*/);
4229                         }
4230                         InvalidateInside();
4231                         OnRowHeadersGlobalAutoSize(value /*expandingRows*/);
4232                     }
4233                 }
4234             }
4235         }
4236  
4237         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowHeadersWidth"]/*‘ />
4238         [
4239             SRCategory(SR.CatLayout),
4240             Localizable(true), 
4241             SRDescription(SR.DataGridView_RowHeadersWidthDescr)
4242         ]
4243         public int RowHeadersWidth
4244         {
4245             get 
4246             {
4247                 return this.rowHeadersWidth;
4248             }
4249             set 
4250             {
4251                 if (value < minimumRowHeadersWidth)
4252                 {
4253                     throw new ArgumentOutOfRangeException("RowHeadersWidth", SR.GetString(SR.InvalidLowBoundArgumentEx, "RowHeadersWidth", (value).ToString(CultureInfo.CurrentCulture), (minimumRowHeadersWidth).ToString(CultureInfo.CurrentCulture)));
4254                 }
4255                 if (value > maxHeadersThickness)
4256                 {
4257                     throw new ArgumentOutOfRangeException("RowHeadersWidth", SR.GetString(SR.InvalidHighBoundArgumentEx, "RowHeadersWidth", (value).ToString(CultureInfo.CurrentCulture), (maxHeadersThickness).ToString(CultureInfo.CurrentCulture)));
4258                 }
4259                 if (this.RowHeadersWidthSizeMode != DataGridViewRowHeadersWidthSizeMode.EnableResizing &&
4260                     this.RowHeadersWidthSizeMode != DataGridViewRowHeadersWidthSizeMode.DisableResizing)
4261                 {
4262                     this.cachedRowHeadersWidth = value;
4263                 }
4264                 else if (this.rowHeadersWidth != value)
4265                 {
4266                     this.RowHeadersWidthInternal = value;
4267                 }
4268             }
4269         }
4270  
4271         private int RowHeadersWidthInternal
4272         {
4273             set
4274             {
4275                 using (LayoutTransaction.CreateTransactionIf(this.AutoSize, this.ParentInternal, this, PropertyNames.RowHeadersWidth))
4276                 {
4277                     Debug.Assert(this.rowHeadersWidth != value);
4278                     Debug.Assert(value >= minimumRowHeadersWidth);
4279                     this.rowHeadersWidth = value;
4280                     if (this.AutoSize)
4281                     {
4282                         InvalidateInside();
4283                     }
4284                     else
4285                     {
4286                         if (this.layout.RowHeadersVisible)
4287                         {
4288                             PerformLayoutPrivate(false /*useRowShortcut*/, false /*computeVisibleRows*/, true /*invalidInAdjustFillingColumns*/, true /*repositionEditingControl*/);
4289                             InvalidateInside();
4290                         }
4291                     }
4292                     OnRowHeadersWidthChanged(EventArgs.Empty);
4293                 }
4294             }
4295         }
4296  
4297         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowHeadersWidthChanged"]/*‘ />
4298         [
4299             SRCategory(SR.CatPropertyChanged), 
4300             SRDescription(SR.DataGridViewRowHeadersWidthChangedDescr)
4301         ]
4302         public event EventHandler RowHeadersWidthChanged
4303         {
4304             add 
4305             {
4306                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWHEADERSWIDTHCHANGED, value);
4307             }
4308             remove 
4309             {
4310                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWHEADERSWIDTHCHANGED, value);
4311             }
4312         }
4313  
4314         private bool ShouldSerializeRowHeadersWidth()
4315         {
4316             return (this.rowHeadersWidthSizeMode == DataGridViewRowHeadersWidthSizeMode.EnableResizing || this.rowHeadersWidthSizeMode == DataGridViewRowHeadersWidthSizeMode.DisableResizing) && 
4317                    defaultRowHeadersWidth != this.RowHeadersWidth;
4318         }
4319  
4320         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowHeadersWidthSizeMode"]/*‘ />
4321         /// <devdoc>
4322         ///    <para>
4323         ///       Gets or sets a value that determines the behavior for adjusting the row headers width.
4324         ///    </para>
4325         /// </devdoc>
4326         [
4327             DefaultValue(DataGridViewRowHeadersWidthSizeMode.EnableResizing),
4328             RefreshProperties(RefreshProperties.All),
4329             SRCategory(SR.CatBehavior),
4330             SRDescription(SR.DataGridView_RowHeadersWidthSizeModeDescr)
4331         ]
4332         public DataGridViewRowHeadersWidthSizeMode RowHeadersWidthSizeMode
4333         {
4334             get
4335             {
4336                 return this.rowHeadersWidthSizeMode;
4337             }
4338             set
4339             {
4340                 // Sequential enum.  Valid values are 0x0 to 0x4
4341                 if (!ClientUtils.IsEnumValid(value, (int)value, (int)DataGridViewRowHeadersWidthSizeMode.EnableResizing, (int)DataGridViewRowHeadersWidthSizeMode.AutoSizeToFirstHeader))
4342                 {
4343                     throw new InvalidEnumArgumentException("value", (int)value, typeof(DataGridViewRowHeadersWidthSizeMode)); 
4344                 }
4345                 if (this.rowHeadersWidthSizeMode != value)
4346                 {
4347                     /*if (value != DataGridViewRowHeadersWidthSizeMode.EnableResizing && 
4348                      *    value != DataGridViewRowHeadersWidthSizeMode.DisableResizing &&
4349                      *    !this.RowHeadersVisible)
4350                     {
4351                         We intentionally don‘t throw an error because of designer code spit order.
4352                     }*/
4353                     DataGridViewAutoSizeModeEventArgs dgvasme = new DataGridViewAutoSizeModeEventArgs(this.rowHeadersWidthSizeMode != DataGridViewRowHeadersWidthSizeMode.EnableResizing &&
4354                                                                                                       this.rowHeadersWidthSizeMode != DataGridViewRowHeadersWidthSizeMode.DisableResizing);
4355                     this.rowHeadersWidthSizeMode = value;
4356                     OnRowHeadersWidthSizeModeChanged(dgvasme);
4357                 }
4358             }
4359         }
4360  
4361         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowHeadersWidthSizeModeChanged"]/*‘ />
4362         [
4363             SRCategory(SR.CatPropertyChanged), 
4364             SRDescription(SR.DataGridView_RowHeadersWidthSizeModeChangedDescr)
4365         ]
4366         public event DataGridViewAutoSizeModeEventHandler RowHeadersWidthSizeModeChanged
4367         {
4368             add
4369             {
4370                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWHEADERSWIDTHSIZEMODECHANGED, value);
4371             }
4372             remove
4373             {
4374                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWHEADERSWIDTHSIZEMODECHANGED, value);
4375             }
4376         }
4377  
4378         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.Rows"]/*‘ />
4379         [
4380             Browsable(false)
4381         ]
4382         public DataGridViewRowCollection Rows
4383         {
4384             get
4385             {
4386                 if (this.dataGridViewRows == null)
4387                 {
4388                     this.dataGridViewRows = CreateRowsInstance();
4389                 }
4390                 return this.dataGridViewRows;
4391             }
4392         }
4393  
4394         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowsDefaultCellStyle"]/*‘ />
4395         [
4396             SRCategory(SR.CatAppearance),
4397             SRDescription(SR.DataGridView_RowsDefaultCellStyleDescr)
4398         ]
4399         public DataGridViewCellStyle RowsDefaultCellStyle
4400         {
4401             get
4402             {
4403                 if (this.rowsDefaultCellStyle == null)
4404                 {
4405                     this.rowsDefaultCellStyle = new DataGridViewCellStyle();
4406                     this.rowsDefaultCellStyle.AddScope(this, DataGridViewCellStyleScopes.Rows);
4407                 }
4408                 return this.rowsDefaultCellStyle;
4409             }
4410             set
4411             {
4412                 DataGridViewCellStyle cs = this.RowsDefaultCellStyle;
4413                 cs.RemoveScope(DataGridViewCellStyleScopes.Rows);
4414                 this.rowsDefaultCellStyle = value;
4415                 if (value != null)
4416                 {
4417                     this.rowsDefaultCellStyle.AddScope(this, DataGridViewCellStyleScopes.Rows);
4418                 }
4419                 DataGridViewCellStyleDifferences dgvcsc = cs.GetDifferencesFrom(this.RowsDefaultCellStyle);
4420                 if (dgvcsc != DataGridViewCellStyleDifferences.None)
4421                 {
4422                     this.CellStyleChangedEventArgs.ChangeAffectsPreferredSize = (dgvcsc == DataGridViewCellStyleDifferences.AffectPreferredSize);
4423                     OnRowsDefaultCellStyleChanged(this.CellStyleChangedEventArgs);
4424                 }
4425             }
4426         }
4427  
4428         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowsDefaultCellStyleChanged"]/*‘ />
4429         [
4430             SRCategory(SR.CatPropertyChanged), 
4431             SRDescription(SR.DataGridViewRowsDefaultCellStyleChangedDescr)
4432         ]
4433         public event EventHandler RowsDefaultCellStyleChanged
4434         {
4435             add
4436             {
4437                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWSDEFAULTCELLSTYLECHANGED, value);
4438             }
4439             remove
4440             {
4441                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWSDEFAULTCELLSTYLECHANGED, value);
4442             }
4443         }
4444  
4445         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowTemplate"]/*‘ />
4446         [
4447             SRCategory(SR.CatAppearance),
4448             Browsable(true),
4449             SRDescription(SR.DataGridView_RowTemplateDescr),
4450             DesignerSerializationVisibility(DesignerSerializationVisibility.Content)
4451         ]
4452         public DataGridViewRow RowTemplate
4453         {
4454             get
4455             {
4456                 if (this.rowTemplate == null)
4457                 {
4458                     this.rowTemplate = new DataGridViewRow();
4459                 }
4460                 return this.rowTemplate;
4461             }
4462             set
4463             {
4464                 DataGridViewRow dataGridViewRow = value;
4465                 if (dataGridViewRow != null)
4466                 {
4467                     if (dataGridViewRow.DataGridView != null)
4468                     {
4469                         throw new InvalidOperationException(SR.GetString(SR.DataGridView_RowAlreadyBelongsToDataGridView));
4470                     }
4471                     //if (dataGridViewRow.Selected)
4472                     //{
4473                     //    throw new InvalidOperationException(SR.GetString(SR.DataGridView_RowTemplateCannotBeSelected));
4474                     //}
4475                 }
4476                 this.rowTemplate = dataGridViewRow;
4477             }
4478         }
4479  
4480         private bool ShouldSerializeRowTemplate()
4481         {
4482             return this.rowTemplate != null;
4483         }
4484  
4485         internal DataGridViewRow RowTemplateClone
4486         {
4487             get
4488             {
4489                 DataGridViewRow rowTemplateClone = (DataGridViewRow) this.RowTemplate.Clone();
4490                 CompleteCellsCollection(rowTemplateClone);
4491                 return rowTemplateClone;
4492             }
4493         }
4494  
4495         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ScrollBars"]/*‘ />
4496         /// <devdoc>
4497         ///     Possible return values are given by the ScrollBars enumeration.
4498         /// </devdoc>
4499         [
4500             DefaultValue(ScrollBars.Both), 
4501             Localizable(true), 
4502             SRCategory(SR.CatLayout), 
4503             SRDescription(SR.DataGridView_ScrollBarsDescr)
4504         ]
4505         public ScrollBars ScrollBars
4506         {
4507             get
4508             {
4509                 return this.scrollBars;
4510             }
4511             set
4512             {
4513                 // Sequential enum.  Valid values are 0x0 to 0x3
4514                 if (!ClientUtils.IsEnumValid(value, (int)value, (int)ScrollBars.None, (int)ScrollBars.Both))
4515                 {
4516                      throw new InvalidEnumArgumentException("value", (int)value, typeof(ScrollBars)); 
4517                 }
4518  
4519                 if (this.scrollBars != value)
4520                 {
4521                     using (LayoutTransaction.CreateTransactionIf(this.AutoSize, this.ParentInternal, this, PropertyNames.ScrollBars))
4522                     {
4523                         // Before changing the value of this.scrollBars, we scroll to the top-left cell to
4524                         // avoid inconsitent state of scrollbars.
4525                         DataGridViewColumn dataGridViewColumn = this.Columns.GetFirstColumn(DataGridViewElementStates.Visible);
4526                         int firstVisibleRowIndex = this.Rows.GetFirstRow(DataGridViewElementStates.Visible);
4527  
4528                         if (dataGridViewColumn != null && firstVisibleRowIndex != -1)
4529                         {
4530                             if (!ScrollIntoView(dataGridViewColumn.Index, firstVisibleRowIndex, false))
4531                             {
4532                                 throw new InvalidOperationException(SR.GetString(SR.DataGridView_CellChangeCannotBeCommittedOrAborted));
4533                             }
4534                         }
4535                         Debug.Assert(this.HorizontalOffset == 0);
4536                         Debug.Assert(this.VerticalOffset == 0);
4537  
4538                         this.scrollBars = value;
4539  
4540                         if (!this.AutoSize)
4541                         {
4542                             PerformLayoutPrivate(false /*useRowShortcut*/, false /*computeVisibleRows*/, true /*invalidInAdjustFillingColumns*/, true /*repositionEditingControl*/);
4543                         }
4544                         Invalidate();
4545                     }
4546                 }
4547             }
4548         }
4549  
4550         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.SelectedCells"]/*‘ />
4551         [
4552             Browsable(false)
4553         ]
4554         public DataGridViewSelectedCellCollection SelectedCells
4555         {
4556             [
4557                 SuppressMessage("Microsoft.Performance", "CA1817:DoNotCallPropertiesThatCloneValuesInLoops"), // not legitimate
4558                 SuppressMessage("Microsoft.Performance", "CA1808:AvoidCallsThatBoxValueTypes") // consider using generics instead of DataGridViewIntLinkedList
4559             ]
4560             get
4561             {
4562                 DataGridViewSelectedCellCollection stcc = new DataGridViewSelectedCellCollection();
4563                 switch (this.SelectionMode)
4564                 {
4565                     case DataGridViewSelectionMode.CellSelect:
4566                     {
4567                         // Note: If we change the design and decide that SelectAll() should use band selection, 
4568                         // we need to add those to the selected cells.
4569                         stcc.AddCellLinkedList(this.individualSelectedCells);
4570                         break;
4571                     }
4572                     case DataGridViewSelectionMode.FullColumnSelect:
4573                     case DataGridViewSelectionMode.ColumnHeaderSelect:
4574                     {
4575                         foreach (int columnIndex in this.selectedBandIndexes)
4576                         {
4577                             foreach (DataGridViewRow dataGridViewRow in this.Rows)   // unshares all rows!
4578                             {
4579                                 stcc.Add(dataGridViewRow.Cells[columnIndex]);
4580                             }
4581                         }
4582                         if (this.SelectionMode == DataGridViewSelectionMode.ColumnHeaderSelect)
4583                         {
4584                             stcc.AddCellLinkedList(this.individualSelectedCells);
4585                         }
4586                         break;
4587                     }
4588                     case DataGridViewSelectionMode.FullRowSelect:
4589                     case DataGridViewSelectionMode.RowHeaderSelect:
4590                     {
4591                         foreach (int rowIndex in this.selectedBandIndexes)
4592                         {
4593                             DataGridViewRow dataGridViewRow = (DataGridViewRow) this.Rows[rowIndex]; // unshares the selected row
4594                             foreach (DataGridViewCell dataGridViewCell in dataGridViewRow.Cells)
4595                             {
4596                                 stcc.Add(dataGridViewCell);
4597                             }
4598                         }
4599                         if (this.SelectionMode == DataGridViewSelectionMode.RowHeaderSelect)
4600                         {
4601                             stcc.AddCellLinkedList(this.individualSelectedCells);
4602                         }
4603                         break;
4604                     }
4605                 }
4606                 return stcc;
4607             }
4608         }
4609  
4610         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.SelectedColumns"]/*‘ />
4611         [
4612             Browsable(false)
4613         ]
4614         public DataGridViewSelectedColumnCollection SelectedColumns
4615         {
4616             [
4617                 SuppressMessage("Microsoft.Performance", "CA1808:AvoidCallsThatBoxValueTypes") // consider using generics instead of DataGridViewIntLinkedList
4618             ]
4619             get
4620             {
4621                 DataGridViewSelectedColumnCollection strc = new DataGridViewSelectedColumnCollection();
4622                 switch (this.SelectionMode)
4623                 {
4624                     case DataGridViewSelectionMode.CellSelect:
4625                     case DataGridViewSelectionMode.FullRowSelect:
4626                     case DataGridViewSelectionMode.RowHeaderSelect:
4627                         break;
4628                     case DataGridViewSelectionMode.FullColumnSelect:
4629                     case DataGridViewSelectionMode.ColumnHeaderSelect:
4630                         foreach (int columnIndex in this.selectedBandIndexes)
4631                         {
4632                             strc.Add(this.Columns[columnIndex]);
4633                         }
4634                         break;
4635                 }
4636                 return strc;
4637             }
4638         }
4639         
4640         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.SelectedRows"]/*‘ />
4641         [
4642             Browsable(false),
4643         ]
4644         public DataGridViewSelectedRowCollection SelectedRows
4645         {
4646             [
4647                 SuppressMessage("Microsoft.Performance", "CA1808:AvoidCallsThatBoxValueTypes"), // using specialized DataGridViewIntLinkedList class instead of generics
4648                 SuppressMessage("Microsoft.Performance", "CA1817:DoNotCallPropertiesThatCloneValuesInLoops") // not legitimate
4649             ]
4650             get
4651             {
4652                 DataGridViewSelectedRowCollection strc = new DataGridViewSelectedRowCollection();
4653                 switch (this.SelectionMode)
4654                 {
4655                     case DataGridViewSelectionMode.CellSelect:
4656                     case DataGridViewSelectionMode.FullColumnSelect:
4657                     case DataGridViewSelectionMode.ColumnHeaderSelect:
4658                         break;
4659                     case DataGridViewSelectionMode.FullRowSelect:
4660                     case DataGridViewSelectionMode.RowHeaderSelect:
4661                         foreach (int rowIndex in this.selectedBandIndexes)
4662                         {
4663                             strc.Add((DataGridViewRow) this.Rows[rowIndex]); // unshares the selected row
4664                         }
4665                         break;
4666                 }
4667                 return strc;
4668             }
4669         }
4670  
4671         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.SelectionMode"]/*‘ />
4672         [
4673             Browsable(true),
4674             SRCategory(SR.CatBehavior),
4675             DefaultValue(DataGridViewSelectionMode.RowHeaderSelect),
4676             SRDescription(SR.DataGridView_SelectionModeDescr)
4677         ]
4678         public DataGridViewSelectionMode SelectionMode
4679         {
4680             get
4681             {
4682                 return this.selectionMode;
4683             }
4684             set
4685             {
4686                 // Sequential enum.  Valid values are 0x0 to 0x4
4687                 if (!ClientUtils.IsEnumValid(value, (int)value, (int)DataGridViewSelectionMode.CellSelect, (int)DataGridViewSelectionMode.ColumnHeaderSelect))
4688                 {
4689                     throw new InvalidEnumArgumentException("value", (int)value, typeof(DataGridViewSelectionMode)); 
4690                 }
4691  
4692                 if (this.SelectionMode != value)
4693                 {
4694                     if (!this.dataGridViewState2[DATAGRIDVIEWSTATE2_initializing] &&
4695                         (value == DataGridViewSelectionMode.FullColumnSelect || value == DataGridViewSelectionMode.ColumnHeaderSelect))
4696                     {
4697                         foreach (DataGridViewColumn dataGridViewColumn in this.Columns)
4698                         {
4699                             if (dataGridViewColumn.SortMode == DataGridViewColumnSortMode.Automatic)
4700                             {
4701                                 throw new InvalidOperationException(SR.GetString(SR.DataGridView_SelectionModeAndSortModeClash, (value).ToString()));
4702                             }
4703                         }
4704                     }
4705                     ClearSelection();
4706                     this.selectionMode = value;
4707                 }
4708             }
4709         }
4710  
4711         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ShowCellErrors"]/*‘ />
4712         [
4713             DefaultValue(true),
4714             SRCategory(SR.CatAppearance),
4715             SRDescription(SR.DataGridView_ShowCellErrorsDescr)
4716         ]
4717         public bool ShowCellErrors
4718         {
4719             get
4720             {
4721                 return this.dataGridViewState2[DATAGRIDVIEWSTATE2_showCellErrors];
4722             }
4723             set
4724             {
4725                 if (this.ShowCellErrors != value)
4726                 {
4727                     this.dataGridViewState2[DATAGRIDVIEWSTATE2_showCellErrors] = value;
4728  
4729                     // Put this into OnShowCellErrorsChanged if created.
4730                     if (this.IsHandleCreated && !this.DesignMode)
4731                     {
4732                         if (value && !this.ShowRowErrors && !this.ShowCellToolTips)
4733                         {
4734                             // the tool tip hasn‘t yet been activated
4735                             // activate it now
4736                             this.toolTipControl.Activate(!String.IsNullOrEmpty(this.toolTipCaption));
4737                         }
4738  
4739                         if (!value && !this.ShowRowErrors && !this.ShowCellToolTips)
4740                         {
4741                             // there is no reason to keep the tool tip activated
4742                             // deactivate it
4743                             this.toolTipCaption = String.Empty;
4744                             this.toolTipControl.Activate(false /*activate*/);
4745                         }
4746  
4747                         if (!value && (this.ShowRowErrors || this.ShowCellToolTips))
4748                         {
4749                             // reset the tool tip
4750                             this.toolTipControl.Activate(!String.IsNullOrEmpty(this.toolTipCaption));
4751                         }
4752  
4753                         // Some autosizing may have to be applied since the potential presence of error icons influences the preferred sizes.
4754                         OnGlobalAutoSize();
4755                     }
4756  
4757                     if (!this.layout.dirty && !this.DesignMode)
4758                     {
4759                         this.Invalidate(Rectangle.Union(this.layout.Data, this.layout.ColumnHeaders));
4760                         this.Invalidate(this.layout.TopLeftHeader);
4761                     }
4762                 }
4763             }
4764         }
4765  
4766         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ShowCellToolTips"]/*‘ />
4767         [
4768             DefaultValue(true),
4769             SRCategory(SR.CatAppearance),
4770             SRDescription(SR.DataGridView_ShowCellToolTipsDescr)
4771         ]
4772         public bool ShowCellToolTips
4773         {
4774             get
4775             {
4776                 return this.dataGridViewState2[DATAGRIDVIEWSTATE2_showCellToolTips];
4777             }
4778             set
4779             {
4780                 if (this.ShowCellToolTips != value)
4781                 {
4782                     this.dataGridViewState2[DATAGRIDVIEWSTATE2_showCellToolTips] = value;
4783  
4784                     if (this.IsHandleCreated && !this.DesignMode)
4785                     {
4786                         if (value && !this.ShowRowErrors && !this.ShowCellErrors)
4787                         {
4788                             // the tool tip hasn‘t yet been activated
4789                             // activate it now
4790                             this.toolTipControl.Activate(!String.IsNullOrEmpty(this.toolTipCaption) /*activate*/);
4791                         }
4792  
4793                         if (!value && !this.ShowRowErrors && !this.ShowCellErrors)
4794                         {
4795                             // there is no reason to keep the tool tip activated
4796                             // deactivate it
4797                             this.toolTipCaption = String.Empty;
4798                             this.toolTipControl.Activate(false /*activate*/);
4799                         }
4800  
4801                         if (!value && (this.ShowRowErrors || this.ShowCellErrors))
4802                         {
4803                             bool activate = !String.IsNullOrEmpty(this.toolTipCaption);
4804                             Point mouseCoord = System.Windows.Forms.Control.MousePosition;
4805                             activate &= this.ClientRectangle.Contains(PointToClient(mouseCoord));
4806  
4807                             // reset the tool tip
4808                             this.toolTipControl.Activate(activate);
4809                         }
4810                     }
4811  
4812                     if (!this.layout.dirty && !this.DesignMode)
4813                     {
4814                         Invalidate(this.layout.Data);
4815                     }
4816                 }
4817             }
4818         }
4819  
4820         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ShowEditingIcon"]/*‘ />
4821         [
4822             DefaultValue(true),
4823             SRCategory(SR.CatAppearance),
4824             SRDescription(SR.DataGridView_ShowEditingIconDescr)
4825         ]
4826         public bool ShowEditingIcon
4827         {
4828             get
4829             {
4830                 return this.dataGridViewState2[DATAGRIDVIEWSTATE2_showEditingIcon];
4831             }
4832             set
4833             {
4834                 if (this.ShowEditingIcon != value)
4835                 {
4836                     this.dataGridViewState2[DATAGRIDVIEWSTATE2_showEditingIcon] = value;
4837  
4838                     // invalidate the row header to pick up the new ShowEditingIcon value 
4839                     if (this.RowHeadersVisible)
4840                     {
4841                         if (this.VirtualMode || this.DataSource != null)
4842                         {
4843                             if (this.IsCurrentRowDirty)
4844                             {
4845                                 Debug.Assert(this.ptCurrentCell.Y >= 0);
4846                                 InvalidateCellPrivate(-1, this.ptCurrentCell.Y);
4847                             }
4848                         }
4849                         else
4850                         {
4851                             if (this.IsCurrentCellDirty) {
4852                                 Debug.Assert(this.ptCurrentCell.Y >= 0);
4853                                 InvalidateCellPrivate(-1, this.ptCurrentCell.Y);
4854                             }
4855                         }
4856                     }
4857                 }
4858             }
4859         }
4860  
4861         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ShowRowErrors"]/*‘ />
4862         [
4863             DefaultValue(true),
4864             SRCategory(SR.CatAppearance),
4865             SRDescription(SR.DataGridView_ShowRowErrorsDescr)
4866         ]
4867         public bool ShowRowErrors
4868         {
4869             get
4870             {
4871                 return this.dataGridViewState2[DATAGRIDVIEWSTATE2_showRowErrors];
4872             }
4873             set 
4874             {
4875                 if (this.ShowRowErrors != value)
4876                 {
4877                     this.dataGridViewState2[DATAGRIDVIEWSTATE2_showRowErrors] = value;
4878  
4879                     if (this.IsHandleCreated && !this.DesignMode)
4880                     {
4881                         if (value && !this.ShowCellErrors && !this.ShowCellToolTips)
4882                         {
4883                             // the tool tip hasn‘t yet been activated
4884                             // activate it now
4885                             this.toolTipControl.Activate(!String.IsNullOrEmpty(this.toolTipCaption));
4886                         }
4887  
4888                         if (!value && !this.ShowCellErrors && !this.ShowCellToolTips)
4889                         {
4890                             // there is no reason to keep the tool tip activated
4891                             // deactivate it
4892                             this.toolTipCaption = String.Empty;
4893                             this.toolTipControl.Activate(false /*activate*/);
4894                         }
4895  
4896                         if (!value && (this.ShowCellErrors || this.ShowCellToolTips))
4897                         {
4898                             // reset the tool tip
4899                             this.toolTipControl.Activate(!String.IsNullOrEmpty(this.toolTipCaption));
4900                         }
4901                     }
4902  
4903                     if (!this.layout.dirty && !this.DesignMode)
4904                     {
4905                         Invalidate(this.layout.RowHeaders);
4906                     }
4907                 }
4908             }
4909         }
4910  
4911         internal bool SingleHorizontalBorderAdded
4912         {
4913             get
4914             {
4915                 return !this.layout.ColumnHeadersVisible && 
4916                     (this.AdvancedCellBorderStyle.All == DataGridViewAdvancedCellBorderStyle.Single ||
4917                      this.CellBorderStyle == DataGridViewCellBorderStyle.SingleHorizontal);
4918             }
4919         }
4920  
4921         internal bool SingleVerticalBorderAdded
4922         {
4923             get
4924             {
4925                 return !this.layout.RowHeadersVisible && 
4926                     (this.AdvancedCellBorderStyle.All == DataGridViewAdvancedCellBorderStyle.Single ||
4927                      this.CellBorderStyle == DataGridViewCellBorderStyle.SingleVertical);
4928             }
4929         }
4930  
4931         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.SortedColumn"]/*‘ />
4932         [
4933             Browsable(false)
4934         ]
4935         public DataGridViewColumn SortedColumn
4936         {
4937             get
4938             {
4939                 return this.sortedColumn;
4940             }
4941         }
4942  
4943         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.SortOrder"]/*‘ />
4944         [
4945             Browsable(false)
4946         ]
4947         public SortOrder SortOrder
4948         {
4949             get
4950             {
4951                 return this.sortOrder;
4952             }
4953         }
4954  
4955         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.StandardTab"]/*‘ />
4956         /// <devdoc>
4957         ///    <para>
4958         ///    </para>
4959         /// </devdoc>
4960         [
4961             SRCategory(SR.CatBehavior), 
4962             DefaultValue(false), 
4963             EditorBrowsable(EditorBrowsableState.Advanced),
4964             SRDescription(SR.DataGridView_StandardTabDescr)
4965         ]
4966         public bool StandardTab
4967         {
4968             get
4969             {
4970                 return this.dataGridViewState1[DATAGRIDVIEWSTATE1_standardTab];
4971             }
4972             set
4973             {
4974                 if (this.dataGridViewState1[DATAGRIDVIEWSTATE1_standardTab] != value)
4975                 {
4976                     this.dataGridViewState1[DATAGRIDVIEWSTATE1_standardTab] = value;
4977                     //OnStandardTabChanged(EventArgs.Empty);
4978                 }
4979             }
4980         }
4981  
4982         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.Text"]/*‘ />
4983         [
4984             Browsable(false), 
4985             EditorBrowsable(EditorBrowsableState.Never),
4986             Bindable(false)
4987         ]
4988         public override string Text
4989         {
4990             get
4991             {
4992                 return base.Text;
4993             }
4994             set
4995             {
4996                 base.Text = value;
4997             }
4998         }
4999  
5000         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.TextChanged"]/*‘ />
5001         [
5002             Browsable(false),
5003             EditorBrowsable(EditorBrowsableState.Never)
5004         ]
5005         new public event EventHandler TextChanged
5006         {
5007             add
5008             {
5009                 base.TextChanged += value;
5010             }
5011             remove
5012             {
5013                 base.TextChanged -= value;
5014             }
5015         }
5016  
5017         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.this"]/*‘ />
5018         [
5019             Browsable(false),
5020             DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
5021             SuppressMessage("Microsoft.Design", "CA1023:IndexersShouldNotBeMultidimensional")
5022         ]
5023         public DataGridViewCell this[int columnIndex, int rowIndex]
5024         {
5025             get
5026             {
5027                 DataGridViewRow row = this.Rows[rowIndex];
5028                 return row.Cells[columnIndex];
5029             }
5030             set
5031             {
5032                 DataGridViewRow row = this.Rows[rowIndex];
5033                 row.Cells[columnIndex] = value;
5034             }
5035         }
5036  
5037         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.this1"]/*‘ />
5038         [
5039             Browsable(false),
5040             DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
5041             SuppressMessage("Microsoft.Design", "CA1023:IndexersShouldNotBeMultidimensional")
5042         ]
5043         public DataGridViewCell this[string columnName, int rowIndex]
5044         {
5045             get
5046             {
5047                 DataGridViewRow row = this.Rows[rowIndex];
5048                 return row.Cells[columnName];
5049             }
5050             set
5051             {
5052                 DataGridViewRow row = this.Rows[rowIndex];
5053                 row.Cells[columnName] = value;
5054             }
5055         }
5056  
5057         private string ToolTipPrivate
5058         {
5059             get
5060             {
5061                 return this.toolTipCaption;
5062             }
5063         }
5064  
5065         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.TopLeftHeaderCell"]/*‘ />
5066         [
5067             Browsable(false),
5068             DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
5069         ]
5070         public DataGridViewHeaderCell TopLeftHeaderCell
5071         {
5072             get
5073             {
5074                 if (this.topLeftHeaderCell == null)
5075                 {
5076                     this.TopLeftHeaderCell = new DataGridViewTopLeftHeaderCell();
5077                 }
5078                 return this.topLeftHeaderCell;
5079             }
5080             set
5081             {
5082                 if (this.topLeftHeaderCell != value)
5083                 {
5084                     if (this.topLeftHeaderCell != null)
5085                     {
5086                         // Detach existing header cell
5087                         this.topLeftHeaderCell.DataGridViewInternal = null;
5088                     }
5089                     this.topLeftHeaderCell = value;
5090                     if (value != null)
5091                     {
5092                         this.topLeftHeaderCell.DataGridViewInternal = this;
5093                     }
5094                     if (this.ColumnHeadersVisible && this.RowHeadersVisible)
5095                     {
5096                         // If headers (rows or columns) are autosized, then this.RowHeadersWidth or this.ColumnHeadersHeight
5097                         // must be updated based on new cell preferred size
5098                         OnColumnHeadersGlobalAutoSize();
5099                         // In all cases, the top left cell needs to repaint
5100                         Invalidate(new Rectangle(this.layout.Inside.X, this.layout.Inside.Y, this.RowHeadersWidth, this.ColumnHeadersHeight));
5101                     }
5102                 }
5103             }
5104         }
5105  
5106         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.UserSetCursor"]/*‘ />
5107         [
5108             Browsable(false),
5109             EditorBrowsable(EditorBrowsableState.Advanced)
5110         ]
5111         public Cursor UserSetCursor
5112         {
5113             get
5114             {
5115                 if (this.dataGridViewState1[DATAGRIDVIEWSTATE1_customCursorSet])
5116                 {
5117                     return this.oldCursor;
5118                 }
5119                 else
5120                 {
5121                     return this.Cursor;
5122                 }
5123             }
5124         }
5125  
5126         internal int VerticalOffset
5127         {
5128             get
5129             {
5130                 return this.verticalOffset;
5131             }
5132             set 
5133             {
5134                 if (value < 0)
5135                 {
5136                     value = 0;
5137                 }
5138                 int totalVisibleFrozenHeight = this.Rows.GetRowsHeight(DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen);
5139                 int fittingTrailingScrollingRowsHeight = ComputeHeightOfFittingTrailingScrollingRows(totalVisibleFrozenHeight);
5140                 if (value > this.vertScrollBar.Maximum - fittingTrailingScrollingRowsHeight)
5141                 {
5142                     value = this.vertScrollBar.Maximum - fittingTrailingScrollingRowsHeight;
5143                 }
5144                 if (value == this.verticalOffset)
5145                 {
5146                     return;
5147                 }
5148  
5149                 int change = value - this.verticalOffset;
5150                 if (this.vertScrollBar.Enabled)
5151                 {
5152                     this.vertScrollBar.Value = value;
5153                 }
5154                 ScrollRowsByHeight(change); // calculate how many rows need to be scrolled based on ‘change‘
5155             }
5156         }
5157  
5158         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.VerticalScrollBar"]/*‘ />
5159         protected ScrollBar VerticalScrollBar
5160         {
5161             get
5162             {
5163                 return this.vertScrollBar;
5164             }
5165         }
5166  
5167         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.VerticalScrollingOffset"]/*‘ />
5168         [
5169             Browsable(false),
5170             DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
5171         ]
5172         public int VerticalScrollingOffset
5173         {
5174             get
5175             {
5176                 return this.verticalOffset;
5177             }
5178         }
5179  
5180         private System.Windows.Forms.Timer VertScrollTimer
5181         {
5182             get
5183             {
5184                 if (this.vertScrollTimer == null)
5185                 {
5186                     this.vertScrollTimer = new System.Windows.Forms.Timer();
5187                     this.vertScrollTimer.Tick += new System.EventHandler(VertScrollTimer_Tick);
5188                 }
5189                 return this.vertScrollTimer;
5190             }
5191         }
5192  
5193         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.VirtualMode"]/*‘ />
5194         /// <devdoc>
5195         ///    <para>
5196         ///    </para>
5197         /// </devdoc>
5198         [
5199             SRCategory(SR.CatBehavior),
5200             DefaultValue(false),
5201             EditorBrowsable(EditorBrowsableState.Advanced),
5202             SRDescription(SR.DataGridViewVirtualModeDescr)
5203         ]
5204         public bool VirtualMode
5205         {
5206             get
5207             {
5208                 return this.dataGridViewState1[DATAGRIDVIEWSTATE1_virtualMode];
5209             }
5210             set
5211             {
5212                 if (this.dataGridViewState1[DATAGRIDVIEWSTATE1_virtualMode] != value)
5213                 {
5214                     this.dataGridViewState1[DATAGRIDVIEWSTATE1_virtualMode] = value;
5215                     InvalidateRowHeights();
5216                     //OnVirtualModeChanged(EventArgs.Empty);
5217                 }
5218             }
5219         }
5220  
5221         private bool VisibleCellExists
5222         {
5223             get
5224             {
5225                 if (null == this.Columns.GetFirstColumn(DataGridViewElementStates.Visible))
5226                 {
5227                     return false;
5228                 }
5229                 return -1 != this.Rows.GetFirstRow(DataGridViewElementStates.Visible);
5230             }
5231         }
5232  
5233         // Events start here
5234  
5235         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.AutoSizeColumnModeChanged"]/*‘ />
5236         [
5237             SRCategory(SR.CatPropertyChanged), 
5238             SRDescription(SR.DataGridViewAutoSizeColumnModeChangedDescr)
5239         ]
5240         public event DataGridViewAutoSizeColumnModeEventHandler AutoSizeColumnModeChanged
5241         {
5242             add
5243             {
5244                 this.Events.AddHandler(EVENT_DATAGRIDVIEWAUTOSIZECOLUMNMODECHANGED, value);
5245             }
5246             remove
5247             {
5248                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWAUTOSIZECOLUMNMODECHANGED, value);
5249             }
5250         }
5251  
5252         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CancelRowEdit"]/*‘ />
5253         [
5254             SRCategory(SR.CatAction),
5255             SRDescription(SR.DataGridView_CancelRowEditDescr)
5256         ]
5257         public event QuestionEventHandler CancelRowEdit
5258         {
5259             add
5260             {
5261                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCANCELROWEDIT, value);
5262             }
5263             remove
5264             {
5265                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCANCELROWEDIT, value);
5266             }
5267         }
5268  
5269         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellBeginEdit"]/*‘ />
5270         [
5271             SRCategory(SR.CatData),
5272             SRDescription(SR.DataGridView_CellBeginEditDescr)
5273         ]
5274         public event DataGridViewCellCancelEventHandler CellBeginEdit 
5275         {
5276             add 
5277             {
5278                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLBEGINEDIT, value);
5279             }
5280             remove 
5281             {
5282                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLBEGINEDIT, value);
5283             }
5284         }
5285  
5286         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellClick"]/*‘ />
5287         [
5288             SRCategory(SR.CatMouse),
5289             SRDescription(SR.DataGridView_CellClickDescr)
5290         ]
5291         public event DataGridViewCellEventHandler CellClick
5292         {
5293             add 
5294             {
5295                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLCLICK, value);
5296             }
5297             remove 
5298             {
5299                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLCLICK, value);
5300             }
5301         }
5302  
5303         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellContentClick"]/*‘ />
5304         [
5305             SRCategory(SR.CatMouse),
5306             SRDescription(SR.DataGridView_CellContentClick)
5307         ]
5308         public event DataGridViewCellEventHandler CellContentClick
5309         {
5310             add 
5311             {
5312                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLCONTENTCLICK, value);
5313             }
5314             remove 
5315             {
5316                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLCONTENTCLICK, value);
5317             }
5318         }
5319  
5320         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellContentDoubleClick"]/*‘ />
5321         [
5322             SRCategory(SR.CatMouse),
5323             SRDescription(SR.DataGridView_CellContentDoubleClick)
5324         ]
5325         public event DataGridViewCellEventHandler CellContentDoubleClick
5326         {
5327             add
5328             {
5329                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLCONTENTDOUBLECLICK, value);
5330             }
5331             remove
5332             {
5333                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLCONTENTDOUBLECLICK, value);
5334             }
5335         }
5336  
5337         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellContextMenuStripChanged"]/*‘ />
5338         [
5339             SRCategory(SR.CatAction),
5340             SRDescription(SR.DataGridView_CellContextMenuStripChanged),
5341             EditorBrowsable(EditorBrowsableState.Advanced)
5342         ]
5343         public event DataGridViewCellEventHandler CellContextMenuStripChanged
5344         {
5345             add
5346             {
5347                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLCONTEXTMENUSTRIPCHANGED, value);
5348             }
5349             remove
5350             {
5351                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLCONTEXTMENUSTRIPCHANGED, value);
5352             }
5353         }
5354  
5355         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellContextMenuStripNeeded"]/*‘ />
5356         [
5357             SRCategory(SR.CatBehavior),
5358             SRDescription(SR.DataGridView_CellContextMenuStripNeeded),
5359             EditorBrowsable(EditorBrowsableState.Advanced)
5360         ]
5361         public event DataGridViewCellContextMenuStripNeededEventHandler CellContextMenuStripNeeded
5362         {
5363             add
5364             {
5365                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLCONTEXTMENUSTRIPNEEDED, value);
5366             }
5367             remove
5368             {
5369                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLCONTEXTMENUSTRIPNEEDED, value);
5370             }
5371         }
5372  
5373         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellDoubleClick"]/*‘ />
5374         [
5375             SRCategory(SR.CatMouse),
5376             SRDescription(SR.DataGridView_CellDoubleClickDescr)
5377         ]
5378         public event DataGridViewCellEventHandler CellDoubleClick
5379         {
5380             add
5381             {
5382                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLDOUBLECLICK, value);
5383             }
5384             remove
5385             {
5386                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLDOUBLECLICK, value);
5387             }
5388         }
5389  
5390         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellEndEdit"]/*‘ />
5391         [
5392             SRCategory(SR.CatData),
5393             SRDescription(SR.DataGridView_CellEndEditDescr)
5394         ]
5395         public event DataGridViewCellEventHandler CellEndEdit 
5396         {
5397             add 
5398             {
5399                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLENDEDIT, value);
5400             }
5401             remove 
5402             {
5403                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLENDEDIT, value);
5404             }
5405         }
5406  
5407         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellEnter"]/*‘ />
5408         [
5409             SRCategory(SR.CatFocus),
5410             SRDescription(SR.DataGridView_CellEnterDescr)
5411         ]
5412         public event DataGridViewCellEventHandler CellEnter
5413         {
5414             add 
5415             {
5416                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLENTER, value);
5417             }
5418             remove 
5419             {
5420                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLENTER, value);
5421             }
5422         }
5423  
5424         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellErrorTextChanged"]/*‘ />
5425         [
5426             SRCategory(SR.CatPropertyChanged),
5427             SRDescription(SR.DataGridView_CellErrorTextChangedDescr)
5428         ]
5429         public event DataGridViewCellEventHandler CellErrorTextChanged
5430         {
5431             add
5432             {
5433                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLERRORTEXTCHANGED, value);
5434             }
5435             remove
5436             {
5437                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLERRORTEXTCHANGED, value);
5438             }
5439         }
5440  
5441         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellErrorTextNeeded"]/*‘ />
5442         [
5443             SRCategory(SR.CatData),
5444             EditorBrowsable(EditorBrowsableState.Advanced),
5445             SRDescription(SR.DataGridView_CellErrorTextNeededDescr)
5446         ]
5447         public event DataGridViewCellErrorTextNeededEventHandler CellErrorTextNeeded
5448         {
5449             add
5450             {
5451                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLERRORTEXTNEEDED, value);
5452             }
5453             remove
5454             {
5455                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLERRORTEXTNEEDED, value);
5456             }
5457         }
5458  
5459         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellFormatting"]/*‘ />
5460         [
5461             SRCategory(SR.CatDisplay),
5462             SRDescription(SR.DataGridView_CellFormattingDescr)
5463         ]
5464         public event DataGridViewCellFormattingEventHandler CellFormatting 
5465         {
5466             add 
5467             {
5468                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLFORMATTING, value);
5469             }
5470             remove 
5471             {
5472                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLFORMATTING, value);
5473             }
5474         }
5475  
5476         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellLeave"]/*‘ />
5477         [
5478             SRCategory(SR.CatFocus),
5479             SRDescription(SR.DataGridView_CellLeaveDescr)
5480         ]
5481         public event DataGridViewCellEventHandler CellLeave
5482         {
5483             add 
5484             {
5485                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLLEAVE, value);
5486             }
5487             remove 
5488             {
5489                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLLEAVE, value);
5490             }
5491         }
5492  
5493         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellMouseClick"]/*‘ />
5494         [
5495             SRCategory(SR.CatMouse),
5496             SRDescription(SR.DataGridView_CellMouseClickDescr)
5497         ]
5498         public event DataGridViewCellMouseEventHandler CellMouseClick
5499         {
5500             add 
5501             {
5502                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLMOUSECLICK, value);
5503             }
5504             remove 
5505             {
5506                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLMOUSECLICK, value);
5507             }
5508         }
5509  
5510         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellMouseDoubleClick"]/*‘ />
5511         [
5512             SRCategory(SR.CatMouse),
5513             SRDescription(SR.DataGridView_CellMouseDoubleClickDescr)
5514         ]
5515         public event DataGridViewCellMouseEventHandler CellMouseDoubleClick
5516         {
5517             add
5518             {
5519                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLMOUSEDOUBLECLICK, value);
5520             }
5521             remove
5522             {
5523                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLMOUSEDOUBLECLICK, value);
5524             }
5525         }
5526  
5527         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellMouseDown"]/*‘ />
5528         [
5529             SRCategory(SR.CatMouse),
5530             SRDescription(SR.DataGridView_CellMouseDownDescr)
5531         ]
5532         public event DataGridViewCellMouseEventHandler CellMouseDown
5533         {
5534             add 
5535             {
5536                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLMOUSEDOWN, value);
5537             }
5538             remove 
5539             {
5540                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLMOUSEDOWN, value);
5541             }
5542         }
5543  
5544         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellMouseEnter"]/*‘ />
5545         [
5546             SRCategory(SR.CatMouse),
5547             SRDescription(SR.DataGridView_CellMouseEnterDescr)
5548         ]
5549         public event DataGridViewCellEventHandler CellMouseEnter
5550         {
5551             add 
5552             {
5553                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLMOUSEENTER, value);
5554             }
5555             remove 
5556             {
5557                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLMOUSEENTER, value);
5558             }
5559         }
5560  
5561         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellMouseLeave"]/*‘ />
5562         [
5563             SRCategory(SR.CatMouse),
5564             SRDescription(SR.DataGridView_CellMouseLeaveDescr)
5565         ]
5566         public event DataGridViewCellEventHandler CellMouseLeave
5567         {
5568             add 
5569             {
5570                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLMOUSELEAVE, value);
5571             }
5572             remove 
5573             {
5574                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLMOUSELEAVE, value);
5575             }
5576         }
5577  
5578         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellMouseMove"]/*‘ />
5579         [
5580             SRCategory(SR.CatMouse),
5581             SRDescription(SR.DataGridView_CellMouseMoveDescr)
5582         ]
5583         public event DataGridViewCellMouseEventHandler CellMouseMove
5584         {
5585             add 
5586             {
5587                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLMOUSEMOVE, value);
5588             }
5589             remove 
5590             {
5591                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLMOUSEMOVE, value);
5592             }
5593         }
5594  
5595         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellMouseUp"]/*‘ />
5596         [
5597             SRCategory(SR.CatMouse),
5598             SRDescription(SR.DataGridView_CellMouseUpDescr)
5599         ]
5600         public event DataGridViewCellMouseEventHandler CellMouseUp 
5601         {
5602             add 
5603             {
5604                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLMOUSEUP, value);
5605             }
5606             remove 
5607             {
5608                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLMOUSEUP, value);
5609             }
5610         }
5611  
5612         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellPainting"]/*‘ />
5613         [
5614             SRCategory(SR.CatDisplay),
5615             SRDescription(SR.DataGridView_CellPaintingDescr)
5616         ]
5617         public event DataGridViewCellPaintingEventHandler CellPainting 
5618         {
5619             add 
5620             {
5621                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLPAINTING, value);
5622             }
5623             remove 
5624             {
5625                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLPAINTING, value);
5626             }
5627         }
5628  
5629         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellParsing"]/*‘ />
5630         [
5631             SRCategory(SR.CatDisplay),
5632             SRDescription(SR.DataGridView_CellParsingDescr)
5633         ]
5634         public event DataGridViewCellParsingEventHandler CellParsing
5635         {
5636             add 
5637             {
5638                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLPARSING, value);
5639             }
5640             remove 
5641             {
5642                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLPARSING, value);
5643             }
5644         }
5645  
5646         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellStateChanged"]/*‘ />
5647         [
5648             SRCategory(SR.CatBehavior),
5649             SRDescription(SR.DataGridView_CellStateChangedDescr)
5650         ]
5651         public event DataGridViewCellStateChangedEventHandler CellStateChanged 
5652         {
5653             add 
5654             {
5655                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLSTATECHANGED, value);
5656             }
5657             remove 
5658             {
5659                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLSTATECHANGED, value);
5660             }
5661         }
5662  
5663         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellStyleChanged"]/*‘ />
5664         [
5665             SRCategory(SR.CatPropertyChanged),
5666             SRDescription(SR.DataGridView_CellStyleChangedDescr)
5667         ]
5668         public event DataGridViewCellEventHandler CellStyleChanged 
5669         {
5670             add 
5671             {
5672                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLSTYLECHANGED, value);
5673             }
5674             remove 
5675             {
5676                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLSTYLECHANGED, value);
5677             }
5678         }
5679  
5680         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellStyleContentChanged"]/*‘ />
5681         [
5682             SRCategory(SR.CatPropertyChanged),
5683             SRDescription(SR.DataGridView_CellStyleContentChangedDescr)
5684         ]
5685         public event DataGridViewCellStyleContentChangedEventHandler CellStyleContentChanged
5686         {
5687             add
5688             {
5689                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLSTYLECONTENTCHANGED, value);
5690             }
5691             remove
5692             {
5693                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLSTYLECONTENTCHANGED, value);
5694             }
5695         }
5696  
5697         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellToolTipTextChanged"]/*‘ />
5698         [
5699             SRCategory(SR.CatPropertyChanged),
5700             SRDescription(SR.DataGridView_CellToolTipTextChangedDescr)
5701         ]
5702         public event DataGridViewCellEventHandler CellToolTipTextChanged
5703         {
5704             add
5705             {
5706                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLTOOLTIPTEXTCHANGED, value);
5707             }
5708             remove
5709             {
5710                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLTOOLTIPTEXTCHANGED, value);
5711             }
5712         }
5713  
5714         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellToolTipTextNeeded"]/*‘ />
5715         [
5716             SRCategory(SR.CatBehavior),
5717             SRDescription(SR.DataGridView_CellToolTipTextNeededDescr),
5718             EditorBrowsable(EditorBrowsableState.Advanced)
5719         ]
5720         public event DataGridViewCellToolTipTextNeededEventHandler CellToolTipTextNeeded
5721         {
5722             add
5723             {
5724                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLTOOLTIPTEXTNEEDED, value);
5725             }
5726             remove
5727             {
5728                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLTOOLTIPTEXTNEEDED, value);
5729             }
5730         }
5731  
5732         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellValidated"]/*‘ />
5733         [
5734             SRCategory(SR.CatFocus),
5735             SRDescription(SR.DataGridView_CellValidatedDescr)
5736         ]
5737         public event DataGridViewCellEventHandler CellValidated
5738         {
5739             add 
5740             {
5741                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLVALIDATED, value);
5742             }
5743             remove 
5744             {
5745                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLVALIDATED, value);
5746             }
5747         }
5748  
5749         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellValidating"]/*‘ />
5750         [
5751             SRCategory(SR.CatFocus),
5752             SRDescription(SR.DataGridView_CellValidatingDescr)
5753         ]
5754         public event DataGridViewCellValidatingEventHandler CellValidating
5755         {
5756             add 
5757             {
5758                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLVALIDATING, value);
5759             }
5760             remove 
5761             {
5762                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLVALIDATING, value);
5763             }
5764         }
5765  
5766         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellValueChanged"]/*‘ />
5767         [
5768             SRCategory(SR.CatAction),
5769             SRDescription(SR.DataGridView_CellValueChangedDescr)
5770         ]
5771         public event DataGridViewCellEventHandler CellValueChanged 
5772         {
5773             add 
5774             {
5775                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLVALUECHANGED, value);
5776             }
5777             remove 
5778             {
5779                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLVALUECHANGED, value);
5780             }
5781         }
5782  
5783         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellValueNeeded"]/*‘ />
5784         [
5785             SRCategory(SR.CatData),
5786             EditorBrowsable(EditorBrowsableState.Advanced),
5787             SRDescription(SR.DataGridView_CellValueNeededDescr)
5788         ]
5789         public event DataGridViewCellValueEventHandler CellValueNeeded 
5790         {
5791             add 
5792             {
5793                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLVALUENEEDED, value);
5794             }
5795             remove 
5796             {
5797                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLVALUENEEDED, value);
5798             }
5799         }
5800  
5801         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CellValuePushed"]/*‘ />
5802         [
5803             SRCategory(SR.CatData),
5804             EditorBrowsable(EditorBrowsableState.Advanced),
5805             SRDescription(SR.DataGridView_CellValuePushedDescr)
5806         ]
5807         public event DataGridViewCellValueEventHandler CellValuePushed 
5808         {
5809             add 
5810             {
5811                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCELLVALUEPUSHED, value);
5812             }
5813             remove 
5814             {
5815                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCELLVALUEPUSHED, value);
5816             }
5817         }
5818  
5819         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnAdded"]/*‘ />
5820         [
5821             SRCategory(SR.CatAction),
5822             SRDescription(SR.DataGridView_ColumnAddedDescr)
5823         ]
5824         public event DataGridViewColumnEventHandler ColumnAdded
5825         {
5826             add
5827             {
5828                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCOLUMNADDED, value);
5829             }
5830             remove
5831             {
5832                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCOLUMNADDED, value);
5833             }
5834         }
5835  
5836         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnContextMenuStripChanged"]/*‘ />
5837         [
5838             SRCategory(SR.CatPropertyChanged),
5839             SRDescription(SR.DataGridView_ColumnContextMenuStripChangedDescr)
5840         ]
5841         public event DataGridViewColumnEventHandler ColumnContextMenuStripChanged
5842         {
5843             add
5844             {
5845                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCOLUMNCONTEXTMENUSTRIPCHANGED, value);
5846             }
5847             remove
5848             {
5849                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCOLUMNCONTEXTMENUSTRIPCHANGED, value);
5850             }
5851         }
5852  
5853         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnDataPropertyNameChanged"]/*‘ />
5854         [
5855             SRCategory(SR.CatPropertyChanged),
5856             SRDescription(SR.DataGridView_ColumnDataPropertyNameChangedDescr)
5857         ]
5858         public event DataGridViewColumnEventHandler ColumnDataPropertyNameChanged
5859         {
5860             add
5861             {
5862                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCOLUMNDATAPROPERTYNAMECHANGED, value);
5863             }
5864             remove
5865             {
5866                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCOLUMNDATAPROPERTYNAMECHANGED, value);
5867             }
5868         }
5869  
5870         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnDefaultCellStyleChanged"]/*‘ />
5871         [
5872             SRCategory(SR.CatPropertyChanged),
5873             SRDescription(SR.DataGridView_ColumnDefaultCellStyleChangedDescr)
5874         ]
5875         public event DataGridViewColumnEventHandler ColumnDefaultCellStyleChanged
5876         {
5877             add 
5878             {
5879                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCOLUMNDEFAULTCELLSTYLECHANGED, value);
5880             }
5881             remove 
5882             {
5883                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCOLUMNDEFAULTCELLSTYLECHANGED, value);
5884             }
5885         }
5886  
5887         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnDisplayIndexChanged"]/*‘ />
5888         [
5889             SRCategory(SR.CatPropertyChanged),
5890             SRDescription(SR.DataGridView_ColumnDisplayIndexChangedDescr)
5891         ]
5892         public event DataGridViewColumnEventHandler ColumnDisplayIndexChanged 
5893         {
5894             add 
5895             {
5896                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCOLUMNDISPLAYINDEXCHANGED, value);
5897             }
5898             remove 
5899             {
5900                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCOLUMNDISPLAYINDEXCHANGED, value);
5901             }
5902         }
5903  
5904         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnDividerDoubleClick"]/*‘ />
5905         [
5906             SRCategory(SR.CatMouse),
5907             SRDescription(SR.DataGridView_ColumnDividerDoubleClickDescr)
5908         ]
5909         public event DataGridViewColumnDividerDoubleClickEventHandler ColumnDividerDoubleClick
5910         {
5911             add
5912             {
5913                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCOLUMNDIVIDERDOUBLECLICK, value);
5914             }
5915             remove
5916             {
5917                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCOLUMNDIVIDERDOUBLECLICK, value);
5918             }
5919         }
5920  
5921         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnDividerWidthChanged"]/*‘ />
5922         [
5923             SRCategory(SR.CatPropertyChanged),
5924             SRDescription(SR.DataGridView_ColumnDividerWidthChangedDescr)
5925         ]
5926         public event DataGridViewColumnEventHandler ColumnDividerWidthChanged
5927         {
5928             add 
5929             {
5930                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCOLUMNDIVIDERWIDTHCHANGED, value);
5931             }
5932             remove 
5933             {
5934                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCOLUMNDIVIDERWIDTHCHANGED, value);
5935             }
5936         }
5937  
5938         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnHeaderMouseClick"]/*‘ />
5939         [
5940             SRCategory(SR.CatMouse),
5941             SRDescription(SR.DataGridView_ColumnHeaderMouseClickDescr)
5942         ]
5943         public event DataGridViewCellMouseEventHandler ColumnHeaderMouseClick 
5944         {
5945             add 
5946             {
5947                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCOLUMNHEADERMOUSECLICK, value);
5948             }
5949             remove 
5950             {
5951                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCOLUMNHEADERMOUSECLICK, value);
5952             }
5953         }
5954  
5955         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnHeaderMouseDoubleClick"]/*‘ />
5956         [
5957             SRCategory(SR.CatMouse), 
5958             SRDescription(SR.DataGridView_ColumnHeaderMouseDoubleClickDescr)
5959         ]
5960         public event DataGridViewCellMouseEventHandler ColumnHeaderMouseDoubleClick
5961         {
5962             add
5963             {
5964                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCOLUMNHEADERMOUSEDOUBLECLICK, value);
5965             }
5966             remove
5967             {
5968                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCOLUMNHEADERMOUSEDOUBLECLICK, value);
5969             }
5970         }
5971  
5972         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnHeaderCellChanged"]/*‘ />
5973         [
5974             SRCategory(SR.CatPropertyChanged),
5975             SRDescription(SR.DataGridView_ColumnHeaderCellChangedDescr)
5976         ]
5977         public event DataGridViewColumnEventHandler ColumnHeaderCellChanged 
5978         {
5979             add 
5980             {
5981                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCOLUMNHEADERCELLCHANGED, value);
5982             }
5983             remove 
5984             {
5985                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCOLUMNHEADERCELLCHANGED, value);
5986             }
5987         }
5988  
5989         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnMinimumWidthChanged"]/*‘ />
5990         [
5991             SRCategory(SR.CatPropertyChanged),
5992             SRDescription(SR.DataGridView_ColumnMinimumWidthChangedDescr)
5993         ]
5994         public event DataGridViewColumnEventHandler ColumnMinimumWidthChanged 
5995         {
5996             add 
5997             {
5998                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCOLUMNMINIMUMWIDTHCHANGED, value);
5999             }
6000             remove 
6001             {
6002                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCOLUMNMINIMUMWIDTHCHANGED, value);
6003             }
6004         }
6005  
6006         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnNameChanged"]/*‘ />
6007         [
6008             SRCategory(SR.CatPropertyChanged),
6009             SRDescription(SR.DataGridView_ColumnNameChangedDescr)
6010         ]
6011         public event DataGridViewColumnEventHandler ColumnNameChanged
6012         {
6013             add 
6014             {
6015                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCOLUMNNAMECHANGED, value);
6016             }
6017             remove 
6018             {
6019                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCOLUMNNAMECHANGED, value);
6020             }
6021         }
6022  
6023         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnRemoved"]/*‘ />
6024         [
6025             SRCategory(SR.CatAction),
6026             SRDescription(SR.DataGridView_ColumnRemovedDescr)
6027         ]
6028         public event DataGridViewColumnEventHandler ColumnRemoved
6029         {
6030             add
6031             {
6032                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCOLUMNREMOVED, value);
6033             }
6034             remove
6035             {
6036                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCOLUMNREMOVED, value);
6037             }
6038         }
6039  
6040         /*/// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnsDefaultCellStyleChanged"]/*‘ />
6041         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnsDefaultCellStyleChanged"]/*‘ />
6042         public event EventHandler ColumnsDefaultCellStyleChanged
6043         {
6044             add
6045             {
6046                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCOLUMNSDEFAULTCELLSTYLECHANGED, value);
6047             }
6048             remove
6049             {
6050                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCOLUMNSDEFAULTCELLSTYLECHANGED, value);
6051             }
6052         }*/
6053  
6054         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnSortModeChanged"]/*‘ />
6055         [
6056             SRCategory(SR.CatBehavior),
6057             SRDescription(SR.DataGridViewColumnSortModeChangedDescr)
6058         ]
6059         public event DataGridViewColumnEventHandler ColumnSortModeChanged
6060         {
6061             add
6062             {
6063                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCOLUMNSORTMODECHANGED, value);
6064             }
6065             remove
6066             {
6067                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCOLUMNSORTMODECHANGED, value);
6068             }
6069         }
6070  
6071         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnStateChanged"]/*‘ />
6072         [
6073             SRCategory(SR.CatBehavior),
6074             SRDescription(SR.DataGridView_ColumnStateChangedDescr)
6075         ]
6076         public event DataGridViewColumnStateChangedEventHandler ColumnStateChanged 
6077         {
6078             add 
6079             {
6080                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCOLUMNSTATECHANGED, value);
6081             }
6082             remove 
6083             {
6084                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCOLUMNSTATECHANGED, value);
6085             }
6086         }
6087  
6088         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnToolTipTextChanged"]/*‘ />
6089         [
6090             SRCategory(SR.CatPropertyChanged),
6091             SRDescription(SR.DataGridView_ColumnToolTipTextChangedDescr)
6092         ]
6093         public event DataGridViewColumnEventHandler ColumnToolTipTextChanged
6094         {
6095             add
6096             {
6097                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCOLUMNTOOLTIPTEXTCHANGED, value);
6098             }
6099             remove
6100             {
6101                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCOLUMNTOOLTIPTEXTCHANGED, value);
6102             }
6103         }
6104  
6105         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.ColumnWidthChanged"]/*‘ />
6106         [
6107             SRCategory(SR.CatAction),
6108             SRDescription(SR.DataGridView_ColumnWidthChangedDescr)
6109         ]
6110         public event DataGridViewColumnEventHandler ColumnWidthChanged 
6111         {
6112             add 
6113             {
6114                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCOLUMNWIDTHCHANGED, value);
6115             }
6116             remove 
6117             {
6118                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCOLUMNWIDTHCHANGED, value);
6119             }
6120         }
6121  
6122         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CurrentCellChanged"]/*‘ />
6123         [
6124             SRCategory(SR.CatAction), 
6125             SRDescription(SR.DataGridView_CurrentCellChangedDescr)
6126         ]
6127         public event EventHandler CurrentCellChanged
6128         {
6129             add
6130             {
6131                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCURRENTCELLCHANGED, value);
6132             }
6133             remove
6134             {
6135                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCURRENTCELLCHANGED, value);
6136             }
6137         }
6138  
6139         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.CurrentCellDirtyStateChanged"]/*‘ />
6140         [
6141             SRCategory(SR.CatBehavior), 
6142             EditorBrowsable(EditorBrowsableState.Advanced),
6143             SRDescription(SR.DataGridView_CurrentCellDirtyStateChangedDescr)
6144         ]
6145         public event EventHandler CurrentCellDirtyStateChanged
6146         {
6147             add
6148             {
6149                 this.Events.AddHandler(EVENT_DATAGRIDVIEWCURRENTCELLDIRTYSTATECHANGED, value);
6150             }
6151             remove
6152             {
6153                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWCURRENTCELLDIRTYSTATECHANGED, value);
6154             }
6155         }
6156  
6157         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.BindingComplete"]/*‘ />
6158         [
6159             SRCategory(SR.CatData), 
6160             SRDescription(SR.DataGridView_DataBindingCompleteDescr)
6161         ]
6162         public event DataGridViewBindingCompleteEventHandler DataBindingComplete
6163         {
6164             add
6165             {
6166                 this.Events.AddHandler(EVENT_DATAGRIDVIEWDATABINDINGCOMPLETE, value);
6167             }
6168             remove
6169             {
6170                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWDATABINDINGCOMPLETE, value);
6171             }
6172         }
6173  
6174         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.DataError"]/*‘ />
6175         [
6176             SRCategory(SR.CatBehavior),
6177             SRDescription(SR.DataGridView_DataErrorDescr)
6178         ]
6179         public event DataGridViewDataErrorEventHandler DataError
6180         {
6181             add 
6182             {
6183                 this.Events.AddHandler(EVENT_DATAGRIDVIEWDATAERROR, value);
6184             }
6185             remove 
6186             {
6187                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWDATAERROR, value);
6188             }
6189         }
6190  
6191         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.DefaultValuesNeeded"]/*‘ />
6192         [
6193             SRCategory(SR.CatData), 
6194             EditorBrowsable(EditorBrowsableState.Advanced),
6195             SRDescription(SR.DataGridView_DefaultValuesNeededDescr)
6196         ]
6197         public event DataGridViewRowEventHandler DefaultValuesNeeded
6198         {
6199             add
6200             {
6201                 this.Events.AddHandler(EVENT_DATAGRIDVIEWDEFAULTVALUESNEEDED, value);
6202             }
6203             remove
6204             {
6205                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWDEFAULTVALUESNEEDED, value);
6206             }
6207         }
6208  
6209         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.EditingControlShowing"]/*‘ />
6210         [
6211             SRCategory(SR.CatAction),
6212             SRDescription(SR.DataGridView_EditingControlShowingDescr)
6213         ]
6214         public event DataGridViewEditingControlShowingEventHandler EditingControlShowing
6215         {
6216             add
6217             {
6218                 this.Events.AddHandler(EVENT_DATAGRIDVIEWEDITINGCONTROLSHOWING, value);
6219             }
6220             remove
6221             {
6222                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWEDITINGCONTROLSHOWING, value);
6223             }
6224         }
6225  
6226         /*
6227         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.KeepNewRow"]/*‘ />
6228         public event QuestionEventHandler KeepNewRow
6229         {
6230             add
6231             {
6232                 this.Events.AddHandler(EVENT_DATAGRIDVIEWKEEPNEWROW, value);
6233             }
6234             remove
6235             {
6236                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWKEEPNEWROW, value);
6237             }
6238         }*/
6239  
6240         /*/// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.NewRowDiscarded"]/*‘ />
6241         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.NewRowDiscarded"]/*‘ />
6242         public event EventHandler NewRowDiscarded
6243         {
6244             add
6245             {
6246                 this.Events.AddHandler(EVENT_DATAGRIDVIEWNEWROWDISCARDED, value);
6247             }
6248             remove
6249             {
6250                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWNEWROWDISCARDED, value);
6251             }
6252         }*/
6253  
6254         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.NewRowNeeded"]/*‘ />
6255         [
6256             SRCategory(SR.CatData),
6257             SRDescription(SR.DataGridView_NewRowNeededDescr)
6258         ]
6259         public event DataGridViewRowEventHandler NewRowNeeded
6260         {
6261             add
6262             {
6263                 this.Events.AddHandler(EVENT_DATAGRIDVIEWNEWROWNEEDED, value);
6264             }
6265             remove
6266             {
6267                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWNEWROWNEEDED, value);
6268             }
6269         }
6270  
6271         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowContextMenuStripChanged"]/*‘ />
6272         [
6273             SRCategory(SR.CatPropertyChanged),
6274             SRDescription(SR.DataGridView_RowContextMenuStripChangedDescr)
6275         ]
6276         public event DataGridViewRowEventHandler RowContextMenuStripChanged
6277         {
6278             add 
6279             {
6280                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWCONTEXTMENUSTRIPCHANGED, value);
6281             }
6282             remove 
6283             {
6284                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWCONTEXTMENUSTRIPCHANGED, value);
6285             }
6286         }
6287  
6288         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowContextMenuStripNeeded"]/*‘ />
6289         [
6290             SRCategory(SR.CatData),
6291             EditorBrowsable(EditorBrowsableState.Advanced),
6292             SRDescription(SR.DataGridView_RowContextMenuStripNeededDescr)
6293         ]
6294         public event DataGridViewRowContextMenuStripNeededEventHandler RowContextMenuStripNeeded
6295         {
6296             add
6297             {
6298                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWCONTEXTMENUSTRIPNEEDED, value);
6299             }
6300             remove
6301             {
6302                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWCONTEXTMENUSTRIPNEEDED, value);
6303             }
6304         }
6305  
6306         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowDefaultCellStyleChanged"]/*‘ />
6307         [
6308             SRCategory(SR.CatPropertyChanged),
6309             SRDescription(SR.DataGridView_RowDefaultCellStyleChangedDescr)
6310         ]
6311         public event DataGridViewRowEventHandler RowDefaultCellStyleChanged 
6312         {
6313             add 
6314             {
6315                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWDEFAULTCELLSTYLECHANGED, value);
6316             }
6317             remove 
6318             {
6319                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWDEFAULTCELLSTYLECHANGED, value);
6320             }
6321         }
6322  
6323         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowDirtyStateNeeded"]/*‘ />
6324         [
6325             SRCategory(SR.CatData),
6326             EditorBrowsable(EditorBrowsableState.Advanced),
6327             SRDescription(SR.DataGridView_RowDirtyStateNeededDescr)
6328         ]
6329         public event QuestionEventHandler RowDirtyStateNeeded
6330         {
6331             add
6332             {
6333                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWDIRTYSTATENEEDED, value);
6334             }
6335             remove
6336             {
6337                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWDIRTYSTATENEEDED, value);
6338             }
6339         }
6340  
6341         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowDividerDoubleClick"]/*‘ />
6342         [
6343             SRCategory(SR.CatMouse),
6344             SRDescription(SR.DataGridView_RowDividerDoubleClickDescr)
6345         ]
6346         public event DataGridViewRowDividerDoubleClickEventHandler RowDividerDoubleClick
6347         {
6348             add
6349             {
6350                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWDIVIDERDOUBLECLICK, value);
6351             }
6352             remove
6353             {
6354                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWDIVIDERDOUBLECLICK, value);
6355             }
6356         }
6357  
6358         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowDividerHeightChanged"]/*‘ />
6359         [
6360             SRCategory(SR.CatAppearance),
6361             SRDescription(SR.DataGridView_RowDividerHeightChangedDescr)
6362         ]
6363         public event DataGridViewRowEventHandler RowDividerHeightChanged
6364         {
6365             add
6366             {
6367                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWDIVIDERHEIGHTCHANGED, value);
6368             }
6369             remove
6370             {
6371                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWDIVIDERHEIGHTCHANGED, value);
6372             }
6373         }
6374  
6375         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowEnter"]/*‘ />
6376         [
6377             SRCategory(SR.CatFocus),
6378             SRDescription(SR.DataGridView_RowEnterDescr)
6379         ]
6380         public event DataGridViewCellEventHandler RowEnter
6381         {
6382             add
6383             {
6384                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWENTER, value);
6385             }
6386             remove
6387             {
6388                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWENTER, value);
6389             }
6390         }
6391  
6392         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowErrorTextChanged"]/*‘ />
6393         [
6394             SRCategory(SR.CatPropertyChanged),
6395             SRDescription(SR.DataGridView_RowErrorTextChangedDescr)
6396         ]
6397         public event DataGridViewRowEventHandler RowErrorTextChanged
6398         {
6399             add
6400             {
6401                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWERRORTEXTCHANGED, value);
6402             }
6403             remove
6404             {
6405                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWERRORTEXTCHANGED, value);
6406             }
6407         }
6408  
6409         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowErrorTextNeeded"]/*‘ />
6410         [
6411             SRCategory(SR.CatData),
6412             EditorBrowsable(EditorBrowsableState.Advanced),
6413             SRDescription(SR.DataGridView_RowErrorTextNeededDescr)
6414         ]
6415         public event DataGridViewRowErrorTextNeededEventHandler RowErrorTextNeeded
6416         {
6417             add
6418             {
6419                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWERRORTEXTNEEDED, value);
6420             }
6421             remove
6422             {
6423                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWERRORTEXTNEEDED, value);
6424             }
6425         }
6426  
6427         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowHeaderMouseClick"]/*‘ />
6428         [
6429             SRCategory(SR.CatMouse),
6430             SRDescription(SR.DataGridView_RowHeaderMouseClickDescr)
6431         ]
6432         public event DataGridViewCellMouseEventHandler RowHeaderMouseClick 
6433         {
6434             add 
6435             {
6436                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWHEADERMOUSECLICK, value);
6437             }
6438             remove 
6439             {
6440                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWHEADERMOUSECLICK, value);
6441             }
6442         }
6443  
6444         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowHeaderMouseDoubleClick"]/*‘ />
6445         [
6446             SRCategory(SR.CatMouse),
6447             SRDescription(SR.DataGridView_RowHeaderMouseDoubleClickDescr)
6448         ]
6449         public event DataGridViewCellMouseEventHandler RowHeaderMouseDoubleClick 
6450         {
6451             add 
6452             {
6453                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWHEADERMOUSEDOUBLECLICK, value);
6454             }
6455             remove 
6456             {
6457                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWHEADERMOUSEDOUBLECLICK, value);
6458             }
6459         }
6460  
6461         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowHeaderCellChanged"]/*‘ />
6462         [
6463             SRCategory(SR.CatPropertyChanged),
6464             SRDescription(SR.DataGridView_RowHeaderCellChangedDescr)
6465         ]
6466         public event DataGridViewRowEventHandler RowHeaderCellChanged 
6467         {
6468             add 
6469             {
6470                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWHEADERCELLCHANGED, value);
6471             }
6472             remove 
6473             {
6474                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWHEADERCELLCHANGED, value);
6475             }
6476         }
6477  
6478         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowHeightChanged"]/*‘ />
6479         [
6480             SRCategory(SR.CatPropertyChanged),
6481             SRDescription(SR.DataGridView_RowHeightChangedDescr)
6482         ]
6483         public event DataGridViewRowEventHandler RowHeightChanged 
6484         {
6485             add 
6486             {
6487                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWHEIGHTCHANGED, value);
6488             }
6489             remove 
6490             {
6491                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWHEIGHTCHANGED, value);
6492             }
6493         }
6494  
6495         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowHeightInfoNeeded"]/*‘ />
6496         [
6497             SRCategory(SR.CatData),
6498             EditorBrowsable(EditorBrowsableState.Advanced),
6499             SRDescription(SR.DataGridView_RowHeightInfoNeededDescr)
6500         ]
6501         public event DataGridViewRowHeightInfoNeededEventHandler RowHeightInfoNeeded
6502         {
6503             add
6504             {
6505                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWHEIGHTINFONEEDED, value);
6506             }
6507             remove
6508             {
6509                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWHEIGHTINFONEEDED, value);
6510             }
6511         }
6512  
6513         internal DataGridViewRowHeightInfoNeededEventArgs RowHeightInfoNeededEventArgs
6514         {
6515             get
6516             {
6517                 if (this.dgvrhine == null)
6518                 {
6519                     this.dgvrhine = new DataGridViewRowHeightInfoNeededEventArgs();
6520                 }
6521                 return this.dgvrhine;
6522             }
6523         }
6524  
6525         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowHeightInfoPushed"]/*‘ />
6526         [
6527             SRCategory(SR.CatData),
6528             EditorBrowsable(EditorBrowsableState.Advanced),
6529             SRDescription(SR.DataGridView_RowHeightInfoPushedDescr)
6530         ]
6531         public event DataGridViewRowHeightInfoPushedEventHandler RowHeightInfoPushed
6532         {
6533             add
6534             {
6535                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWHEIGHTINFOPUSHED, value);
6536             }
6537             remove
6538             {
6539                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWHEIGHTINFOPUSHED, value);
6540             }
6541         }
6542  
6543         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowLeave"]/*‘ />
6544         [
6545             SRCategory(SR.CatFocus),
6546             SRDescription(SR.DataGridView_RowLeaveDescr)
6547         ]
6548         public event DataGridViewCellEventHandler RowLeave
6549         {
6550             add
6551             {
6552                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWLEAVE, value);
6553             }
6554             remove
6555             {
6556                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWLEAVE, value);
6557             }
6558         }
6559  
6560         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowMinimumHeightChanged"]/*‘ />
6561         [
6562             SRCategory(SR.CatPropertyChanged),
6563             SRDescription(SR.DataGridView_RowMinimumHeightChangedDescr)
6564         ]
6565         public event DataGridViewRowEventHandler RowMinimumHeightChanged 
6566         {
6567             add 
6568             {
6569                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWMINIMUMHEIGHTCHANGED, value);
6570             }
6571             remove 
6572             {
6573                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWMINIMUMHEIGHTCHANGED, value);
6574             }
6575         }
6576  
6577         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowPostPaint"]/*‘ />
6578         [
6579             SRCategory(SR.CatDisplay), 
6580             SRDescription(SR.DataGridView_RowPostPaintDescr)
6581         ]
6582         public event DataGridViewRowPostPaintEventHandler RowPostPaint
6583         {
6584             add
6585             {
6586                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWPOSTPAINT, value);
6587             }
6588             remove
6589             {
6590                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWPOSTPAINT, value);
6591             }
6592         }
6593  
6594         internal DataGridViewRowPostPaintEventArgs RowPostPaintEventArgs
6595         {
6596             get
6597             {
6598                 if (this.dgvrpope == null)
6599                 {
6600                     this.dgvrpope = new DataGridViewRowPostPaintEventArgs(this);
6601                 }
6602                 return this.dgvrpope;
6603             }
6604         }
6605  
6606         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowPrePaint"]/*‘ />
6607         [
6608             SRCategory(SR.CatDisplay), 
6609             SRDescription(SR.DataGridView_RowPrePaintDescr)
6610         ]
6611         public event DataGridViewRowPrePaintEventHandler RowPrePaint
6612         {
6613             add
6614             {
6615                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWPREPAINT, value);
6616             }
6617             remove
6618             {
6619                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWPREPAINT, value);
6620             }
6621         }
6622  
6623         internal DataGridViewRowPrePaintEventArgs RowPrePaintEventArgs
6624         {
6625             get
6626             {
6627                 if (this.dgvrprpe == null)
6628                 {
6629                     this.dgvrprpe = new DataGridViewRowPrePaintEventArgs(this);
6630                 }
6631                 return this.dgvrprpe;
6632             }
6633         }
6634  
6635         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowsAdded"]/*‘ />
6636         [
6637             SRCategory(SR.CatAction), 
6638             SRDescription(SR.DataGridView_RowsAddedDescr)
6639         ]
6640         public event DataGridViewRowsAddedEventHandler RowsAdded
6641         {
6642             add
6643             {
6644                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWSADDED, value);
6645             }
6646             remove
6647             {
6648                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWSADDED, value);
6649             }
6650         }
6651  
6652         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowsRemoved"]/*‘ />
6653         [
6654             SRCategory(SR.CatAction),
6655             SRDescription(SR.DataGridView_RowsRemovedDescr)
6656         ]
6657         public event DataGridViewRowsRemovedEventHandler RowsRemoved
6658         {
6659             add
6660             {
6661                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWSREMOVED, value);
6662             }
6663             remove
6664             {
6665                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWSREMOVED, value);
6666             }
6667         }
6668  
6669         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowStateChanged"]/*‘ />
6670         [
6671             SRCategory(SR.CatBehavior),
6672             SRDescription(SR.DataGridView_RowStateChangedDescr)
6673         ]
6674         public event DataGridViewRowStateChangedEventHandler RowStateChanged 
6675         {
6676             add 
6677             {
6678                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWSTATECHANGED, value);
6679             }
6680             remove 
6681             {
6682                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWSTATECHANGED, value);
6683             }
6684         }
6685  
6686         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowUnshared"]/*‘ />
6687         [
6688             SRCategory(SR.CatBehavior),
6689             EditorBrowsable(EditorBrowsableState.Advanced),
6690             SRDescription(SR.DataGridView_RowUnsharedDescr)
6691         ] 
6692         public event DataGridViewRowEventHandler RowUnshared 
6693         {
6694             add 
6695             {
6696                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWUNSHARED, value);
6697             }
6698             remove 
6699             {
6700                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWUNSHARED, value);
6701             }
6702         }
6703  
6704         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowValidated"]/*‘ />
6705         [
6706             SRCategory(SR.CatFocus),
6707             SRDescription(SR.DataGridView_RowValidatedDescr)
6708         ]
6709         public event DataGridViewCellEventHandler RowValidated
6710         {
6711             add
6712             {
6713                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWVALIDATED, value);
6714             }
6715             remove
6716             {
6717                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWVALIDATED, value);
6718             }
6719         }
6720  
6721         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.RowValidating"]/*‘ />
6722         [
6723             SRCategory(SR.CatFocus),
6724             SRDescription(SR.DataGridView_RowValidatingDescr)
6725         ]
6726         public event DataGridViewCellCancelEventHandler RowValidating
6727         {
6728             add
6729             {
6730                 this.Events.AddHandler(EVENT_DATAGRIDVIEWROWVALIDATING, value);
6731             }
6732             remove
6733             {
6734                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWROWVALIDATING, value);
6735             }
6736         }
6737  
6738         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.Scroll"]/*‘ />
6739         [
6740             SRCategory(SR.CatAction), 
6741             SRDescription(SR.DataGridView_ScrollDescr)
6742         ]
6743         public event ScrollEventHandler Scroll
6744         {
6745             add
6746             {
6747                 this.Events.AddHandler(EVENT_DATAGRIDVIEWSCROLL, value);
6748             }
6749             remove
6750             {
6751                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWSCROLL, value);
6752             }
6753         }
6754  
6755         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.SelectionChanged"]/*‘ />
6756         [
6757             SRCategory(SR.CatAction),
6758             SRDescription(SR.DataGridView_SelectionChangedDescr)
6759         ]
6760         public event EventHandler SelectionChanged
6761         {
6762             add
6763             {
6764                 this.Events.AddHandler(EVENT_DATAGRIDVIEWSELECTIONCHANGED, value);
6765             }
6766             remove 
6767             {
6768                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWSELECTIONCHANGED, value);
6769             }
6770         }
6771  
6772         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.SortCompare"]/*‘ />
6773         [
6774             SRCategory(SR.CatData),
6775             EditorBrowsable(EditorBrowsableState.Advanced),
6776             SRDescription(SR.DataGridView_SortCompareDescr)
6777         ]
6778         public event DataGridViewSortCompareEventHandler SortCompare
6779         {
6780             add
6781             {
6782                 this.Events.AddHandler(EVENT_DATAGRIDVIEWSORTCOMPARE, value);
6783             }
6784             remove
6785             {
6786                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWSORTCOMPARE, value);
6787             }
6788         }
6789  
6790         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.Sorted"]/*‘ />
6791         [
6792             SRCategory(SR.CatData),
6793             SRDescription(SR.DataGridView_SortedDescr)
6794         ]
6795         public event EventHandler Sorted
6796         {
6797             add
6798             {
6799                 this.Events.AddHandler(EVENT_DATAGRIDVIEWSORTED, value);
6800             }
6801             remove
6802             {
6803                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWSORTED, value);
6804             }
6805         }
6806  
6807         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.StyleChanged"]/*‘ />
6808         /// <internalonly/>
6809         [
6810             Browsable(false), 
6811             EditorBrowsable(EditorBrowsableState.Never)
6812         ]
6813         new public event EventHandler StyleChanged
6814         {
6815             add
6816             {
6817                 base.StyleChanged += value;
6818             }
6819             remove
6820             {
6821                 base.StyleChanged -= value;
6822             }
6823         }
6824  
6825         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.UserAddedRow"]/*‘ />
6826         [
6827             SRCategory(SR.CatAction),
6828             SRDescription(SR.DataGridView_UserAddedRowDescr)
6829         ]
6830         public event DataGridViewRowEventHandler UserAddedRow
6831         {
6832             add
6833             {
6834                 this.Events.AddHandler(EVENT_DATAGRIDVIEWUSERADDEDROW, value);
6835             }
6836             remove
6837             {
6838                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWUSERADDEDROW, value);
6839             }
6840         }
6841  
6842         /*/// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.UserAddingRow"]/*‘ />
6843         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.UserAddingRow"]/*‘ />
6844         public event DataGridViewRowCancelEventHandler UserAddingRow
6845         {
6846             add
6847             {
6848                 this.Events.AddHandler(EVENT_DATAGRIDVIEWUSERADDINGROW, value);
6849             }
6850             remove
6851             {
6852                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWUSERADDINGROW, value);
6853             }
6854         }*/
6855  
6856         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.UserDeletedRow"]/*‘ />
6857         [
6858             SRCategory(SR.CatAction),
6859             SRDescription(SR.DataGridView_UserDeletedRowDescr)
6860         ]
6861         public event DataGridViewRowEventHandler UserDeletedRow
6862         {
6863             add
6864             {
6865                 this.Events.AddHandler(EVENT_DATAGRIDVIEWUSERDELETEDROW, value);
6866             }
6867             remove
6868             {
6869                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWUSERDELETEDROW, value);
6870             }
6871         }
6872  
6873         /// <include file=‘doc\DataGridView.uex‘ path=‘docs/doc[@for="DataGridView.UserDeletingRow"]/*‘ />
6874         [
6875             SRCategory(SR.CatAction),
6876             SRDescription(SR.DataGridView_UserDeletingRowDescr)
6877         ]
6878         public event DataGridViewRowCancelEventHandler UserDeletingRow
6879         {
6880             add
6881             {
6882                 this.Events.AddHandler(EVENT_DATAGRIDVIEWUSERDELETINGROW, value);
6883             }
6884             remove
6885             {
6886                 this.Events.RemoveHandler(EVENT_DATAGRIDVIEWUSERDELETINGROW, value);
6887             }
6888         }
6889  
6890         ////////////////////////
6891         //                    //
6892         // ISupportInitialize //
6893         //                    //
6894         ////////////////////////
6895         [
6896             SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes") // VSWhidbey 405004
6897         ]
6898         void ISupportInitialize.BeginInit()
6899         {
6900             if (this.dataGridViewState2[DATAGRIDVIEWSTATE2_initializing])
6901             {
6902                 throw new InvalidOperationException(SR.GetString(SR.DataGridViewBeginInit));
6903             }
6904  
6905             this.dataGridViewState2[DATAGRIDVIEWSTATE2_initializing] = true;
6906         }
6907  
6908         [
6909             SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes") // VSWhidbey 405004
6910         ]
6911         void ISupportInitialize.EndInit()
6912         {
6913             this.dataGridViewState2[DATAGRIDVIEWSTATE2_initializing] = false;
6914  
6915             foreach (DataGridViewColumn dataGridViewColumn in this.Columns)
6916             {
6917                 if (dataGridViewColumn.Frozen &&
6918                     dataGridViewColumn.Visible &&
6919                     dataGridViewColumn.InheritedAutoSizeMode == DataGridViewAutoSizeColumnMode.Fill)
6920                 {
6921                     dataGridViewColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
6922                 }
6923             }
6924  
6925             DataGridViewSelectionMode selectionMode = this.SelectionMode;
6926             if (selectionMode == DataGridViewSelectionMode.FullColumnSelect || selectionMode == DataGridViewSelectionMode.ColumnHeaderSelect)
6927             {
6928                 foreach (DataGridViewColumn dataGridViewColumn in this.Columns)
6929                 {
6930                     if (dataGridViewColumn.SortMode == DataGridViewColumnSortMode.Automatic)
6931                     {
6932                         // Resetting SelectionMode to its acceptable default value. We don‘t want the control to ever end up in an invalid state.
6933                         this.SelectionMode = defaultSelectionMode; // DataGridViewSelectionMode.RowHeaderSelect
6934                         throw new InvalidOperationException(SR.GetString(SR.DataGridView_SelectionModeReset, 
6935                                                                          SR.GetString(SR.DataGridView_SelectionModeAndSortModeClash, (selectionMode).ToString()), 
6936                                                                          (defaultSelectionMode).ToString()));
6937                     }
6938                 }
6939             }
6940         }
6941  
6942         /* INTERNAL ENUMERATIONS */
6943  
6944         internal enum DataGridViewHitTestTypeInternal 
6945         {
6946             None,
6947             Cell,
6948             ColumnHeader,
6949             RowHeader,
6950             ColumnResizeLeft,
6951             ColumnResizeRight,
6952             RowResizeTop,
6953             RowResizeBottom,
6954             FirstColumnHeaderLeft,
6955             TopLeftHeader,
6956             TopLeftHeaderResizeLeft,
6957             TopLeftHeaderResizeRight,
6958             TopLeftHeaderResizeTop,
6959             TopLeftHeaderResizeBottom,
6960             ColumnHeadersResizeBottom,
6961             ColumnHeadersResizeTop,
6962             RowHeadersResizeRight,
6963             RowHeadersResizeLeft,
6964             ColumnHeaderLeft,
6965             ColumnHeaderRight
6966         }
6967  
6968         internal enum DataGridViewValidateCellInternal
6969         {
6970             Never,
6971             Always,
6972             WhenChanged
6973         }
6974  
6975         private enum DataGridViewMouseEvent
6976         {
6977             Click,
6978             DoubleClick,
6979             MouseClick,
6980             MouseDoubleClick,
6981             MouseDown,
6982             MouseUp,
6983             MouseMove
6984         }
6985  
6986         private struct MouseClickInfo
6987         {
6988             public MouseButtons button;
6989             public long timeStamp;
6990             public int x;
6991             public int y;
6992             public int col;
6993             public int row;
6994         }
6995     }
6996 }
6997 Document OutlineProject ExplorerNamespace Explorer
View Code

 

System.Windows.Forms

原文:http://www.cnblogs.com/endv/p/4273586.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!