Skip to content

Commit 3c2e4b3

Browse files
committed
Update switch "DataGridViewUIAStartRowCountAtZero" to "DataGridViewUIAStartRowCountAtOne" and disable it by default
1 parent a935df2 commit 3c2e4b3

File tree

5 files changed

+26
-35
lines changed

5 files changed

+26
-35
lines changed

src/System.Windows.Forms.Primitives/src/System/LocalAppContextSwitches/LocalAppContextSwitches.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ internal static partial class LocalAppContextSwitches
2020
internal const string ServicePointManagerCheckCrlSwitchName = "System.Windows.Forms.ServicePointManagerCheckCrl";
2121
internal const string TrackBarModernRenderingSwitchName = "System.Windows.Forms.TrackBarModernRendering";
2222
private const string DoNotCatchUnhandledExceptionsSwitchName = "System.Windows.Forms.DoNotCatchUnhandledExceptions";
23-
internal const string DataGridViewUIAStartRowCountAtZeroSwitchName = "System.Windows.Forms.DataGridViewUIAStartRowCountAtZero";
23+
internal const string DataGridViewUIAStartRowCountAtOneSwitchName = "System.Windows.Forms.DataGridViewUIAStartRowCountAtOne";
2424

2525
private static int s_scaleTopLevelFormMinMaxSizeForDpi;
2626
private static int s_anchorLayoutV2;
2727
private static int s_servicePointManagerCheckCrl;
2828
private static int s_trackBarModernRendering;
2929
private static int s_doNotCatchUnhandledExceptions;
30-
private static int s_dataGridViewUIAStartRowCountAtZero;
30+
private static int s_dataGridViewUIAStartRowCountAtOne;
3131

3232
private static FrameworkName? s_targetFrameworkName;
3333

@@ -154,11 +154,9 @@ public static bool ServicePointManagerCheckCrl
154154
get => GetCachedSwitchValue(ServicePointManagerCheckCrlSwitchName, ref s_servicePointManagerCheckCrl);
155155
}
156156

157-
public static bool DataGridViewUIAStartRowCountAtZero
157+
public static bool DataGridViewUIAStartRowCountAtOne
158158
{
159159
[MethodImpl(MethodImplOptions.AggressiveInlining)]
160-
get => GetCachedSwitchValue(DataGridViewUIAStartRowCountAtZeroSwitchName, ref s_dataGridViewUIAStartRowCountAtZero);
160+
get => GetCachedSwitchValue(DataGridViewUIAStartRowCountAtOneSwitchName, ref s_dataGridViewUIAStartRowCountAtOne);
161161
}
162-
163-
internal static void SetDataGridViewUIAStartRowCountAtZero(bool value) => s_dataGridViewUIAStartRowCountAtZero = value ? 1 : 0;
164162
}

src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewCell.DataGridViewCellAccessibleObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private AccessibleObject? ParentPrivate
114114

115115
public override AccessibleRole Role => AccessibleRole.Cell;
116116

117-
private static int RowStartIndex => LocalAppContextSwitches.DataGridViewUIAStartRowCountAtZero ? 0 : 1;
117+
private static int RowStartIndex => LocalAppContextSwitches.DataGridViewUIAStartRowCountAtOne ? 1 : 0;
118118

119119
public override AccessibleStates State
120120
{

src/System.Windows.Forms/src/System/Windows/Forms/DataGridViewRow.DataGridViewRowAccessibleObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private AccessibleObject? ParentPrivate
133133

134134
public override AccessibleRole Role => AccessibleRole.Row;
135135

136-
private static int RowStartIndex => LocalAppContextSwitches.DataGridViewUIAStartRowCountAtZero ? 0 : 1;
136+
private static int RowStartIndex => LocalAppContextSwitches.DataGridViewUIAStartRowCountAtOne ? 1 : 0;
137137

138138
internal override int[] RuntimeId
139139
=> _runtimeId ??= new int[]

src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellAccessibleObjectTests.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ public void DataGridViewCellAccessibleObject_Name_ReturnExpected_IfDataGridViewN
208208
Assert.Equal(expected, accessibleObject.Name);
209209
}
210210

211-
// Whether UIA row indexing is 1-based or 0-based, is controlled by the DataGridViewUIAStartRowCountAtZero switch
212211
[WinFormsFact]
213212
public void DataGridViewCellAccessibleObject_Name_ReturnExpected()
214213
{
@@ -220,13 +219,12 @@ public void DataGridViewCellAccessibleObject_Name_ReturnExpected()
220219
dataGridView.Rows.Add("3");
221220

222221
AccessibleObject accessibleObject = dataGridView.Rows[2].Cells[0].AccessibilityObject;
223-
string expected = string.Format(SR.DataGridView_AccDataGridViewCellName, column.HeaderText, 3);
222+
string expected = string.Format(SR.DataGridView_AccDataGridViewCellName, column.HeaderText, 2);
224223

225224
Assert.Equal(expected, accessibleObject.Name);
226225
Assert.False(dataGridView.IsHandleCreated);
227226
}
228227

229-
// Whether UIA row indexing is 1-based or 0-based, is controlled by the DataGridViewUIAStartRowCountAtZero switch
230228
[WinFormsFact]
231229
public void DataGridViewCellAccessibleObject_Name_ReturnExpected_IfOneRowHidden()
232230
{
@@ -239,13 +237,12 @@ public void DataGridViewCellAccessibleObject_Name_ReturnExpected_IfOneRowHidden(
239237
dataGridView.Rows[0].Visible = false;
240238

241239
AccessibleObject accessibleObject = dataGridView.Rows[2].Cells[0].AccessibilityObject;
242-
string expected = string.Format(SR.DataGridView_AccDataGridViewCellName, column.HeaderText, 2);
240+
string expected = string.Format(SR.DataGridView_AccDataGridViewCellName, column.HeaderText, 1);
243241

244242
Assert.Equal(expected, accessibleObject.Name);
245243
Assert.False(dataGridView.IsHandleCreated);
246244
}
247245

248-
// Whether UIA row indexing is 1-based or 0-based, is controlled by the DataGridViewUIAStartRowCountAtZero switch
249246
[WinFormsFact]
250247
public void DataGridViewCellAccessibleObject_Name_ReturnExpected_IfTwoRowsHidden()
251248
{
@@ -259,7 +256,7 @@ public void DataGridViewCellAccessibleObject_Name_ReturnExpected_IfTwoRowsHidden
259256
dataGridView.Rows[1].Visible = false;
260257

261258
AccessibleObject accessibleObject = dataGridView.Rows[2].Cells[0].AccessibilityObject;
262-
string expected = string.Format(SR.DataGridView_AccDataGridViewCellName, column.HeaderText, 1);
259+
string expected = string.Format(SR.DataGridView_AccDataGridViewCellName, column.HeaderText, 0);
263260

264261
Assert.Equal(expected, accessibleObject.Name);
265262
Assert.False(dataGridView.IsHandleCreated);
@@ -1440,17 +1437,17 @@ private DataGridView CreateDataGridView(int columnCount, bool createControl = tr
14401437
[WinFormsFact]
14411438
public void DataGridView_SwitchConfigured_AdjustsCellRowStartIndices()
14421439
{
1443-
LocalAppContextSwitches.SetDataGridViewUIAStartRowCountAtZero(true);
1440+
AppContext.SetSwitch(LocalAppContextSwitches.DataGridViewUIAStartRowCountAtOneSwitchName, true);
14441441

14451442
using DataGridView dataGridView = new();
14461443
dataGridView.Columns.Add(new DataGridViewTextBoxColumn());
14471444
dataGridView.Rows.Add(new DataGridViewRow());
14481445

1449-
Assert.Equal($"{string.Format(SR.DataGridView_AccRowName, 0)}, Not sorted.", dataGridView.Rows[0].Cells[0].AccessibilityObject.Name);
1446+
Assert.Equal($"{string.Format(SR.DataGridView_AccRowName, 1)}, Not sorted.", dataGridView.Rows[0].Cells[0].AccessibilityObject.Name);
14501447

1451-
LocalAppContextSwitches.SetDataGridViewUIAStartRowCountAtZero(false);
1448+
AppContext.SetSwitch(LocalAppContextSwitches.DataGridViewUIAStartRowCountAtOneSwitchName, false);
14521449

1453-
Assert.Equal($"{string.Format(SR.DataGridView_AccRowName, 1)}, Not sorted.", dataGridView.Rows[0].Cells[0].AccessibilityObject.Name);
1450+
Assert.Equal($"{string.Format(SR.DataGridView_AccRowName, 0)}, Not sorted.", dataGridView.Rows[0].Cells[0].AccessibilityObject.Name);
14541451
}
14551452

14561453
private class SubDataGridViewCell : DataGridViewCell

src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewRowAccessibleObjectTests.cs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ public void DataGridViewRowAccessibleObject_Name_Get_ReturnsExpected_IfDataGridV
7272
Assert.Equal(string.Format(SR.DataGridView_AccRowName, -1), accessibilityObject.Name);
7373
}
7474

75-
// Whether UIA row indexing is 1-based or 0-based, is controlled by the DataGridViewUIAStartRowCountAtZero switch
7675
[Fact]
7776
public void DataGridViewRowAccessibleObject_Name_Get_ReturnsExpected()
7877
{
@@ -86,13 +85,12 @@ public void DataGridViewRowAccessibleObject_Name_Get_ReturnsExpected()
8685
AccessibleObject accessibleObject2 = dataGridView.Rows[1].AccessibilityObject;
8786
AccessibleObject accessibleObject3 = dataGridView.Rows[2].AccessibilityObject;
8887

89-
Assert.Equal(string.Format(SR.DataGridView_AccRowName, 1), accessibleObject1.Name);
90-
Assert.Equal(string.Format(SR.DataGridView_AccRowName, 2), accessibleObject2.Name);
91-
Assert.Equal(string.Format(SR.DataGridView_AccRowName, 3), accessibleObject3.Name);
88+
Assert.Equal(string.Format(SR.DataGridView_AccRowName, 0), accessibleObject1.Name);
89+
Assert.Equal(string.Format(SR.DataGridView_AccRowName, 1), accessibleObject2.Name);
90+
Assert.Equal(string.Format(SR.DataGridView_AccRowName, 2), accessibleObject3.Name);
9291
Assert.False(dataGridView.IsHandleCreated);
9392
}
9493

95-
// Whether UIA row indexing is 1-based or 0-based, is controlled by the DataGridViewUIAStartRowCountAtZero switch
9694
[Fact]
9795
public void DataGridViewRowAccessibleObject_Name_Get_ReturnsExpected_IfFirstRowHidden()
9896
{
@@ -108,12 +106,11 @@ public void DataGridViewRowAccessibleObject_Name_Get_ReturnsExpected_IfFirstRowH
108106
AccessibleObject accessibleObject3 = dataGridView.Rows[2].AccessibilityObject;
109107

110108
Assert.Equal(string.Format(SR.DataGridView_AccRowName, -1), accessibleObject1.Name);
111-
Assert.Equal(string.Format(SR.DataGridView_AccRowName, 1), accessibleObject2.Name);
112-
Assert.Equal(string.Format(SR.DataGridView_AccRowName, 2), accessibleObject3.Name);
109+
Assert.Equal(string.Format(SR.DataGridView_AccRowName, 0), accessibleObject2.Name);
110+
Assert.Equal(string.Format(SR.DataGridView_AccRowName, 1), accessibleObject3.Name);
113111
Assert.False(dataGridView.IsHandleCreated);
114112
}
115113

116-
// Whether UIA row indexing is 1-based or 0-based, is controlled by the DataGridViewUIAStartRowCountAtZero switch
117114
[Fact]
118115
public void DataGridViewRowAccessibleObject_Name_Get_ReturnsExpected_IfSecondRowHidden()
119116
{
@@ -128,13 +125,12 @@ public void DataGridViewRowAccessibleObject_Name_Get_ReturnsExpected_IfSecondRow
128125
AccessibleObject accessibleObject2 = dataGridView.Rows[1].AccessibilityObject;
129126
AccessibleObject accessibleObject3 = dataGridView.Rows[2].AccessibilityObject;
130127

131-
Assert.Equal(string.Format(SR.DataGridView_AccRowName, 1), accessibleObject1.Name);
128+
Assert.Equal(string.Format(SR.DataGridView_AccRowName, 0), accessibleObject1.Name);
132129
Assert.Equal(string.Format(SR.DataGridView_AccRowName, -1), accessibleObject2.Name);
133-
Assert.Equal(string.Format(SR.DataGridView_AccRowName, 2), accessibleObject3.Name);
130+
Assert.Equal(string.Format(SR.DataGridView_AccRowName, 1), accessibleObject3.Name);
134131
Assert.False(dataGridView.IsHandleCreated);
135132
}
136133

137-
// Whether UIA row indexing is 1-based or 0-based, is controlled by the DataGridViewUIAStartRowCountAtZero switch
138134
[Fact]
139135
public void DataGridViewRowAccessibleObject_Name_Get_ReturnsExpected_IfLastRowHidden()
140136
{
@@ -149,8 +145,8 @@ public void DataGridViewRowAccessibleObject_Name_Get_ReturnsExpected_IfLastRowHi
149145
AccessibleObject accessibleObject2 = dataGridView.Rows[1].AccessibilityObject;
150146
AccessibleObject accessibleObject3 = dataGridView.Rows[2].AccessibilityObject;
151147

152-
Assert.Equal(string.Format(SR.DataGridView_AccRowName, 1), accessibleObject1.Name);
153-
Assert.Equal(string.Format(SR.DataGridView_AccRowName, 2), accessibleObject2.Name);
148+
Assert.Equal(string.Format(SR.DataGridView_AccRowName, 0), accessibleObject1.Name);
149+
Assert.Equal(string.Format(SR.DataGridView_AccRowName, 1), accessibleObject2.Name);
154150
Assert.Equal(string.Format(SR.DataGridView_AccRowName, -1), accessibleObject3.Name);
155151
Assert.False(dataGridView.IsHandleCreated);
156152
}
@@ -2388,17 +2384,17 @@ public void DataGridViewRowAccessibleObject_GetPropertyValue_ValueValuePropertyI
23882384
[WinFormsFact]
23892385
public void DataGridView_SwitchConfigured_AdjustsRowStartIndices()
23902386
{
2391-
LocalAppContextSwitches.SetDataGridViewUIAStartRowCountAtZero(true);
2387+
AppContext.SetSwitch(LocalAppContextSwitches.DataGridViewUIAStartRowCountAtOneSwitchName, true);
23922388

23932389
using DataGridView dataGridView = new();
23942390
dataGridView.Columns.Add(new DataGridViewTextBoxColumn());
23952391
dataGridView.Rows.Add(new DataGridViewRow());
23962392

2397-
Assert.Equal(string.Format(SR.DataGridView_AccRowName, 0), dataGridView.Rows[0].AccessibilityObject.Name);
2393+
Assert.Equal(string.Format(SR.DataGridView_AccRowName, 1), dataGridView.Rows[0].AccessibilityObject.Name);
23982394

2399-
LocalAppContextSwitches.SetDataGridViewUIAStartRowCountAtZero(false);
2395+
AppContext.SetSwitch(LocalAppContextSwitches.DataGridViewUIAStartRowCountAtOneSwitchName, false);
24002396

2401-
Assert.Equal(string.Format(SR.DataGridView_AccRowName, 1), dataGridView.Rows[0].AccessibilityObject.Name);
2397+
Assert.Equal(string.Format(SR.DataGridView_AccRowName, 0), dataGridView.Rows[0].AccessibilityObject.Name);
24022398
}
24032399

24042400
private class SubDataGridViewCell : DataGridViewCell

0 commit comments

Comments
 (0)