2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
4
using System . Drawing ;
5
+ using System . Windows . Forms . Primitives ;
5
6
using static Interop ;
6
7
7
8
namespace System . Windows . Forms . Tests ;
@@ -71,6 +72,7 @@ public void DataGridViewRowAccessibleObject_Name_Get_ReturnsExpected_IfDataGridV
71
72
Assert . Equal ( string . Format ( SR . DataGridView_AccRowName , - 1 ) , accessibilityObject . Name ) ;
72
73
}
73
74
75
+ // Whether UIA row indexing is 1-based or 0-based, is controlled by the DataGridViewUIAStartRowCountAtZero switch
74
76
[ Fact ]
75
77
public void DataGridViewRowAccessibleObject_Name_Get_ReturnsExpected ( )
76
78
{
@@ -84,9 +86,9 @@ public void DataGridViewRowAccessibleObject_Name_Get_ReturnsExpected()
84
86
AccessibleObject accessibleObject2 = dataGridView . Rows [ 1 ] . AccessibilityObject ;
85
87
AccessibleObject accessibleObject3 = dataGridView . Rows [ 2 ] . AccessibilityObject ;
86
88
87
- Assert . Equal ( string . Format ( SR . DataGridView_AccRowName , 0 ) , accessibleObject1 . Name ) ;
88
- Assert . Equal ( string . Format ( SR . DataGridView_AccRowName , 1 ) , accessibleObject2 . Name ) ;
89
- Assert . Equal ( string . Format ( SR . DataGridView_AccRowName , 2 ) , accessibleObject3 . Name ) ;
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 ) ;
90
92
Assert . False ( dataGridView . IsHandleCreated ) ;
91
93
}
92
94
@@ -110,6 +112,7 @@ public void DataGridViewRowAccessibleObject_Name_Get_ReturnsExpected_IfFirstRowH
110
112
Assert . False ( dataGridView . IsHandleCreated ) ;
111
113
}
112
114
115
+ // Whether UIA row indexing is 1-based or 0-based, is controlled by the DataGridViewUIAStartRowCountAtZero switch
113
116
[ Fact ]
114
117
public void DataGridViewRowAccessibleObject_Name_Get_ReturnsExpected_IfSecondRowHidden ( )
115
118
{
@@ -125,11 +128,12 @@ public void DataGridViewRowAccessibleObject_Name_Get_ReturnsExpected_IfSecondRow
125
128
AccessibleObject accessibleObject3 = dataGridView . Rows [ 2 ] . AccessibilityObject ;
126
129
127
130
Assert . Equal ( string . Format ( SR . DataGridView_AccRowName , 0 ) , accessibleObject1 . Name ) ;
128
- Assert . Equal ( string . Format ( SR . DataGridView_AccRowName , - 1 ) , accessibleObject2 . Name ) ;
129
- Assert . Equal ( string . Format ( SR . DataGridView_AccRowName , 1 ) , accessibleObject3 . Name ) ;
131
+ Assert . Equal ( string . Format ( SR . DataGridView_AccRowName , 1 ) , accessibleObject2 . Name ) ;
132
+ Assert . Equal ( string . Format ( SR . DataGridView_AccRowName , 2 ) , accessibleObject3 . Name ) ;
130
133
Assert . False ( dataGridView . IsHandleCreated ) ;
131
134
}
132
135
136
+ // Whether UIA row indexing is 1-based or 0-based, is controlled by the DataGridViewUIAStartRowCountAtZero switch
133
137
[ Fact ]
134
138
public void DataGridViewRowAccessibleObject_Name_Get_ReturnsExpected_IfLastRowHidden ( )
135
139
{
@@ -144,8 +148,8 @@ public void DataGridViewRowAccessibleObject_Name_Get_ReturnsExpected_IfLastRowHi
144
148
AccessibleObject accessibleObject2 = dataGridView . Rows [ 1 ] . AccessibilityObject ;
145
149
AccessibleObject accessibleObject3 = dataGridView . Rows [ 2 ] . AccessibilityObject ;
146
150
147
- Assert . Equal ( string . Format ( SR . DataGridView_AccRowName , 0 ) , accessibleObject1 . Name ) ;
148
- Assert . Equal ( string . Format ( SR . DataGridView_AccRowName , 1 ) , accessibleObject2 . Name ) ;
151
+ Assert . Equal ( string . Format ( SR . DataGridView_AccRowName , 1 ) , accessibleObject1 . Name ) ;
152
+ Assert . Equal ( string . Format ( SR . DataGridView_AccRowName , 2 ) , accessibleObject2 . Name ) ;
149
153
Assert . Equal ( string . Format ( SR . DataGridView_AccRowName , - 1 ) , accessibleObject3 . Name ) ;
150
154
Assert . False ( dataGridView . IsHandleCreated ) ;
151
155
}
@@ -2364,6 +2368,23 @@ public void DataGridViewRowAccessibleObject_GetChildCount_ReturnsZero_IfRowHeade
2364
2368
Assert . False ( dataGridView . IsHandleCreated ) ;
2365
2369
}
2366
2370
2371
+ // Unit test for https://github.com/dotnet/winforms/issues/7154
2372
+ [ WinFormsFact ]
2373
+ public void DataGridView_SwitchConfigured_AdjustsRowStartIndices ( )
2374
+ {
2375
+ LocalAppContextSwitches . SetDataGridViewUIAStartRowCountAtZero ( true ) ;
2376
+
2377
+ using DataGridView dataGridView = new ( ) ;
2378
+ dataGridView . Columns . Add ( new DataGridViewTextBoxColumn ( ) ) ;
2379
+ dataGridView . Rows . Add ( new DataGridViewRow ( ) ) ;
2380
+
2381
+ Assert . Equal ( string . Format ( SR . DataGridView_AccRowName , 0 ) , dataGridView . Rows [ 0 ] . AccessibilityObject . Name ) ;
2382
+
2383
+ LocalAppContextSwitches . SetDataGridViewUIAStartRowCountAtZero ( false ) ;
2384
+
2385
+ Assert . Equal ( string . Format ( SR . DataGridView_AccRowName , 1 ) , dataGridView . Rows [ 0 ] . AccessibilityObject . Name ) ;
2386
+ }
2387
+
2367
2388
[ WinFormsFact ]
2368
2389
public void DataGridViewRowAccessibleObject_GetPropertyValue_ValueValuePropertyId_ReturnsExpected ( )
2369
2390
{
0 commit comments