_converters;
private static Color s_defaultBackColor = SystemColors.Window;
private static Color s_defaultBackgroundColor = SystemColors.ControlDark;
private Color _backgroundColor = s_defaultBackgroundColor;
- private RECT[] _cachedScrollableRegion;
+ private RECT[]? _cachedScrollableRegion;
// ToolTip
private readonly DataGridViewToolTip _toolTipControl;
@@ -684,7 +691,7 @@ internal bool AllowUserToAddRowsInternal
[SRCategory(nameof(SR.CatPropertyChanged))]
[SRDescription(nameof(SR.DataGridViewOnAllowUserToAddRowsChangedDescr))]
- public event EventHandler AllowUserToAddRowsChanged
+ public event EventHandler? AllowUserToAddRowsChanged
{
add => Events.AddHandler(s_allowUserToAddRowsChangedEvent, value);
remove => Events.RemoveHandler(s_allowUserToAddRowsChangedEvent, value);
@@ -726,7 +733,7 @@ internal bool AllowUserToDeleteRowsInternal
[SRCategory(nameof(SR.CatPropertyChanged))]
[SRDescription(nameof(SR.DataGridViewOnAllowUserToDeleteRowsChangedDescr))]
- public event EventHandler AllowUserToDeleteRowsChanged
+ public event EventHandler? AllowUserToDeleteRowsChanged
{
add => Events.AddHandler(s_allowUserToDeleteRowsChangedEvent, value);
remove => Events.RemoveHandler(s_allowUserToDeleteRowsChangedEvent, value);
@@ -753,7 +760,7 @@ public bool AllowUserToOrderColumns
[SRCategory(nameof(SR.CatPropertyChanged))]
[SRDescription(nameof(SR.DataGridViewOnAllowUserToOrderColumnsChangedDescr))]
- public event EventHandler AllowUserToOrderColumnsChanged
+ public event EventHandler? AllowUserToOrderColumnsChanged
{
add => Events.AddHandler(s_allowUserToOrderColumnsChangedEvent, value);
remove => Events.RemoveHandler(s_allowUserToOrderColumnsChangedEvent, value);
@@ -784,7 +791,7 @@ public bool AllowUserToResizeColumns
[SRCategory(nameof(SR.CatPropertyChanged))]
[SRDescription(nameof(SR.DataGridViewOnAllowUserToResizeColumnsChangedDescr))]
- public event EventHandler AllowUserToResizeColumnsChanged
+ public event EventHandler? AllowUserToResizeColumnsChanged
{
add => Events.AddHandler(s_allowUserToResizeColumnsChangedEvent, value);
remove => Events.RemoveHandler(s_allowUserToResizeColumnsChangedEvent, value);
@@ -815,7 +822,7 @@ public bool AllowUserToResizeRows
[SRCategory(nameof(SR.CatPropertyChanged))]
[SRDescription(nameof(SR.DataGridViewOnAllowUserToResizeRowsChangedDescr))]
- public event EventHandler AllowUserToResizeRowsChanged
+ public event EventHandler? AllowUserToResizeRowsChanged
{
add => Events.AddHandler(s_allowUserToResizeRowsChangedEvent, value);
remove => Events.RemoveHandler(s_allowUserToResizeRowsChangedEvent, value);
@@ -823,6 +830,7 @@ public event EventHandler AllowUserToResizeRowsChanged
[SRCategory(nameof(SR.CatAppearance))]
[SRDescription(nameof(SR.DataGridView_AlternatingRowsDefaultCellStyleDescr))]
+ [AllowNull]
public DataGridViewCellStyle AlternatingRowsDefaultCellStyle
{
get
@@ -840,10 +848,7 @@ public DataGridViewCellStyle AlternatingRowsDefaultCellStyle
DataGridViewCellStyle cs = AlternatingRowsDefaultCellStyle;
cs.RemoveScope(DataGridViewCellStyleScopes.AlternatingRows);
_alternatingRowsDefaultCellStyle = value;
- if (value is not null)
- {
- _alternatingRowsDefaultCellStyle.AddScope(this, DataGridViewCellStyleScopes.AlternatingRows);
- }
+ _alternatingRowsDefaultCellStyle?.AddScope(this, DataGridViewCellStyleScopes.AlternatingRows);
DataGridViewCellStyleDifferences dgvcsc = cs.GetDifferencesFrom(AlternatingRowsDefaultCellStyle);
if (dgvcsc != DataGridViewCellStyleDifferences.None)
@@ -856,7 +861,7 @@ public DataGridViewCellStyle AlternatingRowsDefaultCellStyle
[SRCategory(nameof(SR.CatPropertyChanged))]
[SRDescription(nameof(SR.DataGridViewAlternatingRowsDefaultCellStyleChangedDescr))]
- public event EventHandler AlternatingRowsDefaultCellStyleChanged
+ public event EventHandler? AlternatingRowsDefaultCellStyleChanged
{
add => Events.AddHandler(s_alternatingRowsDefaultCellStyleChangedEvent, value);
remove => Events.RemoveHandler(s_alternatingRowsDefaultCellStyleChangedEvent, value);
@@ -899,7 +904,7 @@ public bool AutoGenerateColumns
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
- public event EventHandler AutoGenerateColumnsChanged
+ public event EventHandler? AutoGenerateColumnsChanged
{
add => Events.AddHandler(s_autoGenerateColumnsChangedEvent, value);
remove => Events.RemoveHandler(s_autoGenerateColumnsChangedEvent, value);
@@ -990,7 +995,7 @@ public DataGridViewAutoSizeColumnsMode AutoSizeColumnsMode
[SRCategory(nameof(SR.CatPropertyChanged))]
[SRDescription(nameof(SR.DataGridViewAutoSizeColumnsModeChangedDescr))]
- public event DataGridViewAutoSizeColumnsModeEventHandler AutoSizeColumnsModeChanged
+ public event DataGridViewAutoSizeColumnsModeEventHandler? AutoSizeColumnsModeChanged
{
add => Events.AddHandler(s_autosizeColumnsModeChangedEvent, value);
remove => Events.RemoveHandler(s_autosizeColumnsModeChangedEvent, value);
@@ -1041,7 +1046,7 @@ public DataGridViewAutoSizeRowsMode AutoSizeRowsMode
[SRCategory(nameof(SR.CatPropertyChanged))]
[SRDescription(nameof(SR.DataGridViewAutoSizeRowsModeChangedDescr))]
- public event DataGridViewAutoSizeModeEventHandler AutoSizeRowsModeChanged
+ public event DataGridViewAutoSizeModeEventHandler? AutoSizeRowsModeChanged
{
add => Events.AddHandler(s_autosizeRowsModeChangedEvent, value);
remove => Events.RemoveHandler(s_autosizeRowsModeChangedEvent, value);
@@ -1058,7 +1063,7 @@ public override Color BackColor
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
- public new event EventHandler BackColorChanged
+ public new event EventHandler? BackColorChanged
{
add => base.BackColorChanged += value;
remove => base.BackColorChanged -= value;
@@ -1089,7 +1094,7 @@ public Color BackgroundColor
[SRCategory(nameof(SR.CatPropertyChanged))]
[SRDescription(nameof(SR.DataGridViewBackgroundColorChangedDescr))]
- public event EventHandler BackgroundColorChanged
+ public event EventHandler? BackgroundColorChanged
{
add => Events.AddHandler(s_backgroundColorChangedEvent, value);
remove => Events.RemoveHandler(s_backgroundColorChangedEvent, value);
@@ -1097,7 +1102,7 @@ public event EventHandler BackgroundColorChanged
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
- public override Image BackgroundImage
+ public override Image? BackgroundImage
{
get => base.BackgroundImage;
set => base.BackgroundImage = value;
@@ -1113,7 +1118,7 @@ public override ImageLayout BackgroundImageLayout
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
- public new event EventHandler BackgroundImageChanged
+ public new event EventHandler? BackgroundImageChanged
{
add => base.BackgroundImageChanged += value;
remove => base.BackgroundImageChanged -= value;
@@ -1121,14 +1126,14 @@ public override ImageLayout BackgroundImageLayout
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
- public new event EventHandler BackgroundImageLayoutChanged
+ public new event EventHandler? BackgroundImageLayoutChanged
{
add => base.BackgroundImageLayoutChanged += value;
remove => base.BackgroundImageLayoutChanged -= value;
}
private bool ShouldSerializeBackgroundColor() => !BackgroundColor.Equals(s_defaultBackgroundColor);
-
+#nullable disable
[DefaultValue(BorderStyle.FixedSingle)]
[SRCategory(nameof(SR.CatAppearance))]
[SRDescription(nameof(SR.DataGridView_BorderStyleDescr))]
@@ -2624,10 +2629,8 @@ public int FirstDisplayedScrollingColumnIndex
}
set
{
- if (value < 0 || value >= Columns.Count)
- {
- throw new ArgumentOutOfRangeException(nameof(value));
- }
+ ArgumentOutOfRangeException.ThrowIfNegative(value);
+ ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(value, Columns.Count);
if (!Columns[value].Visible)
{
@@ -2701,10 +2704,8 @@ public int FirstDisplayedScrollingRowIndex
}
set
{
- if (value < 0 || value >= Rows.Count)
- {
- throw new ArgumentOutOfRangeException(nameof(value));
- }
+ ArgumentOutOfRangeException.ThrowIfNegative(value);
+ ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(value, Rows.Count);
if ((Rows.GetRowState(value) & DataGridViewElementStates.Visible) == 0)
{
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAdvancedBorderStyle.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAdvancedBorderStyle.cs
index 8cb7e5d605c..de7eadd5c01 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAdvancedBorderStyle.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAdvancedBorderStyle.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAdvancedCellBorderStyle.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAdvancedCellBorderStyle.cs
index 2e500059cae..c9cd9cfdd14 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAdvancedCellBorderStyle.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAdvancedCellBorderStyle.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeColumnCriteriaInternal.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeColumnCriteriaInternal.cs
index 7d95f61011f..e3a61601b9a 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeColumnCriteriaInternal.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeColumnCriteriaInternal.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeColumnMode.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeColumnMode.cs
index 213c97a0ee1..17179645b2e 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeColumnMode.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeColumnMode.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeColumnModeEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeColumnModeEventArgs.cs
index 7202f60f557..a1012aeeaf5 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeColumnModeEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeColumnModeEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeColumnsMode.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeColumnsMode.cs
index 5a8ff73cfb8..b1d9a9ee014 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeColumnsMode.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeColumnsMode.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeColumnsModeEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeColumnsModeEventArgs.cs
index cabc0c16714..512f6a14894 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeColumnsModeEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeColumnsModeEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeModeEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeModeEventArgs.cs
index e30fd0b12cb..4e6ada76121 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeModeEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeModeEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeRowCriteriaInternal.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeRowCriteriaInternal.cs
index 39110cb91b1..c0f3da807fb 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeRowCriteriaInternal.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeRowCriteriaInternal.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeRowMode.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeRowMode.cs
index 7f0c1189ebc..f1b09ae4b56 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeRowMode.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeRowMode.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeRowsMode.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeRowsMode.cs
index 883812e6498..41e51cf8d50 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeRowsMode.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeRowsMode.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeRowsModeInternal.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeRowsModeInternal.cs
index 980f59fbcc4..f3a8dbd275a 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeRowsModeInternal.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewAutoSizeRowsModeInternal.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewBand.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewBand.cs
index bcd3c5d3bcd..85a6b17bb41 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewBand.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewBand.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.ComponentModel;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewBindingCompleteEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewBindingCompleteEventArgs.cs
index 5f151a574cb..cd13f9712e9 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewBindingCompleteEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewBindingCompleteEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.ComponentModel;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewButtonCell.DataGridViewButtonCellAccessibleObject.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewButtonCell.DataGridViewButtonCellAccessibleObject.cs
index 96e82e14927..d5a0e4c1ac6 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewButtonCell.DataGridViewButtonCellAccessibleObject.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewButtonCell.DataGridViewButtonCellAccessibleObject.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using static Interop;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewButtonCell.DataGridViewButtonCellRenderer.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewButtonCell.DataGridViewButtonCellRenderer.cs
index 0a3466c4e02..f9c8a6bb2af 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewButtonCell.DataGridViewButtonCellRenderer.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewButtonCell.DataGridViewButtonCellRenderer.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.Drawing;
using System.Windows.Forms.VisualStyles;
@@ -17,7 +16,7 @@ public static VisualStyleRenderer DataGridViewButtonRenderer
{
get
{
- s_visualStyleRenderer ??= new VisualStyleRenderer(ButtonElement);
+ s_visualStyleRenderer ??= new VisualStyleRenderer(s_buttonElement);
return s_visualStyleRenderer;
}
@@ -25,7 +24,7 @@ public static VisualStyleRenderer DataGridViewButtonRenderer
public static void DrawButton(Graphics g, Rectangle bounds, int buttonState)
{
- DataGridViewButtonRenderer.SetParameters(ButtonElement.ClassName, ButtonElement.Part, buttonState);
+ DataGridViewButtonRenderer.SetParameters(s_buttonElement.ClassName, s_buttonElement.Part, buttonState);
DataGridViewButtonRenderer.DrawBackground(g, bounds, Rectangle.Truncate(g.ClipBounds));
}
}
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewButtonCell.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewButtonCell.cs
index 75ae1f15d74..ab8286119cf 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewButtonCell.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewButtonCell.cs
@@ -1,8 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-#nullable disable
using System.ComponentModel;
using System.Drawing;
@@ -17,22 +14,22 @@ namespace System.Windows.Forms;
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
public partial class DataGridViewButtonCell : DataGridViewCell
{
- private static readonly int PropButtonCellFlatStyle = PropertyStore.CreateKey();
- private static readonly int PropButtonCellState = PropertyStore.CreateKey();
- private static readonly int PropButtonCellUseColumnTextForButtonValue = PropertyStore.CreateKey();
- private static readonly VisualStyleElement ButtonElement = VisualStyleElement.Button.PushButton.Normal;
+ private static readonly int s_propButtonCellFlatStyle = PropertyStore.CreateKey();
+ private static readonly int s_propButtonCellState = PropertyStore.CreateKey();
+ private static readonly int s_propButtonCellUseColumnTextForButtonValue = PropertyStore.CreateKey();
+ private static readonly VisualStyleElement s_buttonElement = VisualStyleElement.Button.PushButton.Normal;
private const byte DATAGRIDVIEWBUTTONCELL_themeMargin = 100; // Used to calculate the margins required for theming rendering
private const byte DATAGRIDVIEWBUTTONCELL_horizontalTextMargin = 2;
private const byte DATAGRIDVIEWBUTTONCELL_verticalTextMargin = 1;
private const byte DATAGRIDVIEWBUTTONCELL_textPadding = 5;
- private static Rectangle rectThemeMargins = new Rectangle(-1, -1, 0, 0);
- private static bool mouseInContentBounds;
+ private static Rectangle s_rectThemeMargins = new(-1, -1, 0, 0);
+ private static bool s_mouseInContentBounds;
- private static readonly Type defaultFormattedValueType = typeof(string);
- private static readonly Type defaultValueType = typeof(object);
- private static readonly Type cellType = typeof(DataGridViewButtonCell);
+ private static readonly Type s_defaultFormattedValueType = typeof(string);
+ private static readonly Type s_defaultValueType = typeof(object);
+ private static readonly Type s_cellType = typeof(DataGridViewButtonCell);
public DataGridViewButtonCell()
{
@@ -42,7 +39,7 @@ private ButtonState ButtonState
{
get
{
- int buttonState = Properties.GetInteger(PropButtonCellState, out bool found);
+ int buttonState = Properties.GetInteger(s_propButtonCellState, out bool found);
if (found)
{
return (ButtonState)buttonState;
@@ -57,13 +54,13 @@ private ButtonState ButtonState
Debug.Assert((value & ~(ButtonState.Normal | ButtonState.Pushed | ButtonState.Checked)) == 0);
if (ButtonState != value)
{
- Properties.SetInteger(PropButtonCellState, (int)value);
+ Properties.SetInteger(s_propButtonCellState, (int)value);
}
}
}
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.Interfaces)]
- public override Type EditType
+ public override Type? EditType
{
get
{
@@ -77,7 +74,7 @@ public FlatStyle FlatStyle
{
get
{
- int flatStyle = Properties.GetInteger(PropButtonCellFlatStyle, out bool found);
+ int flatStyle = Properties.GetInteger(s_propButtonCellFlatStyle, out bool found);
if (found)
{
return (FlatStyle)flatStyle;
@@ -91,7 +88,7 @@ public FlatStyle FlatStyle
SourceGenerated.EnumValidator.Validate(value);
if (value != FlatStyle)
{
- Properties.SetInteger(PropButtonCellFlatStyle, (int)value);
+ Properties.SetInteger(s_propButtonCellFlatStyle, (int)value);
OnCommonChange();
}
}
@@ -104,26 +101,21 @@ internal FlatStyle FlatStyleInternal
Debug.Assert(value >= FlatStyle.Flat && value <= FlatStyle.System);
if (value != FlatStyle)
{
- Properties.SetInteger(PropButtonCellFlatStyle, (int)value);
+ Properties.SetInteger(s_propButtonCellFlatStyle, (int)value);
}
}
}
- public override Type FormattedValueType
- {
- get
- {
- // we return string for the formatted type
- return defaultFormattedValueType;
- }
- }
+ public override Type FormattedValueType =>
+ // We return string for the formatted type.
+ s_defaultFormattedValueType;
[DefaultValue(false)]
public bool UseColumnTextForButtonValue
{
get
{
- int useColumnTextForButtonValue = Properties.GetInteger(PropButtonCellUseColumnTextForButtonValue, out bool found);
+ int useColumnTextForButtonValue = Properties.GetInteger(s_propButtonCellUseColumnTextForButtonValue, out bool found);
if (found)
{
return useColumnTextForButtonValue == 0 ? false : true;
@@ -135,7 +127,7 @@ public bool UseColumnTextForButtonValue
{
if (value != UseColumnTextForButtonValue)
{
- Properties.SetInteger(PropButtonCellUseColumnTextForButtonValue, value ? 1 : 0);
+ Properties.SetInteger(s_propButtonCellUseColumnTextForButtonValue, value ? 1 : 0);
OnCommonChange();
}
}
@@ -147,7 +139,7 @@ internal bool UseColumnTextForButtonValueInternal
{
if (value != UseColumnTextForButtonValue)
{
- Properties.SetInteger(PropButtonCellUseColumnTextForButtonValue, value ? 1 : 0);
+ Properties.SetInteger(s_propButtonCellUseColumnTextForButtonValue, value ? 1 : 0);
}
}
}
@@ -162,7 +154,7 @@ public override Type ValueType
return valueType;
}
- return defaultValueType;
+ return s_defaultValueType;
}
}
@@ -171,13 +163,13 @@ public override object Clone()
DataGridViewButtonCell dataGridViewCell;
Type thisType = GetType();
- if (thisType == cellType) //performance improvement
+ if (thisType == s_cellType) //performance improvement
{
dataGridViewCell = new DataGridViewButtonCell();
}
else
{
- dataGridViewCell = (DataGridViewButtonCell)System.Activator.CreateInstance(thisType);
+ dataGridViewCell = (DataGridViewButtonCell)Activator.CreateInstance(thisType)!;
}
base.CloneInternal(dataGridViewCell);
@@ -186,10 +178,7 @@ public override object Clone()
return dataGridViewCell;
}
- protected override AccessibleObject CreateAccessibilityInstance()
- {
- return new DataGridViewButtonCellAccessibleObject(this);
- }
+ protected override AccessibleObject CreateAccessibilityInstance() => new DataGridViewButtonCellAccessibleObject(this);
protected override Rectangle GetContentBounds(Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex)
{
@@ -206,7 +195,8 @@ protected override Rectangle GetContentBounds(Graphics graphics, DataGridViewCel
out DataGridViewElementStates cellState,
out Rectangle cellBounds);
- Rectangle contentBounds = PaintPrivate(graphics,
+ Rectangle contentBounds = PaintPrivate(
+ graphics,
cellBounds,
cellBounds,
rowIndex,
@@ -221,27 +211,28 @@ protected override Rectangle GetContentBounds(Graphics graphics, DataGridViewCel
paint: false);
#if DEBUG
- object value = GetValue(rowIndex);
- Rectangle contentBoundsDebug = PaintPrivate(graphics,
+ object? value = GetValue(rowIndex);
+ Rectangle contentBoundsDebug = PaintPrivate(
+ graphics,
cellBounds,
cellBounds,
rowIndex,
cellState,
- GetFormattedValue(value, rowIndex, ref cellStyle, null, null, DataGridViewDataErrorContexts.Formatting),
+ GetFormattedValue(value, rowIndex, ref cellStyle, valueTypeConverter: null, formattedValueTypeConverter: null, DataGridViewDataErrorContexts.Formatting),
GetErrorText(rowIndex),
cellStyle,
dgvabsEffective,
DataGridViewPaintParts.ContentForeground,
- true /*computeContentBounds*/,
- false /*computeErrorIconBounds*/,
- false /*paint*/);
+ computeContentBounds: true,
+ computeErrorIconBounds: false,
+ paint: false);
Debug.Assert(contentBoundsDebug.Equals(contentBounds));
#endif
return contentBounds;
}
- private protected override string GetDefaultToolTipText()
+ private protected override string? GetDefaultToolTipText()
{
if (string.IsNullOrEmpty(Value?.ToString()?.Trim(' ')) || Value is DBNull)
{
@@ -264,44 +255,54 @@ OwningColumn is null ||
return Rectangle.Empty;
}
- ComputeBorderStyleCellStateAndCellBounds(rowIndex, out DataGridViewAdvancedBorderStyle dgvabsEffective, out DataGridViewElementStates cellState, out Rectangle cellBounds);
+ ComputeBorderStyleCellStateAndCellBounds(
+ rowIndex,
+ out DataGridViewAdvancedBorderStyle dgvabsEffective,
+ out DataGridViewElementStates cellState,
+ out Rectangle cellBounds);
- Rectangle errorIconBounds = PaintPrivate(graphics,
+ Rectangle errorIconBounds = PaintPrivate(
+ graphics,
cellBounds,
cellBounds,
rowIndex,
cellState,
- null /*formattedValue*/, // errorIconBounds is independent of formattedValue
+ formattedValue: null, // errorIconBounds is independent of formattedValue
GetErrorText(rowIndex),
cellStyle,
dgvabsEffective,
DataGridViewPaintParts.ContentForeground,
- false /*computeContentBounds*/,
- true /*computeErrorIconBounds*/,
- false /*paint*/);
+ computeContentBounds: false,
+ computeErrorIconBounds: true,
+ paint: false);
#if DEBUG
- object value = GetValue(rowIndex);
- Rectangle errorIconBoundsDebug = PaintPrivate(graphics,
+ object? value = GetValue(rowIndex);
+ Rectangle errorIconBoundsDebug = PaintPrivate(
+ graphics,
cellBounds,
cellBounds,
rowIndex,
cellState,
- GetFormattedValue(value, rowIndex, ref cellStyle, null, null, DataGridViewDataErrorContexts.Formatting),
+ GetFormattedValue(value, rowIndex, ref cellStyle, valueTypeConverter: null, formattedValueTypeConverter: null, DataGridViewDataErrorContexts.Formatting),
GetErrorText(rowIndex),
cellStyle,
dgvabsEffective,
DataGridViewPaintParts.ContentForeground,
- false /*computeContentBounds*/,
- true /*computeErrorIconBounds*/,
- false /*paint*/);
+ computeContentBounds: false,
+ computeErrorIconBounds: true,
+ paint: false);
Debug.Assert(errorIconBoundsDebug.Equals(errorIconBounds));
#endif
return errorIconBounds;
}
- protected override Size GetPreferredSize(Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize)
+ protected override Size GetPreferredSize(
+ Graphics graphics,
+ DataGridViewCellStyle cellStyle,
+ int rowIndex,
+ Size constraintSize)
{
if (DataGridView is null)
{
@@ -316,7 +317,7 @@ protected override Size GetPreferredSize(Graphics graphics, DataGridViewCellStyl
int borderAndPaddingHeights = borderWidthsRect.Top + borderWidthsRect.Height + cellStyle.Padding.Vertical;
DataGridViewFreeDimension freeDimension = DataGridViewCell.GetFreeDimensionFromConstraint(constraintSize);
int marginWidths, marginHeights;
- string formattedString = GetFormattedValue(rowIndex, ref cellStyle, DataGridViewDataErrorContexts.Formatting | DataGridViewDataErrorContexts.PreferredSize) as string;
+ string? formattedString = GetFormattedValue(rowIndex, ref cellStyle, DataGridViewDataErrorContexts.Formatting | DataGridViewDataErrorContexts.PreferredSize) as string;
if (string.IsNullOrEmpty(formattedString))
{
formattedString = " ";
@@ -349,8 +350,7 @@ protected override Size GetPreferredSize(Graphics graphics, DataGridViewCellStyl
graphics,
formattedString,
cellStyle.Font,
- constraintSize.Height - borderAndPaddingHeights - marginHeights - 2
- * DATAGRIDVIEWBUTTONCELL_verticalTextMargin,
+ constraintSize.Height - borderAndPaddingHeights - marginHeights - 2 * DATAGRIDVIEWBUTTONCELL_verticalTextMargin,
flags),
0);
}
@@ -432,62 +432,49 @@ protected override Size GetPreferredSize(Graphics graphics, DataGridViewCellStyl
private static Rectangle GetThemeMargins(Graphics g)
{
- if (rectThemeMargins.X == -1)
+ if (s_rectThemeMargins.X == -1)
{
Rectangle rectCell = new Rectangle(0, 0, DATAGRIDVIEWBUTTONCELL_themeMargin, DATAGRIDVIEWBUTTONCELL_themeMargin);
Rectangle rectContent = DataGridViewButtonCellRenderer.DataGridViewButtonRenderer.GetBackgroundContentRectangle(g, rectCell);
- rectThemeMargins.X = rectContent.X;
- rectThemeMargins.Y = rectContent.Y;
- rectThemeMargins.Width = DATAGRIDVIEWBUTTONCELL_themeMargin - rectContent.Right;
- rectThemeMargins.Height = DATAGRIDVIEWBUTTONCELL_themeMargin - rectContent.Bottom;
+ s_rectThemeMargins.X = rectContent.X;
+ s_rectThemeMargins.Y = rectContent.Y;
+ s_rectThemeMargins.Width = DATAGRIDVIEWBUTTONCELL_themeMargin - rectContent.Right;
+ s_rectThemeMargins.Height = DATAGRIDVIEWBUTTONCELL_themeMargin - rectContent.Bottom;
}
- return rectThemeMargins;
+ return s_rectThemeMargins;
}
- protected override object GetValue(int rowIndex)
+ protected override object? GetValue(int rowIndex)
{
if (UseColumnTextForButtonValue &&
DataGridView is not null &&
DataGridView.NewRowIndex != rowIndex &&
- OwningColumn is not null &&
- OwningColumn is DataGridViewButtonColumn)
+ OwningColumn is DataGridViewButtonColumn dataGridViewButtonColumn)
{
- return ((DataGridViewButtonColumn)OwningColumn).Text;
+ return dataGridViewButtonColumn.Text;
}
return base.GetValue(rowIndex);
}
- protected override bool KeyDownUnsharesRow(KeyEventArgs e, int rowIndex)
- {
- return e.KeyCode == Keys.Space && !e.Alt && !e.Control && !e.Shift;
- }
+ protected override bool KeyDownUnsharesRow(KeyEventArgs e, int rowIndex) =>
+ e.KeyCode == Keys.Space && !e.Alt && !e.Control && !e.Shift;
- protected override bool KeyUpUnsharesRow(KeyEventArgs e, int rowIndex)
- {
- return e.KeyCode == Keys.Space;
- }
+ protected override bool KeyUpUnsharesRow(KeyEventArgs e, int rowIndex) =>
+ e.KeyCode == Keys.Space;
- protected override bool MouseDownUnsharesRow(DataGridViewCellMouseEventArgs e)
- {
- return e.Button == MouseButtons.Left;
- }
+ protected override bool MouseDownUnsharesRow(DataGridViewCellMouseEventArgs e) =>
+ e.Button == MouseButtons.Left;
- protected override bool MouseEnterUnsharesRow(int rowIndex)
- {
- return ColumnIndex == DataGridView.MouseDownCellAddress.X && rowIndex == DataGridView.MouseDownCellAddress.Y;
- }
+ protected override bool MouseEnterUnsharesRow(int rowIndex) =>
+ ColumnIndex == DataGridView!.MouseDownCellAddress.X && rowIndex == DataGridView.MouseDownCellAddress.Y;
- protected override bool MouseLeaveUnsharesRow(int rowIndex)
- {
- return (ButtonState & ButtonState.Pushed) != 0;
- }
+ protected override bool MouseLeaveUnsharesRow(int rowIndex) =>
+ (ButtonState & ButtonState.Pushed) != 0;
- protected override bool MouseUpUnsharesRow(DataGridViewCellMouseEventArgs e)
- {
- return e.Button == MouseButtons.Left;
- }
+ protected override bool MouseUpUnsharesRow(DataGridViewCellMouseEventArgs e) =>
+ e.Button == MouseButtons.Left;
protected override void OnKeyDown(KeyEventArgs e, int rowIndex)
{
@@ -549,7 +536,7 @@ protected override void OnMouseDown(DataGridViewCellMouseEventArgs e)
return;
}
- if (e.Button == MouseButtons.Left && mouseInContentBounds)
+ if (e.Button == MouseButtons.Left && s_mouseInContentBounds)
{
Debug.Assert(DataGridView.CellMouseDownInContentBounds);
UpdateButtonState(ButtonState | ButtonState.Pushed, e.RowIndex);
@@ -563,9 +550,9 @@ protected override void OnMouseLeave(int rowIndex)
return;
}
- if (mouseInContentBounds)
+ if (s_mouseInContentBounds)
{
- mouseInContentBounds = false;
+ s_mouseInContentBounds = false;
if (ColumnIndex >= 0 &&
rowIndex >= 0 &&
(DataGridView.ApplyVisualStylesToInnerCells || FlatStyle == FlatStyle.Flat || FlatStyle == FlatStyle.Popup))
@@ -589,9 +576,9 @@ protected override void OnMouseMove(DataGridViewCellMouseEventArgs e)
return;
}
- bool oldMouseInContentBounds = mouseInContentBounds;
- mouseInContentBounds = GetContentBounds(e.RowIndex).Contains(e.X, e.Y);
- if (oldMouseInContentBounds != mouseInContentBounds)
+ bool oldMouseInContentBounds = s_mouseInContentBounds;
+ s_mouseInContentBounds = GetContentBounds(e.RowIndex).Contains(e.X, e.Y);
+ if (oldMouseInContentBounds != s_mouseInContentBounds)
{
if (DataGridView.ApplyVisualStylesToInnerCells || FlatStyle == FlatStyle.Flat || FlatStyle == FlatStyle.Popup)
{
@@ -603,12 +590,12 @@ protected override void OnMouseMove(DataGridViewCellMouseEventArgs e)
Control.MouseButtons == MouseButtons.Left)
{
if ((ButtonState & ButtonState.Pushed) == 0 &&
- mouseInContentBounds &&
+ s_mouseInContentBounds &&
DataGridView.CellMouseDownInContentBounds)
{
UpdateButtonState(ButtonState | ButtonState.Pushed, e.RowIndex);
}
- else if ((ButtonState & ButtonState.Pushed) != 0 && !mouseInContentBounds)
+ else if ((ButtonState & ButtonState.Pushed) != 0 && !s_mouseInContentBounds)
{
UpdateButtonState(ButtonState & ~ButtonState.Pushed, e.RowIndex);
}
@@ -631,21 +618,23 @@ protected override void OnMouseUp(DataGridViewCellMouseEventArgs e)
}
}
- protected override void Paint(Graphics graphics,
+ protected override void Paint(
+ Graphics graphics,
Rectangle clipBounds,
Rectangle cellBounds,
int rowIndex,
DataGridViewElementStates elementState,
- object value,
- object formattedValue,
- string errorText,
+ object? value,
+ object? formattedValue,
+ string? errorText,
DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts)
{
ArgumentNullException.ThrowIfNull(cellStyle);
- PaintPrivate(graphics,
+ PaintPrivate(
+ graphics,
clipBounds,
cellBounds,
rowIndex,
@@ -655,9 +644,9 @@ protected override void Paint(Graphics graphics,
cellStyle,
advancedBorderStyle,
paintParts,
- false /*computeContentBounds*/,
- false /*computeErrorIconBounds*/,
- true /*paint*/);
+ computeContentBounds: false,
+ computeErrorIconBounds: false,
+ paint: true);
}
// PaintPrivate is used in three places that need to duplicate the paint code:
@@ -668,13 +657,14 @@ protected override void Paint(Graphics graphics,
// if computeContentBounds is true then PaintPrivate returns the contentBounds
// else if computeErrorIconBounds is true then PaintPrivate returns the errorIconBounds
// else it returns Rectangle.Empty;
- private Rectangle PaintPrivate(Graphics g,
+ private Rectangle PaintPrivate(
+ Graphics g,
Rectangle clipBounds,
Rectangle cellBounds,
int rowIndex,
DataGridViewElementStates elementState,
- object formattedValue,
- string errorText,
+ object? formattedValue,
+ string? errorText,
DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts,
@@ -690,12 +680,12 @@ private Rectangle PaintPrivate(Graphics g,
Debug.Assert(!computeErrorIconBounds || !paint || !computeContentBounds);
Debug.Assert(cellStyle is not null);
- Point ptCurrentCell = DataGridView.CurrentCellAddress;
+ Point ptCurrentCell = DataGridView!.CurrentCellAddress;
bool cellSelected = (elementState & DataGridViewElementStates.Selected) != 0;
bool cellCurrent = (ptCurrentCell.X == ColumnIndex && ptCurrentCell.Y == rowIndex);
Rectangle resultBounds;
- string formattedString = formattedValue as string;
+ string? formattedString = formattedValue as string;
Color backBrushColor = PaintSelectionBackground(paintParts) && cellSelected
? cellStyle.SelectionBackColor
@@ -758,7 +748,7 @@ private Rectangle PaintPrivate(Graphics g,
pbState = PushButtonState.Pressed;
}
else if (DataGridView.MouseEnteredCellAddress.Y == rowIndex &&
- DataGridView.MouseEnteredCellAddress.X == ColumnIndex && mouseInContentBounds)
+ DataGridView.MouseEnteredCellAddress.X == ColumnIndex && s_mouseInContentBounds)
{
pbState = PushButtonState.Hot;
}
@@ -814,7 +804,7 @@ private Rectangle PaintPrivate(Graphics g,
hdc.FillRectangle(valBounds, hbrush);
}
else if (DataGridView.MouseEnteredCellAddress.Y == rowIndex &&
- DataGridView.MouseEnteredCellAddress.X == ColumnIndex && mouseInContentBounds)
+ DataGridView.MouseEnteredCellAddress.X == ColumnIndex && s_mouseInContentBounds)
{
using DeviceContextHdcScope hdc = new(g);
using PInvoke.CreateBrushScope hbrush = new(SystemColors.ControlDark);
@@ -852,7 +842,7 @@ private Rectangle PaintPrivate(Graphics g,
}
else if (DataGridView.MouseEnteredCellAddress.Y == rowIndex &&
DataGridView.MouseEnteredCellAddress.X == ColumnIndex &&
- mouseInContentBounds)
+ s_mouseInContentBounds)
{
// paint over
ButtonBaseAdapter.ColorData colors = ButtonBaseAdapter.PaintPopupRender(
@@ -1039,17 +1029,15 @@ private Rectangle PaintPrivate(Graphics g,
return resultBounds;
}
- public override string ToString()
- {
- return $"DataGridViewButtonCell {{ ColumnIndex={ColumnIndex}, RowIndex={RowIndex} }}";
- }
+ public override string ToString() =>
+ $"DataGridViewButtonCell {{ ColumnIndex={ColumnIndex}, RowIndex={RowIndex} }}";
private void UpdateButtonState(ButtonState newButtonState, int rowIndex)
{
if (ButtonState != newButtonState)
{
ButtonState = newButtonState;
- DataGridView.InvalidateCell(ColumnIndex, rowIndex);
+ DataGridView!.InvalidateCell(ColumnIndex, rowIndex);
}
}
}
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewButtonColumn.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewButtonColumn.cs
index bc05c54b44e..187eac98251 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewButtonColumn.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewButtonColumn.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
#nullable disable
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCell.DataGridViewCellAccessibleObject.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCell.DataGridViewCellAccessibleObject.cs
index 9d578c515b0..10977b3de4d 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCell.DataGridViewCellAccessibleObject.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCell.DataGridViewCellAccessibleObject.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.ComponentModel;
using System.Drawing;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCell.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCell.cs
index 8231653f71e..15c0ad2fca7 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCell.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCell.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
#nullable disable
@@ -697,7 +696,7 @@ private protected Rectangle StdBorderWidths
{
if (DataGridView is not null)
{
- DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceholder = new DataGridViewAdvancedBorderStyle(), dgvabsEffective;
+ DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceholder = new(), dgvabsEffective;
dgvabsEffective = AdjustCellBorderStyle(
DataGridView.AdvancedCellBorderStyle,
dataGridViewAdvancedBorderStylePlaceholder,
@@ -1472,10 +1471,8 @@ protected virtual object GetClipboardContent(int rowIndex,
}
// Header Cell classes override this implementation - this implementation is only for inner cells
- if (rowIndex < 0 || rowIndex >= DataGridView.Rows.Count)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfNegative(rowIndex);
+ ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(rowIndex, DataGridView.Rows.Count);
// Assuming (like in other places in this class) that the formatted value is independent of the style colors.
DataGridViewCellStyle dataGridViewCellStyle = GetInheritedStyle(null, rowIndex, false);
@@ -1502,7 +1499,7 @@ protected virtual object GetClipboardContent(int rowIndex,
sb.Append("| ");
if (formattedValue is not null)
{
- using var sw = new StringWriter(sb, CultureInfo.CurrentCulture);
+ using StringWriter sw = new(sb, CultureInfo.CurrentCulture);
FormatPlainTextAsHtml(formattedValue.ToString(), sw);
}
else
@@ -1539,7 +1536,7 @@ protected virtual object GetClipboardContent(int rowIndex,
{
bool escapeApplied = false;
int insertionPoint = sb.Length;
- using var sw = new StringWriter(sb, CultureInfo.CurrentCulture);
+ using StringWriter sw = new(sb, CultureInfo.CurrentCulture);
FormatPlainText(formattedValue.ToString(), csv, sw, ref escapeApplied);
if (escapeApplied)
{
@@ -1571,12 +1568,13 @@ protected virtual object GetClipboardContent(int rowIndex,
}
}
- internal object GetClipboardContentInternal(int rowIndex,
- bool firstCell,
- bool lastCell,
- bool inFirstRow,
- bool inLastRow,
- string format)
+ internal object GetClipboardContentInternal(
+ int rowIndex,
+ bool firstCell,
+ bool lastCell,
+ bool inFirstRow,
+ bool inLastRow,
+ string format)
{
return GetClipboardContent(rowIndex, firstCell, lastCell, inFirstRow, inLastRow, format);
}
@@ -1870,10 +1868,8 @@ public virtual ContextMenuStrip GetInheritedContextMenuStrip(int rowIndex)
{
if (DataGridView is not null)
{
- if (rowIndex < 0 || rowIndex >= DataGridView.Rows.Count)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfNegative(rowIndex);
+ ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(rowIndex, DataGridView.Rows.Count);
if (ColumnIndex < 0)
{
@@ -1942,10 +1938,8 @@ public virtual DataGridViewElementStates GetInheritedState(int rowIndex)
}
// Header Cell classes override this implementation - this implementation is only for inner cells
- if (rowIndex < 0 || rowIndex >= DataGridView.Rows.Count)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfNegative(rowIndex);
+ ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(rowIndex, DataGridView.Rows.Count);
Debug.Assert(OwningColumn is not null);
Debug.Assert(OwningRow is not null);
@@ -2024,10 +2018,8 @@ public virtual DataGridViewCellStyle GetInheritedStyle(DataGridViewCellStyle inh
throw new InvalidOperationException(SR.DataGridView_CellNeedsDataGridViewForInheritedStyle);
}
- if (rowIndex < 0 || rowIndex >= DataGridView.Rows.Count)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfNegative(rowIndex);
+ ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(rowIndex, DataGridView.Rows.Count);
if (ColumnIndex < 0)
{
@@ -2564,10 +2556,8 @@ protected virtual object GetValue(int rowIndex)
DataGridView dataGridView = DataGridView;
if (dataGridView is not null)
{
- if (rowIndex < 0 || rowIndex >= dataGridView.Rows.Count)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfNegative(rowIndex);
+ ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(rowIndex, DataGridView.Rows.Count);
if (ColumnIndex < 0)
{
@@ -3966,7 +3956,7 @@ public virtual Rectangle PositionEditingPanel(Rectangle cellBounds,
throw new InvalidOperationException();
}
- DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceholder = new DataGridViewAdvancedBorderStyle(), dgvabsEffective;
+ DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceholder = new(), dgvabsEffective;
dgvabsEffective = AdjustCellBorderStyle(DataGridView.AdvancedCellBorderStyle,
dataGridViewAdvancedBorderStylePlaceholder,
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellBorderStyle.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellBorderStyle.cs
index 6b502bab1d0..b84f9b6ee54 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellBorderStyle.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellBorderStyle.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellCancelEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellCancelEventArgs.cs
index 033d94166be..38daec46814 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellCancelEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellCancelEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.ComponentModel;
@@ -15,15 +14,8 @@ internal DataGridViewCellCancelEventArgs(DataGridViewCell dataGridViewCell)
public DataGridViewCellCancelEventArgs(int columnIndex, int rowIndex)
{
- if (columnIndex < -1)
- {
- throw new ArgumentOutOfRangeException(nameof(columnIndex));
- }
-
- if (rowIndex < -1)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfLessThan(columnIndex, -1);
+ ArgumentOutOfRangeException.ThrowIfLessThan(rowIndex, -1);
ColumnIndex = columnIndex;
RowIndex = rowIndex;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellCollection.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellCollection.cs
index 39b72192cdc..b143bd9fc2a 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellCollection.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellCollection.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
#nullable disable
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellContextMenuStripNeededEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellContextMenuStripNeededEventArgs.cs
index 91c0b8e26a6..3eaea645a12 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellContextMenuStripNeededEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellContextMenuStripNeededEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellConverter.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellConverter.cs
index 6fb8fdd3150..4a95d794266 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellConverter.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellConverter.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellErrorTextNeededEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellErrorTextNeededEventArgs.cs
index 7b3842e03ad..4f9d342fb5f 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellErrorTextNeededEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellErrorTextNeededEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellEventArgs.cs
index 08af1dbad3e..7d073b3c862 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
@@ -13,15 +12,8 @@ internal DataGridViewCellEventArgs(DataGridViewCell dataGridViewCell)
public DataGridViewCellEventArgs(int columnIndex, int rowIndex)
{
- if (columnIndex < -1)
- {
- throw new ArgumentOutOfRangeException(nameof(columnIndex));
- }
-
- if (rowIndex < -1)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfLessThan(columnIndex, -1);
+ ArgumentOutOfRangeException.ThrowIfLessThan(rowIndex, -1);
ColumnIndex = columnIndex;
RowIndex = rowIndex;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellFormattingEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellFormattingEventArgs.cs
index 38197bf5da5..80072f363cb 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellFormattingEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellFormattingEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
@@ -14,15 +13,8 @@ public DataGridViewCellFormattingEventArgs(
DataGridViewCellStyle? cellStyle)
: base(value, desiredType)
{
- if (columnIndex < -1)
- {
- throw new ArgumentOutOfRangeException(nameof(columnIndex));
- }
-
- if (rowIndex < -1)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfLessThan(columnIndex, -1);
+ ArgumentOutOfRangeException.ThrowIfLessThan(rowIndex, -1);
ColumnIndex = columnIndex;
RowIndex = rowIndex;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellLinkedList.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellLinkedList.cs
index e04d3d6a39c..034f740fca7 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellLinkedList.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellLinkedList.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.Collections;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellLinkedListElement.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellLinkedListElement.cs
index 48c79dd6e5e..5db6e8a3ebd 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellLinkedListElement.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellLinkedListElement.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellLinkedListEnumerator.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellLinkedListEnumerator.cs
index ba70c69d9ea..bc12862ff49 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellLinkedListEnumerator.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellLinkedListEnumerator.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.Collections;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellMouseEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellMouseEventArgs.cs
index 9d4a5f0e583..707ec46c275 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellMouseEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellMouseEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
@@ -14,16 +13,8 @@ public DataGridViewCellMouseEventArgs(
MouseEventArgs? e)
: base(e?.Button ?? MouseButtons.None, e?.Clicks ?? 0, localX, localY, e?.Delta ?? 0)
{
- if (columnIndex < -1)
- {
- throw new ArgumentOutOfRangeException(nameof(columnIndex));
- }
-
- if (rowIndex < -1)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
-
+ ArgumentOutOfRangeException.ThrowIfLessThan(columnIndex, -1);
+ ArgumentOutOfRangeException.ThrowIfLessThan(rowIndex, -1);
ArgumentNullException.ThrowIfNull(e);
ColumnIndex = columnIndex;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellPaintingEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellPaintingEventArgs.cs
index c5556001cde..8f5c8fbc61e 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellPaintingEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellPaintingEventArgs.cs
@@ -1,8 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-#nullable disable
using System.ComponentModel;
using System.Drawing;
@@ -13,19 +10,20 @@ public class DataGridViewCellPaintingEventArgs : HandledEventArgs
{
private readonly DataGridView _dataGridView;
- public DataGridViewCellPaintingEventArgs(DataGridView dataGridView,
- Graphics graphics,
- Rectangle clipBounds,
- Rectangle cellBounds,
- int rowIndex,
- int columnIndex,
- DataGridViewElementStates cellState,
- object value,
- object formattedValue,
- string errorText,
- DataGridViewCellStyle cellStyle,
- DataGridViewAdvancedBorderStyle advancedBorderStyle,
- DataGridViewPaintParts paintParts)
+ public DataGridViewCellPaintingEventArgs(
+ DataGridView dataGridView,
+ Graphics graphics,
+ Rectangle clipBounds,
+ Rectangle cellBounds,
+ int rowIndex,
+ int columnIndex,
+ DataGridViewElementStates cellState,
+ object? value,
+ object? formattedValue,
+ string? errorText,
+ DataGridViewCellStyle cellStyle,
+ DataGridViewAdvancedBorderStyle? advancedBorderStyle,
+ DataGridViewPaintParts paintParts)
{
if ((paintParts & ~DataGridViewPaintParts.All) != 0)
{
@@ -53,9 +51,9 @@ internal DataGridViewCellPaintingEventArgs(DataGridView dataGridView)
_dataGridView = dataGridView;
}
- public Graphics Graphics { get; private set; }
+ public Graphics? Graphics { get; private set; }
- public DataGridViewAdvancedBorderStyle AdvancedBorderStyle { get; private set; }
+ public DataGridViewAdvancedBorderStyle? AdvancedBorderStyle { get; private set; }
public Rectangle CellBounds { get; private set; }
@@ -67,13 +65,13 @@ internal DataGridViewCellPaintingEventArgs(DataGridView dataGridView)
public DataGridViewElementStates State { get; private set; }
- public object Value { get; private set; }
+ public object? Value { get; private set; }
- public object FormattedValue { get; private set; }
+ public object? FormattedValue { get; private set; }
- public string ErrorText { get; private set; }
+ public string? ErrorText { get; private set; }
- public DataGridViewCellStyle CellStyle { get; private set; }
+ public DataGridViewCellStyle? CellStyle { get; private set; }
public DataGridViewPaintParts PaintParts { get; private set; }
@@ -89,17 +87,20 @@ public void Paint(Rectangle clipBounds, DataGridViewPaintParts paintParts)
throw new InvalidOperationException(SR.DataGridViewElementPaintingEventArgs_ColumnIndexOutOfRange);
}
- _dataGridView.GetCellInternal(ColumnIndex, RowIndex).PaintInternal(Graphics,
- clipBounds,
- CellBounds,
- RowIndex,
- State,
- Value,
- FormattedValue,
- ErrorText,
- CellStyle,
- AdvancedBorderStyle,
- paintParts);
+ _dataGridView
+ .GetCellInternal(ColumnIndex, RowIndex)
+ .PaintInternal(
+ Graphics,
+ clipBounds,
+ CellBounds,
+ RowIndex,
+ State,
+ Value,
+ FormattedValue,
+ ErrorText,
+ CellStyle,
+ AdvancedBorderStyle,
+ paintParts);
}
public void PaintBackground(Rectangle clipBounds, bool cellsPaintSelectionBackground)
@@ -120,17 +121,20 @@ public void PaintBackground(Rectangle clipBounds, bool cellsPaintSelectionBackgr
paintParts |= DataGridViewPaintParts.SelectionBackground;
}
- _dataGridView.GetCellInternal(ColumnIndex, RowIndex).PaintInternal(Graphics,
- clipBounds,
- CellBounds,
- RowIndex,
- State,
- Value,
- FormattedValue,
- ErrorText,
- CellStyle,
- AdvancedBorderStyle,
- paintParts);
+ _dataGridView
+ .GetCellInternal(ColumnIndex, RowIndex)
+ .PaintInternal(
+ Graphics,
+ clipBounds,
+ CellBounds,
+ RowIndex,
+ State,
+ Value,
+ FormattedValue,
+ ErrorText,
+ CellStyle,
+ AdvancedBorderStyle,
+ paintParts);
}
public void PaintContent(Rectangle clipBounds)
@@ -145,31 +149,35 @@ public void PaintContent(Rectangle clipBounds)
throw new InvalidOperationException(SR.DataGridViewElementPaintingEventArgs_ColumnIndexOutOfRange);
}
- _dataGridView.GetCellInternal(ColumnIndex, RowIndex).PaintInternal(Graphics,
- clipBounds,
- CellBounds,
- RowIndex,
- State,
- Value,
- FormattedValue,
- ErrorText,
- CellStyle,
- AdvancedBorderStyle,
- DataGridViewPaintParts.ContentBackground | DataGridViewPaintParts.ContentForeground | DataGridViewPaintParts.ErrorIcon);
+ _dataGridView
+ .GetCellInternal(ColumnIndex, RowIndex)
+ .PaintInternal(
+ Graphics,
+ clipBounds,
+ CellBounds,
+ RowIndex,
+ State,
+ Value,
+ FormattedValue,
+ ErrorText,
+ CellStyle,
+ AdvancedBorderStyle,
+ DataGridViewPaintParts.ContentBackground | DataGridViewPaintParts.ContentForeground | DataGridViewPaintParts.ErrorIcon);
}
- internal void SetProperties(Graphics graphics,
- Rectangle clipBounds,
- Rectangle cellBounds,
- int rowIndex,
- int columnIndex,
- DataGridViewElementStates cellState,
- object value,
- object formattedValue,
- string errorText,
- DataGridViewCellStyle cellStyle,
- DataGridViewAdvancedBorderStyle advancedBorderStyle,
- DataGridViewPaintParts paintParts)
+ internal void SetProperties(
+ Graphics graphics,
+ Rectangle clipBounds,
+ Rectangle cellBounds,
+ int rowIndex,
+ int columnIndex,
+ DataGridViewElementStates cellState,
+ object? value,
+ object? formattedValue,
+ string? errorText,
+ DataGridViewCellStyle cellStyle,
+ DataGridViewAdvancedBorderStyle advancedBorderStyle,
+ DataGridViewPaintParts paintParts)
{
Debug.Assert(graphics is not null);
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellParsingEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellParsingEventArgs.cs
index affbf5da7e9..dfbd4be09b8 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellParsingEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellParsingEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStateChangedEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStateChangedEventArgs.cs
index c25094a9969..d526b77ca89 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStateChangedEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStateChangedEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStyle.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStyle.cs
index 8b3af67a577..9c6424b8af9 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStyle.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStyle.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
#nullable disable
@@ -642,7 +641,7 @@ internal DataGridViewCellStyleDifferences GetDifferencesFrom(DataGridViewCellSty
public override int GetHashCode()
{
- var hash = default(HashCode);
+ HashCode hash = default;
hash.Add(Alignment);
hash.Add(WrapMode);
hash.Add(Padding);
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStyleChangedEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStyleChangedEventArgs.cs
index 6b873028107..a9f22d40597 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStyleChangedEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStyleChangedEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStyleContentChangedEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStyleContentChangedEventArgs.cs
index 6f43e560a29..aa554c59f07 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStyleContentChangedEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStyleContentChangedEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStyleConverter.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStyleConverter.cs
index ae76f3dd264..3009d5e4d9e 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStyleConverter.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStyleConverter.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStyleDifferences.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStyleDifferences.cs
index a6da2cdb9fe..526730f4965 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStyleDifferences.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStyleDifferences.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStyleScopes.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStyleScopes.cs
index 1ab001619eb..44110262eed 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStyleScopes.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellStyleScopes.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellToolTipTextNeededEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellToolTipTextNeededEventArgs.cs
index 4a21c9d392b..ec46381e667 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellToolTipTextNeededEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellToolTipTextNeededEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellValidatingEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellValidatingEventArgs.cs
index 3b893005c24..86e0ca0940d 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellValidatingEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellValidatingEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.ComponentModel;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellValueEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellValueEventArgs.cs
index d66d850f13a..7f99ef25bb8 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellValueEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCellValueEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
@@ -14,15 +13,8 @@ internal DataGridViewCellValueEventArgs()
public DataGridViewCellValueEventArgs(int columnIndex, int rowIndex)
{
- if (columnIndex < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(columnIndex));
- }
-
- if (rowIndex < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfNegative(columnIndex);
+ ArgumentOutOfRangeException.ThrowIfNegative(rowIndex);
ColumnIndex = columnIndex;
RowIndex = rowIndex;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCheckBoxCell.DataGridViewCheckBoxCellAccessibleObject.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCheckBoxCell.DataGridViewCheckBoxCellAccessibleObject.cs
index 0d7ecf5741a..c4430e786d4 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCheckBoxCell.DataGridViewCheckBoxCellAccessibleObject.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCheckBoxCell.DataGridViewCheckBoxCellAccessibleObject.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using static Interop;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCheckBoxCell.DataGridViewCheckBoxCellRenderer.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCheckBoxCell.DataGridViewCheckBoxCellRenderer.cs
index 2b67f4c4762..4d1f3075b71 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCheckBoxCell.DataGridViewCheckBoxCellRenderer.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCheckBoxCell.DataGridViewCheckBoxCellRenderer.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.Drawing;
using System.Windows.Forms.VisualStyles;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCheckBoxCell.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCheckBoxCell.cs
index 7bf243b9430..40959ac1036 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCheckBoxCell.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCheckBoxCell.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
#nullable disable
@@ -1443,7 +1442,7 @@ private Rectangle PaintPrivate(Graphics g,
using (Graphics offscreen = Graphics.FromImage(bitmap))
{
offscreen.Clear(Color.Transparent);
- using var hdc = new DeviceContextHdcScope(offscreen);
+ using DeviceContextHdcScope hdc = new(offscreen);
PInvoke.DrawFrameControl(
hdc,
ref rcCheck,
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCheckBoxColumn.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCheckBoxColumn.cs
index 85b048afa54..06c0dd46b80 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCheckBoxColumn.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCheckBoxColumn.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
#nullable disable
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewClipboardCopyMode.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewClipboardCopyMode.cs
index b49fb9d9930..a7b29e570b8 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewClipboardCopyMode.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewClipboardCopyMode.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumn.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumn.cs
index 0274fb68af0..6dbaaa532d8 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumn.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumn.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
#nullable disable
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnCollection.ColumnOrderComparer.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnCollection.ColumnOrderComparer.cs
index c17836e8b3d..791acfb89c0 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnCollection.ColumnOrderComparer.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnCollection.ColumnOrderComparer.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnCollection.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnCollection.cs
index 2be2f5bae0a..f66936ad4db 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnCollection.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnCollection.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
#nullable disable
@@ -24,7 +23,7 @@ public partial class DataGridViewColumnCollection : BaseCollection, IList
private int _lastAccessedSortedIndex = -1;
private int _columnCountsVisible, _columnCountsVisibleSelected;
private int _columnsWidthVisible, _columnsWidthVisibleFrozen;
- private static readonly ColumnOrderComparer s_columnOrderComparer = new ColumnOrderComparer();
+ private static readonly ColumnOrderComparer s_columnOrderComparer = new();
/* IList interface implementation */
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnConverter.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnConverter.cs
index c55fac3ac2d..45bf538f25d 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnConverter.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnConverter.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnDesignTimeVisibleAttribute.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnDesignTimeVisibleAttribute.cs
index 66a130787f0..5039ce95730 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnDesignTimeVisibleAttribute.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnDesignTimeVisibleAttribute.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnDividerDoubleClickEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnDividerDoubleClickEventArgs.cs
index 6a7bbd243bf..2aef74b90de 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnDividerDoubleClickEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnDividerDoubleClickEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
@@ -9,11 +8,7 @@ public class DataGridViewColumnDividerDoubleClickEventArgs : HandledMouseEventAr
public DataGridViewColumnDividerDoubleClickEventArgs(int columnIndex, HandledMouseEventArgs? e)
: base(e?.Button ?? MouseButtons.None, e?.Clicks ?? 0, e?.X ?? 0, e?.Y ?? 0, e?.Delta ?? 0, e?.Handled ?? false)
{
- if (columnIndex < -1)
- {
- throw new ArgumentOutOfRangeException(nameof(columnIndex));
- }
-
+ ArgumentOutOfRangeException.ThrowIfLessThan(columnIndex, -1);
ArgumentNullException.ThrowIfNull(e);
ColumnIndex = columnIndex;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnEventArgs.cs
index da79aa65c2b..66a34a7d688 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnHeaderCell.DataGridViewColumnHeaderCellAccessibleObject.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnHeaderCell.DataGridViewColumnHeaderCellAccessibleObject.cs
index 7bc761e887d..96cfc729f6a 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnHeaderCell.DataGridViewColumnHeaderCellAccessibleObject.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnHeaderCell.DataGridViewColumnHeaderCellAccessibleObject.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.ComponentModel;
using System.Drawing;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnHeaderCell.DataGridViewColumnHeaderCellRenderer.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnHeaderCell.DataGridViewColumnHeaderCellRenderer.cs
index 01de55f3272..4522ce3abf6 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnHeaderCell.DataGridViewColumnHeaderCellRenderer.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnHeaderCell.DataGridViewColumnHeaderCellRenderer.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.Drawing;
using System.Windows.Forms.VisualStyles;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnHeaderCell.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnHeaderCell.cs
index 7e652fde363..48c5bd80176 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnHeaderCell.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnHeaderCell.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
#nullable disable
@@ -137,10 +136,7 @@ protected override object GetClipboardContent(int rowIndex,
bool inLastRow,
string format)
{
- if (rowIndex != -1)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfNotEqual(rowIndex, -1);
if (DataGridView is null)
{
@@ -164,7 +160,7 @@ protected override object GetClipboardContent(int rowIndex,
sb.Append(" | ");
if (val is not null)
{
- using var sw = new StringWriter(sb, CultureInfo.CurrentCulture);
+ using StringWriter sw = new(sb, CultureInfo.CurrentCulture);
FormatPlainTextAsHtml(val.ToString(), sw);
}
else
@@ -195,7 +191,7 @@ protected override object GetClipboardContent(int rowIndex,
{
bool escapeApplied = false;
int insertionPoint = sb.Length;
- using var sw = new StringWriter(sb, CultureInfo.CurrentCulture);
+ using StringWriter sw = new(sb, CultureInfo.CurrentCulture);
FormatPlainText(val.ToString(), csv, sw, ref escapeApplied);
if (escapeApplied)
{
@@ -230,10 +226,7 @@ protected override Rectangle GetContentBounds(Graphics graphics, DataGridViewCel
{
ArgumentNullException.ThrowIfNull(cellStyle);
- if (rowIndex != -1)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfNotEqual(rowIndex, -1);
if (DataGridView is null || OwningColumn is null)
{
@@ -280,10 +273,7 @@ protected override Rectangle GetContentBounds(Graphics graphics, DataGridViewCel
public override ContextMenuStrip GetInheritedContextMenuStrip(int rowIndex)
{
- if (rowIndex != -1)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfNotEqual(rowIndex, -1);
ContextMenuStrip contextMenuStrip = GetContextMenuStrip(-1);
if (contextMenuStrip is not null)
@@ -308,10 +298,7 @@ public override DataGridViewCellStyle GetInheritedStyle(DataGridViewCellStyle in
throw new InvalidOperationException(SR.DataGridView_CellNeedsDataGridViewForInheritedStyle);
}
- if (rowIndex != -1)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfNotEqual(rowIndex, -1);
DataGridViewCellStyle inheritedCellStyleTmp = inheritedCellStyle ?? new DataGridViewCellStyle();
@@ -507,10 +494,7 @@ public override DataGridViewCellStyle GetInheritedStyle(DataGridViewCellStyle in
protected override Size GetPreferredSize(Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize)
{
- if (rowIndex != -1)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfNotEqual(rowIndex, -1);
if (DataGridView is null)
{
@@ -520,7 +504,7 @@ protected override Size GetPreferredSize(Graphics graphics, DataGridViewCellStyl
ArgumentNullException.ThrowIfNull(cellStyle);
DataGridViewFreeDimension freeDimension = DataGridViewCell.GetFreeDimensionFromConstraint(constraintSize);
- DataGridViewAdvancedBorderStyle dgvabsPlaceholder = new DataGridViewAdvancedBorderStyle(), dgvabsEffective;
+ DataGridViewAdvancedBorderStyle dgvabsPlaceholder = new(), dgvabsEffective;
dgvabsEffective = DataGridView.AdjustColumnHeaderBorderStyle(DataGridView.AdvancedColumnHeadersBorderStyle,
dgvabsPlaceholder,
false /*isFirstDisplayedColumn*/,
@@ -716,10 +700,7 @@ OwningColumn is not null &&
protected override object GetValue(int rowIndex)
{
- if (rowIndex != -1)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfNotEqual(rowIndex, -1);
if (ContainsLocalValue)
{
@@ -1206,10 +1187,7 @@ DataGridView.CurrentCell is not null && DataGridView.CurrentCell.Selected &&
protected override bool SetValue(int rowIndex, object value)
{
- if (rowIndex != -1)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfNotEqual(rowIndex, -1);
object originalValue = GetValue(rowIndex);
Properties.SetObject(s_propCellValue, value);
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnHeadersHeightSizeMode.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnHeadersHeightSizeMode.cs
index 66c86f91db7..7c9fcc8234c 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnHeadersHeightSizeMode.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnHeadersHeightSizeMode.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnSortMode.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnSortMode.cs
index 24e75e88d94..98c88fb159e 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnSortMode.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnSortMode.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnStateChangedEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnStateChangedEventArgs.cs
index 463c5e92e99..0dcac19ba04 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnStateChangedEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewColumnStateChangedEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxCell.DataGridViewComboBoxCellAccessibleObject.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxCell.DataGridViewComboBoxCellAccessibleObject.cs
index 4b6af182460..13b9ac4b88c 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxCell.DataGridViewComboBoxCellAccessibleObject.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxCell.DataGridViewComboBoxCellAccessibleObject.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using static Interop;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxCell.DataGridViewComboBoxCellRenderer.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxCell.DataGridViewComboBoxCellRenderer.cs
index 174380605a5..7c5cf83af53 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxCell.DataGridViewComboBoxCellRenderer.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxCell.DataGridViewComboBoxCellRenderer.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.Drawing;
using System.Windows.Forms.VisualStyles;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxCell.ItemComparer.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxCell.ItemComparer.cs
index c879baf9a2b..e0b14ed7322 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxCell.ItemComparer.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxCell.ItemComparer.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.Globalization;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxCell.ObjectCollection.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxCell.ObjectCollection.cs
index 20d769a8509..1cad44a7016 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxCell.ObjectCollection.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxCell.ObjectCollection.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
#nullable disable
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxCell.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxCell.cs
index 9c2665814a1..95fad6f67b9 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxCell.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxCell.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
#nullable disable
@@ -488,13 +487,7 @@ internal FlatStyle FlatStyleInternal
}
}
- public override Type FormattedValueType
- {
- get
- {
- return s_defaultFormattedValueType;
- }
- }
+ public override Type FormattedValueType => s_defaultFormattedValueType;
internal bool HasItems => Properties.ContainsObjectThatIsNotNull(s_propComboBoxCellItems);
@@ -695,7 +688,7 @@ internal override void CacheEditingControl()
private void CheckDropDownList(int x, int y, int rowIndex)
{
Debug.Assert(EditingComboBox is not null);
- DataGridViewAdvancedBorderStyle dgvabsPlaceholder = new DataGridViewAdvancedBorderStyle(), dgvabsEffective;
+ DataGridViewAdvancedBorderStyle dgvabsPlaceholder = new(), dgvabsEffective;
dgvabsEffective = AdjustCellBorderStyle(DataGridView.AdvancedCellBorderStyle,
dgvabsPlaceholder,
false /*singleVerticalBorderAdded*/,
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxColumn.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxColumn.cs
index 63fbf071a9f..dd41dbc129d 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxColumn.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxColumn.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
#nullable disable
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxDisplayStyle.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxDisplayStyle.cs
index dbc5fe2e6b7..d520aec4434 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxDisplayStyle.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxDisplayStyle.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxEditingControl.DataGridViewComboBoxEditingControlAccessibleObject.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxEditingControl.DataGridViewComboBoxEditingControlAccessibleObject.cs
index b9beaade196..d32010121c4 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxEditingControl.DataGridViewComboBoxEditingControlAccessibleObject.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxEditingControl.DataGridViewComboBoxEditingControlAccessibleObject.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using static Interop;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxEditingControl.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxEditingControl.cs
index 7612fe4ee40..24d409661d5 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxEditingControl.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewComboBoxEditingControl.cs
@@ -1,8 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-#nullable disable
using System.Drawing;
using System.Globalization;
@@ -11,7 +8,7 @@ namespace System.Windows.Forms;
public partial class DataGridViewComboBoxEditingControl : ComboBox, IDataGridViewEditingControl
{
- private DataGridView _dataGridView;
+ private DataGridView? _dataGridView;
private bool _valueChanged;
private int _rowIndex;
@@ -20,14 +17,12 @@ public DataGridViewComboBoxEditingControl() : base()
TabStop = false;
}
- protected override AccessibleObject CreateAccessibilityInstance()
- {
- return new DataGridViewComboBoxEditingControlAccessibleObject(this);
- }
+ protected override AccessibleObject CreateAccessibilityInstance() =>
+ new DataGridViewComboBoxEditingControlAccessibleObject(this);
// IDataGridViewEditingControl interface implementation
- public virtual DataGridView EditingControlDataGridView
+ public virtual DataGridView? EditingControlDataGridView
{
get
{
@@ -41,10 +36,7 @@ public virtual DataGridView EditingControlDataGridView
public virtual object EditingControlFormattedValue
{
- get
- {
- return GetEditingControlFormattedValue(DataGridViewDataErrorContexts.Formatting);
- }
+ get => GetEditingControlFormattedValue(DataGridViewDataErrorContexts.Formatting);
set
{
if (value is string valueStr)
@@ -60,43 +52,19 @@ public virtual object EditingControlFormattedValue
public virtual int EditingControlRowIndex
{
- get
- {
- return _rowIndex;
- }
- set
- {
- _rowIndex = value;
- }
+ get => _rowIndex;
+ set => _rowIndex = value;
}
public virtual bool EditingControlValueChanged
{
- get
- {
- return _valueChanged;
- }
- set
- {
- _valueChanged = value;
- }
+ get => _valueChanged;
+ set => _valueChanged = value;
}
- public virtual Cursor EditingPanelCursor
- {
- get
- {
- return Cursors.Default;
- }
- }
+ public virtual Cursor EditingPanelCursor => Cursors.Default;
- public virtual bool RepositionEditingControlOnValueChange
- {
- get
- {
- return false;
- }
- }
+ public virtual bool RepositionEditingControlOnValueChange => false;
public virtual void ApplyCellStyleToEditingControl(DataGridViewCellStyle dataGridViewCellStyle)
{
@@ -106,7 +74,7 @@ public virtual void ApplyCellStyleToEditingControl(DataGridViewCellStyle dataGri
// Our ComboBox does not support transparent back colors
Color opaqueBackColor = Color.FromArgb(255, dataGridViewCellStyle.BackColor);
BackColor = opaqueBackColor;
- _dataGridView.EditingPanel.BackColor = opaqueBackColor;
+ _dataGridView!.EditingPanel.BackColor = opaqueBackColor;
}
else
{
@@ -130,10 +98,7 @@ public virtual bool EditingControlWantsInputKey(Keys keyData, bool dataGridViewW
return !dataGridViewWantsInputKey;
}
- public virtual object GetEditingControlFormattedValue(DataGridViewDataErrorContexts context)
- {
- return Text;
- }
+ public virtual object GetEditingControlFormattedValue(DataGridViewDataErrorContexts context) => Text;
public virtual void PrepareEditingControlForEdit(bool selectAll)
{
@@ -146,7 +111,7 @@ public virtual void PrepareEditingControlForEdit(bool selectAll)
private void NotifyDataGridViewOfValueChange()
{
_valueChanged = true;
- _dataGridView.NotifyCurrentCellDirty(true);
+ _dataGridView!.NotifyCurrentCellDirty(true);
}
protected override void OnSelectedIndexChanged(EventArgs e)
@@ -171,7 +136,7 @@ protected override void OnHandleCreated(EventArgs e)
internal override void ReleaseUiaProvider(HWND handle)
{
- if (TryGetAccessibilityObject(out AccessibleObject accessibleObject))
+ if (TryGetAccessibilityObject(out AccessibleObject? accessibleObject))
{
((DataGridViewComboBoxEditingControlAccessibleObject)accessibleObject).ClearParent();
}
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewContentAlignment.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewContentAlignment.cs
index c1594b3f24d..6094440cc07 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewContentAlignment.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewContentAlignment.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewDataErrorContexts.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewDataErrorContexts.cs
index bf7215d8a8b..a6f726cb70b 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewDataErrorContexts.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewDataErrorContexts.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewDataErrorEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewDataErrorEventArgs.cs
index 51041500e01..7b7c01c02da 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewDataErrorEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewDataErrorEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewEditMode.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewEditMode.cs
index a68a762d934..e7c035c86d0 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewEditMode.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewEditMode.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewEditingCell.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewEditingCell.cs
index 7399aff026d..c263eee4f41 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewEditingCell.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewEditingCell.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewEditingControl.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewEditingControl.cs
index ff419df1459..5d2e1d74054 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewEditingControl.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewEditingControl.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewEditingControlShowingEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewEditingControlShowingEventArgs.cs
index 1003198de2f..01bb3dabef1 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewEditingControlShowingEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewEditingControlShowingEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewElement.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewElement.cs
index 2bba3c435ae..c861f7ebfb7 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewElement.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewElement.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.ComponentModel;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewElementStates.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewElementStates.cs
index 22f6887c87e..3d7962d602c 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewElementStates.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewElementStates.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewEventHandlers.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewEventHandlers.cs
index 60beceb01d7..b15a0fd0373 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewEventHandlers.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewEventHandlers.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewFreeDimension.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewFreeDimension.cs
index 3b779eccd41..1331cd4c326 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewFreeDimension.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewFreeDimension.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewHeaderBorderStyle.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewHeaderBorderStyle.cs
index fe15818d62e..3406a58bc1d 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewHeaderBorderStyle.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewHeaderBorderStyle.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewHeaderCell.DataGridViewHeaderCellRenderer.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewHeaderCell.DataGridViewHeaderCellRenderer.cs
index fa9342871a9..10f0b837aca 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewHeaderCell.DataGridViewHeaderCellRenderer.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewHeaderCell.DataGridViewHeaderCellRenderer.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.Windows.Forms.VisualStyles;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewHeaderCell.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewHeaderCell.cs
index 34dc253041d..cd179cc290d 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewHeaderCell.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewHeaderCell.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
#nullable disable
@@ -19,7 +18,7 @@ public partial class DataGridViewHeaderCell : DataGridViewCell
private static readonly Type s_defaultFormattedValueType = typeof(string);
private static readonly Type s_defaultValueType = typeof(object);
private static readonly Type s_cellType = typeof(DataGridViewHeaderCell);
- private static Rectangle s_rectThemeMargins = new Rectangle(-1, -1, 0, 0);
+ private static Rectangle s_rectThemeMargins = new(-1, -1, 0, 0);
private static readonly int s_propValueType = PropertyStore.CreateKey();
private static readonly int s_propButtonState = PropertyStore.CreateKey();
private static readonly int s_propFlipXPThemesBitmap = PropertyStore.CreateKey();
@@ -112,13 +111,7 @@ internal Bitmap FlipXPThemesBitmap
}
}
- public override Type FormattedValueType
- {
- get
- {
- return s_defaultFormattedValueType;
- }
- }
+ public override Type FormattedValueType => s_defaultFormattedValueType;
[Browsable(false)]
public override bool Frozen
@@ -328,10 +321,7 @@ public override DataGridViewElementStates GetInheritedState(int rowIndex)
else if (OwningColumn is not null)
{
// column header cell
- if (rowIndex != -1)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfNotEqual(rowIndex, -1);
state |= (OwningColumn.State & DataGridViewElementStates.Frozen);
if (OwningColumn.Resizable == DataGridViewTriState.True ||
@@ -352,10 +342,7 @@ public override DataGridViewElementStates GetInheritedState(int rowIndex)
else if (DataGridView is not null)
{
// top left header cell
- if (rowIndex != -1)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfNotEqual(rowIndex, -1);
state |= DataGridViewElementStates.Frozen;
if (DataGridView.RowHeadersWidthSizeMode == DataGridViewRowHeadersWidthSizeMode.EnableResizing || DataGridView.ColumnHeadersHeightSizeMode == DataGridViewColumnHeadersHeightSizeMode.EnableResizing)
@@ -419,10 +406,7 @@ protected override Size GetSize(int rowIndex)
if (DataGridView is null)
{
// detached cell
- if (rowIndex != -1)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfNotEqual(rowIndex, -1);
return new Size(-1, -1);
}
@@ -430,20 +414,15 @@ protected override Size GetSize(int rowIndex)
if (OwningColumn is not null)
{
// must be a column header cell
- if (rowIndex != -1)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfNotEqual(rowIndex, -1);
return new Size(OwningColumn.Thickness, DataGridView.ColumnHeadersHeight);
}
else if (OwningRow is not null)
{
// must be a row header cell
- if (rowIndex < 0 || rowIndex >= DataGridView.Rows.Count)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfNegative(rowIndex);
+ ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(rowIndex, DataGridView.Rows.Count);
if (DataGridView.Rows.SharedRow(rowIndex) != OwningRow)
{
@@ -455,10 +434,7 @@ protected override Size GetSize(int rowIndex)
else
{
// must be the top left header cell
- if (rowIndex != -1)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfNotEqual(rowIndex, -1);
return new Size(DataGridView.RowHeadersWidth, DataGridView.ColumnHeadersHeight);
}
@@ -504,10 +480,7 @@ internal static Rectangle GetThemeMargins(Graphics g)
protected override object GetValue(int rowIndex)
{
- if (rowIndex != -1)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfNotEqual(rowIndex, -1);
return Properties.GetObject(s_propCellValue);
}
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewHitTestCloseEdge.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewHitTestCloseEdge.cs
index 55dbf755e7f..65dcd17c61e 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewHitTestCloseEdge.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewHitTestCloseEdge.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewHitTestType.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewHitTestType.cs
index 41583645889..2e486ba8a4a 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewHitTestType.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewHitTestType.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewImageCell.DataGridViewImageCellAccessibleObject.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewImageCell.DataGridViewImageCellAccessibleObject.cs
index 01e39c4ffd3..3ebd79bb7a3 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewImageCell.DataGridViewImageCellAccessibleObject.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewImageCell.DataGridViewImageCellAccessibleObject.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using static Interop;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewImageCell.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewImageCell.cs
index cfd3f9c8228..b7090f0036c 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewImageCell.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewImageCell.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
#nullable disable
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewImageCellLayout.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewImageCellLayout.cs
index c80abc06799..e0eac7d6333 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewImageCellLayout.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewImageCellLayout.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewImageColumn.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewImageColumn.cs
index dbe083c8600..e1860c4fe85 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewImageColumn.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewImageColumn.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
#nullable disable
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewIntLinkedList.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewIntLinkedList.cs
index 6760bab297a..033ae5a5f11 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewIntLinkedList.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewIntLinkedList.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
#nullable disable
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewIntLinkedListElement.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewIntLinkedListElement.cs
index 07d23d5eff2..fc7c6b5634b 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewIntLinkedListElement.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewIntLinkedListElement.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewIntLinkedListEnumerator.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewIntLinkedListEnumerator.cs
index 52ddf9495b5..ba3ca7f4fce 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewIntLinkedListEnumerator.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewIntLinkedListEnumerator.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.Collections;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewLinkCell.DataGridViewLinkCellAccessibleObject.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewLinkCell.DataGridViewLinkCellAccessibleObject.cs
index 9c4220b7fc9..abe13d76c47 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewLinkCell.DataGridViewLinkCellAccessibleObject.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewLinkCell.DataGridViewLinkCellAccessibleObject.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using static Interop;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewLinkCell.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewLinkCell.cs
index 18ebcc3fb95..da2f26c5ad2 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewLinkCell.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewLinkCell.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
#nullable disable
@@ -112,13 +111,7 @@ public override Type EditType
}
}
- public override Type FormattedValueType
- {
- get
- {
- return s_defaultFormattedValueType;
- }
- }
+ public override Type FormattedValueType => s_defaultFormattedValueType;
[DefaultValue(LinkBehavior.SystemDefault)]
public LinkBehavior LinkBehavior
@@ -733,10 +726,9 @@ protected override object GetValue(int rowIndex)
if (UseColumnTextForLinkValue &&
DataGridView is not null &&
DataGridView.NewRowIndex != rowIndex &&
- OwningColumn is not null &&
- OwningColumn is DataGridViewLinkColumn)
+ OwningColumn is DataGridViewLinkColumn dataGridViewLinkColumn)
{
- return ((DataGridViewLinkColumn)OwningColumn).Text;
+ return dataGridViewLinkColumn.Text;
}
return base.GetValue(rowIndex);
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewLinkColumn.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewLinkColumn.cs
index a275fff95bd..c28c40391e8 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewLinkColumn.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewLinkColumn.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
#nullable disable
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewPaintParts.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewPaintParts.cs
index 5013c608173..c84f3437fd2 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewPaintParts.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewPaintParts.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRow.DataGridViewRowAccessibleObject.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRow.DataGridViewRowAccessibleObject.cs
index 65684ef8181..e99742fb6a5 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRow.DataGridViewRowAccessibleObject.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRow.DataGridViewRowAccessibleObject.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.Drawing;
using System.Globalization;
@@ -243,10 +242,7 @@ public override string Value
public override AccessibleObject? GetChild(int index)
{
- if (index < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
+ ArgumentOutOfRangeException.ThrowIfNegative(index);
if (_owningDataGridViewRow is null)
{
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRow.DataGridViewSelectedRowCellsAccessibleObject.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRow.DataGridViewSelectedRowCellsAccessibleObject.cs
index d9f61e46ebb..0106b2fa314 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRow.DataGridViewSelectedRowCellsAccessibleObject.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRow.DataGridViewSelectedRowCellsAccessibleObject.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRow.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRow.cs
index a5657bbe117..3fc7a175de6 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRow.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRow.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
#nullable disable
@@ -246,7 +245,7 @@ public override DataGridViewCellStyle InheritedStyle
throw new InvalidOperationException(string.Format(SR.DataGridView_InvalidPropertyGetOnSharedRow, nameof(InheritedStyle)));
}
- var inheritedRowStyle = new DataGridViewCellStyle();
+ DataGridViewCellStyle inheritedRowStyle = new();
BuildInheritedRowStyle(Index, inheritedRowStyle);
return inheritedRowStyle;
}
@@ -1218,10 +1217,8 @@ public ContextMenuStrip GetContextMenuStrip(int rowIndex)
throw new InvalidOperationException(SR.DataGridView_InvalidOperationOnSharedRow);
}
- if (rowIndex < 0 || rowIndex >= DataGridView.Rows.Count)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfNegative(rowIndex);
+ ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(rowIndex, DataGridView.Rows.Count);
if (DataGridView.VirtualMode || DataGridView.DataSource is not null)
{
@@ -1247,10 +1244,8 @@ public string GetErrorText(int rowIndex)
throw new InvalidOperationException(SR.DataGridView_InvalidOperationOnSharedRow);
}
- if (rowIndex < 0 || rowIndex >= DataGridView.Rows.Count)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfNegative(rowIndex);
+ ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(rowIndex, DataGridView.Rows.Count);
if (string.IsNullOrEmpty(errorText) &&
DataGridView.DataSource is not null &&
@@ -1293,16 +1288,14 @@ public virtual int GetPreferredHeight(int rowIndex, DataGridViewAutoSizeRowMode
throw new InvalidEnumArgumentException(nameof(autoSizeRowMode), (int)autoSizeRowMode, typeof(DataGridViewAutoSizeRowMode));
}
- if (!(DataGridView is null || (rowIndex >= 0 && rowIndex < DataGridView.Rows.Count)))
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
-
if (DataGridView is null)
{
return -1;
}
+ ArgumentOutOfRangeException.ThrowIfNegative(rowIndex);
+ ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(rowIndex, DataGridView.Rows.Count);
+
int preferredRowThickness = 0, preferredCellThickness;
// take into account the preferred height of the header cell if displayed and cared about
if (DataGridView.RowHeadersVisible &&
@@ -1379,9 +1372,10 @@ internal bool GetSelected(int rowIndex)
[EditorBrowsable(EditorBrowsableState.Advanced)]
public virtual DataGridViewElementStates GetState(int rowIndex)
{
- if (!(DataGridView is null || (rowIndex >= 0 && rowIndex < DataGridView.Rows.Count)))
+ if (DataGridView is not null)
{
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
+ ArgumentOutOfRangeException.ThrowIfNegative(rowIndex);
+ ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(rowIndex, DataGridView.Rows.Count);
}
if (DataGridView is null || DataGridView.Rows.SharedRow(rowIndex).Index != -1)
@@ -1522,7 +1516,7 @@ protected internal virtual void PaintCells(Graphics graphics,
DataGridViewCell cell;
DataGridViewCellStyle inheritedCellStyle = new DataGridViewCellStyle();
DataGridViewColumn dataGridViewColumnNext = null;
- DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceholder = new DataGridViewAdvancedBorderStyle(), dgvabsEffective;
+ DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceholder = new(), dgvabsEffective;
// first paint the potential visible frozen cells
DataGridViewColumn dataGridViewColumn = dataGridView.Columns.GetFirstColumn(DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen);
@@ -1720,7 +1714,7 @@ protected internal virtual void PaintHeader(Graphics graphics,
if (clipBounds.IntersectsWith(cellBounds))
{
DataGridViewCellStyle inheritedCellStyle = new DataGridViewCellStyle();
- DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceholder = new DataGridViewAdvancedBorderStyle(), dgvabsEffective;
+ DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceholder = new(), dgvabsEffective;
BuildInheritedRowHeaderCellStyle(inheritedCellStyle);
dgvabsEffective = AdjustRowHeaderBorderStyle(dataGridView.AdvancedRowHeadersBorderStyle,
dataGridViewAdvancedBorderStylePlaceholder,
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCancelEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCancelEventArgs.cs
index 1115c355ae9..0f3f704fb87 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCancelEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCancelEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.ComponentModel;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCollection.RowArrayList.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCollection.RowArrayList.cs
index 31d91715185..ae0db46a2d5 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCollection.RowArrayList.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCollection.RowArrayList.cs
@@ -1,8 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-#nullable disable
using System.Collections;
@@ -12,12 +9,12 @@ public partial class DataGridViewRowCollection
{
private class RowArrayList : ArrayList
{
- private readonly DataGridViewRowCollection owner;
- private RowComparer rowComparer;
+ private readonly DataGridViewRowCollection _owner;
+ private RowComparer? _rowComparer;
public RowArrayList(DataGridViewRowCollection owner)
{
- this.owner = owner;
+ _owner = owner;
}
public void CustomSort(RowComparer rowComparer)
@@ -25,7 +22,7 @@ public void CustomSort(RowComparer rowComparer)
Debug.Assert(rowComparer is not null);
Debug.Assert(Count > 0);
- this.rowComparer = rowComparer;
+ _rowComparer = rowComparer;
CustomQuickSort(0, Count - 1);
}
@@ -40,9 +37,9 @@ private void CustomQuickSort(int left, int right)
{
if (right - left < 2) // sort subarray of two elements
{
- if (right - left > 0 && rowComparer.CompareObjects(rowComparer.GetComparedObject(left), rowComparer.GetComparedObject(right), left, right) > 0)
+ if (right - left > 0 && _rowComparer!.CompareObjects(_rowComparer.GetComparedObject(left), _rowComparer.GetComparedObject(right), left, right) > 0)
{
- owner.SwapSortedRows(left, right);
+ _owner.SwapSortedRows(left, right);
}
return;
@@ -54,12 +51,12 @@ private void CustomQuickSort(int left, int right)
int j = right - 1;
do
{
- while (k != i && rowComparer.CompareObjects(rowComparer.GetComparedObject(i), x, i, k) < 0)
+ while (k != i && _rowComparer!.CompareObjects(_rowComparer.GetComparedObject(i), x, i, k) < 0)
{
i++;
}
- while (k != j && rowComparer.CompareObjects(x, rowComparer.GetComparedObject(j), k, j) < 0)
+ while (k != j && _rowComparer!.CompareObjects(x, _rowComparer.GetComparedObject(j), k, j) < 0)
{
j--;
}
@@ -72,7 +69,7 @@ private void CustomQuickSort(int left, int right)
if (i < j)
{
- owner.SwapSortedRows(i, j);
+ _owner.SwapSortedRows(i, j);
if (i == k)
{
k = j;
@@ -113,22 +110,22 @@ private void CustomQuickSort(int left, int right)
private object Pivot(int left, int center, int right)
{
// find median-of-3 (left, center and right) and sort these 3 elements
- if (rowComparer.CompareObjects(rowComparer.GetComparedObject(left), rowComparer.GetComparedObject(center), left, center) > 0)
+ if (_rowComparer!.CompareObjects(_rowComparer.GetComparedObject(left), _rowComparer.GetComparedObject(center), left, center) > 0)
{
- owner.SwapSortedRows(left, center);
+ _owner.SwapSortedRows(left, center);
}
- if (rowComparer.CompareObjects(rowComparer.GetComparedObject(left), rowComparer.GetComparedObject(right), left, right) > 0)
+ if (_rowComparer.CompareObjects(_rowComparer.GetComparedObject(left), _rowComparer.GetComparedObject(right), left, right) > 0)
{
- owner.SwapSortedRows(left, right);
+ _owner.SwapSortedRows(left, right);
}
- if (rowComparer.CompareObjects(rowComparer.GetComparedObject(center), rowComparer.GetComparedObject(right), center, right) > 0)
+ if (_rowComparer.CompareObjects(_rowComparer.GetComparedObject(center), _rowComparer.GetComparedObject(right), center, right) > 0)
{
- owner.SwapSortedRows(center, right);
+ _owner.SwapSortedRows(center, right);
}
- return rowComparer.GetComparedObject(center);
+ return _rowComparer.GetComparedObject(center);
}
}
}
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCollection.RowComparer.ComparedObjectMax.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCollection.RowComparer.ComparedObjectMax.cs
index 36afbbbfbdd..2daafbe9cf5 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCollection.RowComparer.ComparedObjectMax.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCollection.RowComparer.ComparedObjectMax.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCollection.RowComparer.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCollection.RowComparer.cs
index 02a808a9162..60e3890e9e6 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCollection.RowComparer.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCollection.RowComparer.cs
@@ -1,8 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-#nullable disable
using System.Collections;
@@ -12,54 +9,54 @@ public partial class DataGridViewRowCollection
{
private partial class RowComparer
{
- private readonly DataGridView dataGridView;
- private readonly DataGridViewRowCollection dataGridViewRows;
- private readonly DataGridViewColumn dataGridViewSortedColumn;
- private readonly int sortedColumnIndex;
- private readonly IComparer customComparer;
- private readonly bool ascending;
- private static readonly ComparedObjectMax max = new ComparedObjectMax();
+ private readonly DataGridView _dataGridView;
+ private readonly DataGridViewRowCollection _dataGridViewRows;
+ private readonly DataGridViewColumn? _dataGridViewSortedColumn;
+ private readonly int _sortedColumnIndex;
+ private readonly IComparer _customComparer;
+ private readonly bool _ascending;
+ private static readonly ComparedObjectMax s_max = new();
public RowComparer(DataGridViewRowCollection dataGridViewRows, IComparer customComparer, bool ascending)
{
- dataGridView = dataGridViewRows.DataGridView;
- this.dataGridViewRows = dataGridViewRows;
- dataGridViewSortedColumn = dataGridView.SortedColumn;
- if (dataGridViewSortedColumn is null)
+ _dataGridView = dataGridViewRows.DataGridView;
+ _dataGridViewRows = dataGridViewRows;
+ _dataGridViewSortedColumn = _dataGridView.SortedColumn;
+ if (_dataGridViewSortedColumn is null)
{
Debug.Assert(customComparer is not null);
- sortedColumnIndex = -1;
+ _sortedColumnIndex = -1;
}
else
{
- sortedColumnIndex = dataGridViewSortedColumn.Index;
+ _sortedColumnIndex = _dataGridViewSortedColumn.Index;
}
- this.customComparer = customComparer;
- this.ascending = ascending;
+ _customComparer = customComparer;
+ _ascending = ascending;
}
internal object GetComparedObject(int rowIndex)
{
- if (dataGridView.NewRowIndex != -1)
+ if (_dataGridView.NewRowIndex != -1)
{
- Debug.Assert(dataGridView.AllowUserToAddRowsInternal);
- if (rowIndex == dataGridView.NewRowIndex)
+ Debug.Assert(_dataGridView.AllowUserToAddRowsInternal);
+ if (rowIndex == _dataGridView.NewRowIndex)
{
- return max;
+ return s_max;
}
}
- if (customComparer is null)
+ if (_customComparer is null)
{
- DataGridViewRow dataGridViewRow = dataGridViewRows.SharedRow(rowIndex);
+ DataGridViewRow dataGridViewRow = _dataGridViewRows.SharedRow(rowIndex);
Debug.Assert(dataGridViewRow is not null);
- Debug.Assert(sortedColumnIndex >= 0);
- return dataGridViewRow.Cells[sortedColumnIndex].GetValueInternal(rowIndex);
+ Debug.Assert(_sortedColumnIndex >= 0);
+ return dataGridViewRow.Cells[_sortedColumnIndex].GetValueInternal(rowIndex);
}
else
{
- return dataGridViewRows[rowIndex]; // Unsharing compared rows!
+ return _dataGridViewRows[rowIndex]; // Unsharing compared rows!
}
}
@@ -75,9 +72,9 @@ internal int CompareObjects(object value1, object value2, int rowIndex1, int row
}
int result = 0;
- if (customComparer is null)
+ if (_customComparer is null)
{
- if (!dataGridView.OnSortCompare(dataGridViewSortedColumn, value1, value2, rowIndex1, rowIndex2, out result))
+ if (!_dataGridView.OnSortCompare(_dataGridViewSortedColumn, value1, value2, rowIndex1, rowIndex2, out result))
{
if (!(value1 is IComparable) && !(value2 is IComparable))
{
@@ -108,7 +105,7 @@ internal int CompareObjects(object value1, object value2, int rowIndex1, int row
if (result == 0)
{
- if (ascending)
+ if (_ascending)
{
result = rowIndex1 - rowIndex2;
}
@@ -125,12 +122,11 @@ internal int CompareObjects(object value1, object value2, int rowIndex1, int row
Debug.Assert(value2 is DataGridViewRow);
Debug.Assert(value1 is not null);
Debug.Assert(value2 is not null);
- //
- result = customComparer.Compare(value1, value2);
+ result = _customComparer.Compare(value1, value2);
}
- if (ascending)
+ if (_ascending)
{
return result;
}
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCollection.UnsharingRowEnumerator.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCollection.UnsharingRowEnumerator.cs
index 78eafaf01ae..d2bc39cbddd 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCollection.UnsharingRowEnumerator.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCollection.UnsharingRowEnumerator.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.Collections;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCollection.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCollection.cs
index 34b82209ecc..f4a9a8afd37 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCollection.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowCollection.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
#nullable disable
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowContextMenuStripNeededEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowContextMenuStripNeededEventArgs.cs
index abad0d7b8b9..acd47c18e65 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowContextMenuStripNeededEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowContextMenuStripNeededEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
@@ -8,10 +7,7 @@ public class DataGridViewRowContextMenuStripNeededEventArgs : EventArgs
{
public DataGridViewRowContextMenuStripNeededEventArgs(int rowIndex)
{
- if (rowIndex < -1)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfLessThan(rowIndex, -1);
RowIndex = rowIndex;
}
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowConverter.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowConverter.cs
index 8afcea4c655..af860d4c3b9 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowConverter.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowConverter.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowDividerDoubleClickEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowDividerDoubleClickEventArgs.cs
index 1a274576169..42776905256 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowDividerDoubleClickEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowDividerDoubleClickEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
@@ -9,10 +8,7 @@ public class DataGridViewRowDividerDoubleClickEventArgs : HandledMouseEventArgs
public DataGridViewRowDividerDoubleClickEventArgs(int rowIndex, HandledMouseEventArgs e)
: base((e.OrThrowIfNull()).Button, e.Clicks, e.X, e.Y, e.Delta, e.Handled)
{
- if (rowIndex < -1)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfLessThan(rowIndex, -1);
RowIndex = rowIndex;
}
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowErrorTextNeededEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowErrorTextNeededEventArgs.cs
index 7b78502fd49..76fd05d8503 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowErrorTextNeededEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowErrorTextNeededEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowEventArgs.cs
index 3f2ced6ab0b..59bd6618912 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeaderCell.DataGridViewRowHeaderCellAccessibleObject.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeaderCell.DataGridViewRowHeaderCellAccessibleObject.cs
index e56cb616983..446afd5378e 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeaderCell.DataGridViewRowHeaderCellAccessibleObject.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeaderCell.DataGridViewRowHeaderCellAccessibleObject.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.Drawing;
using static Interop;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeaderCell.DataGridViewRowHeaderCellRenderer.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeaderCell.DataGridViewRowHeaderCellRenderer.cs
index e0a80424c81..d193ca1de4f 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeaderCell.DataGridViewRowHeaderCellRenderer.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeaderCell.DataGridViewRowHeaderCellRenderer.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.Drawing;
using System.Windows.Forms.VisualStyles;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeaderCell.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeaderCell.cs
index 30b1e7d5bfa..11865e2fce4 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeaderCell.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeaderCell.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
#nullable disable
@@ -179,10 +178,8 @@ protected override object GetClipboardContent(int rowIndex,
return null;
}
- if (rowIndex < 0 || rowIndex >= DataGridView.Rows.Count)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfNegative(rowIndex);
+ ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(rowIndex, DataGridView.Rows.Count);
// Not using formatted values for header cells.
object val = GetValue(rowIndex);
@@ -202,7 +199,7 @@ protected override object GetClipboardContent(int rowIndex,
if (val is not null)
{
sb.Append("");
- using var sw = new StringWriter(sb, CultureInfo.CurrentCulture);
+ using StringWriter sw = new(sb, CultureInfo.CurrentCulture);
FormatPlainTextAsHtml(val.ToString(), sw);
sb.Append("");
}
@@ -234,7 +231,7 @@ protected override object GetClipboardContent(int rowIndex,
{
bool escapeApplied = false;
int insertionPoint = sb.Length;
- using var sw = new StringWriter(sb, CultureInfo.CurrentCulture);
+ using StringWriter sw = new(sb, CultureInfo.CurrentCulture);
FormatPlainText(val.ToString(), csv, sw, ref escapeApplied);
if (escapeApplied)
{
@@ -366,9 +363,10 @@ protected internal override string GetErrorText(int rowIndex)
public override ContextMenuStrip GetInheritedContextMenuStrip(int rowIndex)
{
- if (DataGridView is not null && (rowIndex < 0 || rowIndex >= DataGridView.Rows.Count))
+ if (DataGridView is not null)
{
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
+ ArgumentOutOfRangeException.ThrowIfNegative(rowIndex);
+ ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(rowIndex, DataGridView.Rows.Count);
}
ContextMenuStrip contextMenuStrip = GetContextMenuStrip(rowIndex);
@@ -597,7 +595,7 @@ protected override Size GetPreferredSize(Graphics graphics, DataGridViewCellStyl
ArgumentNullException.ThrowIfNull(cellStyle);
- DataGridViewAdvancedBorderStyle dgvabsPlaceholder = new DataGridViewAdvancedBorderStyle(), dgvabsEffective;
+ DataGridViewAdvancedBorderStyle dgvabsPlaceholder = new(), dgvabsEffective;
dgvabsEffective = OwningRow.AdjustRowHeaderBorderStyle(DataGridView.AdvancedRowHeadersBorderStyle,
dgvabsPlaceholder,
false /*singleVerticalBorderAdded*/,
@@ -642,9 +640,10 @@ protected override object GetValue(int rowIndex)
{
// We allow multiple rows to share the same row header value. The row header cell's cloning does this.
// So here we need to allow rowIndex == -1.
- if (DataGridView is not null && (rowIndex < -1 || rowIndex >= DataGridView.Rows.Count))
+ if (DataGridView is not null)
{
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
+ ArgumentOutOfRangeException.ThrowIfLessThan(rowIndex, -1);
+ ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(rowIndex, DataGridView.Rows.Count);
}
return Properties.GetObject(s_propCellValue);
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeadersWidthSizeMode.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeadersWidthSizeMode.cs
index 4d38a9c647e..6781a03e854 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeadersWidthSizeMode.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeadersWidthSizeMode.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeightInfoNeededEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeightInfoNeededEventArgs.cs
index df270525fc9..2df2e849e31 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeightInfoNeededEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeightInfoNeededEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeightInfoPushedEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeightInfoPushedEventArgs.cs
index 14d4402e609..5a45ccc42e9 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeightInfoPushedEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowHeightInfoPushedEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.ComponentModel;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowPostPaintEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowPostPaintEventArgs.cs
index e7aaa6668c6..9c341bde27f 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowPostPaintEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowPostPaintEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.Drawing;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowPrePaintEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowPrePaintEventArgs.cs
index 3d9732a6c33..8178fb2cc05 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowPrePaintEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowPrePaintEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.ComponentModel;
using System.Drawing;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowStateChangedEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowStateChangedEventArgs.cs
index 0096a222f88..1a1971fb501 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowStateChangedEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowStateChangedEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowsAddedEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowsAddedEventArgs.cs
index 107d3a9e6bf..628eb4b0ca5 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowsAddedEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowsAddedEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowsRemovedEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowsRemovedEventArgs.cs
index b34eec87da9..323c61b9db7 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowsRemovedEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRowsRemovedEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.Globalization;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewSelectedCellCollection.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewSelectedCellCollection.cs
index 6cd24bac47a..3c06f0c3dc9 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewSelectedCellCollection.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewSelectedCellCollection.cs
@@ -1,8 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-#nullable disable
using System.Collections;
using System.ComponentModel;
@@ -18,7 +15,7 @@ public class DataGridViewSelectedCellCollection : BaseCollection, IList
{
private readonly List _items = new();
- int IList.Add(object value)
+ int IList.Add(object? value)
{
throw new NotSupportedException(SR.DataGridView_ReadOnlyCollection);
}
@@ -28,16 +25,16 @@ void IList.Clear()
throw new NotSupportedException(SR.DataGridView_ReadOnlyCollection);
}
- bool IList.Contains(object value) => ((IList)_items).Contains(value);
+ bool IList.Contains(object? value) => ((IList)_items).Contains(value);
- int IList.IndexOf(object value) => ((IList)_items).IndexOf(value);
+ int IList.IndexOf(object? value) => ((IList)_items).IndexOf(value);
- void IList.Insert(int index, object value)
+ void IList.Insert(int index, object? value)
{
throw new NotSupportedException(SR.DataGridView_ReadOnlyCollection);
}
- void IList.Remove(object value)
+ void IList.Remove(object? value)
{
throw new NotSupportedException(SR.DataGridView_ReadOnlyCollection);
}
@@ -51,7 +48,7 @@ void IList.RemoveAt(int index)
bool IList.IsReadOnly => true;
- object IList.this[int index]
+ object? IList.this[int index]
{
get { return _items[index]; }
set { throw new NotSupportedException(SR.DataGridView_ReadOnlyCollection); }
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewSelectedColumnCollection.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewSelectedColumnCollection.cs
index eb22fbf323f..b6b1d551d1a 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewSelectedColumnCollection.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewSelectedColumnCollection.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.Collections;
using System.ComponentModel;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewSelectedRowCollection.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewSelectedRowCollection.cs
index f01750bebe5..4d65cf31cf3 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewSelectedRowCollection.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewSelectedRowCollection.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.Collections;
using System.ComponentModel;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewSelectionMode.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewSelectionMode.cs
index 7bd40a7f012..ed69e92ef8b 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewSelectionMode.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewSelectionMode.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewSortCompareEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewSortCompareEventArgs.cs
index a6518f74332..532d0aa9c34 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewSortCompareEventArgs.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewSortCompareEventArgs.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.ComponentModel;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTextBoxCell.DataGridViewTextBoxCellAccessibleObject.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTextBoxCell.DataGridViewTextBoxCellAccessibleObject.cs
index 3e50c163b9b..84d6f5e2a9f 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTextBoxCell.DataGridViewTextBoxCellAccessibleObject.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTextBoxCell.DataGridViewTextBoxCellAccessibleObject.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using static Interop;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTextBoxCell.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTextBoxCell.cs
index 6007aac6b32..e5579ee1ff9 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTextBoxCell.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTextBoxCell.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
#nullable disable
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTextBoxColumn.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTextBoxColumn.cs
index 8ee87ed3d24..b09ec81c2b0 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTextBoxColumn.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTextBoxColumn.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.ComponentModel;
using System.Drawing;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTextBoxEditingControl.DataGridViewTextBoxEditingControlAccessibleObject.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTextBoxEditingControl.DataGridViewTextBoxEditingControlAccessibleObject.cs
index 266a1c4f3fc..a5fe41dcf3c 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTextBoxEditingControl.DataGridViewTextBoxEditingControlAccessibleObject.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTextBoxEditingControl.DataGridViewTextBoxEditingControlAccessibleObject.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using static Interop;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTextBoxEditingControl.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTextBoxEditingControl.cs
index d093b11ec3e..b9e3853f4b9 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTextBoxEditingControl.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTextBoxEditingControl.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.Drawing;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTopLeftHeaderCell.DataGridViewTopLeftHeaderCellAccessibleObject.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTopLeftHeaderCell.DataGridViewTopLeftHeaderCellAccessibleObject.cs
index b42a3d3a14e..86f67a483b3 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTopLeftHeaderCell.DataGridViewTopLeftHeaderCellAccessibleObject.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTopLeftHeaderCell.DataGridViewTopLeftHeaderCellAccessibleObject.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.Drawing;
using static Interop;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTopLeftHeaderCell.DataGridViewTopLeftHeaderCellRenderer.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTopLeftHeaderCell.DataGridViewTopLeftHeaderCellRenderer.cs
index 98d11fd17b1..52c34358eef 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTopLeftHeaderCell.DataGridViewTopLeftHeaderCellRenderer.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTopLeftHeaderCell.DataGridViewTopLeftHeaderCellRenderer.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.Drawing;
using System.Windows.Forms.VisualStyles;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTopLeftHeaderCell.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTopLeftHeaderCell.cs
index 07850fcc8d7..c474b5d80b5 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTopLeftHeaderCell.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTopLeftHeaderCell.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.Drawing;
using System.Windows.Forms.VisualStyles;
@@ -28,10 +27,7 @@ protected override Rectangle GetContentBounds(Graphics graphics, DataGridViewCel
{
ArgumentNullException.ThrowIfNull(cellStyle);
- if (rowIndex != -1)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfNotEqual(rowIndex, -1);
if (DataGridView is null)
{
@@ -86,10 +82,7 @@ protected override Rectangle GetContentBounds(Graphics graphics, DataGridViewCel
protected override Rectangle GetErrorIconBounds(Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex)
{
- if (rowIndex != -1)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfNotEqual(rowIndex, -1);
if (DataGridView is null)
{
@@ -140,10 +133,7 @@ protected override Rectangle GetErrorIconBounds(Graphics graphics, DataGridViewC
protected override Size GetPreferredSize(Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize)
{
- if (rowIndex != -1)
- {
- throw new ArgumentOutOfRangeException(nameof(rowIndex));
- }
+ ArgumentOutOfRangeException.ThrowIfNotEqual(rowIndex, -1);
if (DataGridView is null)
{
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTriState.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTriState.cs
index 2d35198b074..0a59ca69089 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTriState.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewTriState.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
namespace System.Windows.Forms;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewUtilities.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewUtilities.cs
index ad9f27766a9..6c2fe44d542 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewUtilities.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewUtilities.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.Drawing;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataObject.BitmapBinder.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataObject.BitmapBinder.cs
index ad471ebbbc9..23df236d142 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataObject.BitmapBinder.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataObject.BitmapBinder.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.Drawing;
using System.Reflection;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataObject.ComDataObjectAdapter.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataObject.ComDataObjectAdapter.cs
index 98cb8083ecf..4ada977c5c1 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataObject.ComDataObjectAdapter.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataObject.ComDataObjectAdapter.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.Buffers;
using System.ComponentModel;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataObject.DataStore.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataObject.DataStore.cs
index d5162233e32..c48f00b9f33 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataObject.DataStore.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataObject.DataStore.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.Collections.Specialized;
using System.ComponentModel;
@@ -25,7 +24,7 @@ public DataStoreEntry(object? data, bool autoConvert)
}
}
- private readonly Dictionary _data = new Dictionary(BackCompatibleStringComparer.Default);
+ private readonly Dictionary _data = new(BackCompatibleStringComparer.Default);
public DataStore()
{
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/DataObject.FormatEnumerator.cs b/src/System.Windows.Forms/src/System/Windows/Forms/DataObject.FormatEnumerator.cs
index f0ca3565cba..954970fc20d 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/DataObject.FormatEnumerator.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/DataObject.FormatEnumerator.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
using System.ComponentModel;
using Windows.Win32.System.Com;
@@ -16,7 +15,7 @@ public partial class DataObject
private unsafe class FormatEnumerator : ComTypes.IEnumFORMATETC, IEnumFORMATETC.Interface, IManagedWrapper
{
private readonly IDataObject _parent;
- private readonly List _formats = new List();
+ private readonly List |