Skip to content

Commit

Permalink
Accessibility: Fixing ItemStatus property in programmatically sorted …
Browse files Browse the repository at this point in the history
…DataGridView (#1055)

* Fixed Programmatic SortMode

* Added unit test

* Fixed Assert syntax in the unit test
  • Loading branch information
vladimir-krestov authored and JuditRose committed May 31, 2019
1 parent 1185b1b commit 65a813c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ internal override object GetPropertyValue(int propertyID)
bool canSort = false;
for (int i = 0; i < owner.Columns.Count; i++)
{
if (owner.CanSort(owner.Columns[i]))
if (owner.IsSortable(owner.Columns[i]))
{
canSort = true;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3296,6 +3296,11 @@ private bool CanSort(DataGridViewColumn dataGridViewColumn)
return dataGridViewColumn.SortMode == DataGridViewColumnSortMode.Automatic && (!VirtualMode || dataGridViewColumn.IsDataBound);
}

private bool IsSortable(DataGridViewColumn dataGridViewColumn)
{
return dataGridViewColumn.SortMode != DataGridViewColumnSortMode.NotSortable && (!VirtualMode || dataGridViewColumn.IsDataBound);
}

// determines if a data bound cell can be validated or not
private bool CanValidateDataBoundDataGridViewCell(DataGridViewCell dataGridViewCurrentCell)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 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 Xunit;

namespace System.Windows.Forms.Tests.AccessibleObjects
Expand All @@ -17,5 +18,21 @@ public void PropertyGridAccessibleObject_Ctor_Default()
Assert.NotNull(accessibleObject);
Assert.Equal(AccessibleRole.Table, accessibleObject.Role);
}

[Fact]
public void DataGridViewAccessibleObject_ItemStatus()
{
DataGridView dataGridView = new DataGridView();
DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
column.SortMode = DataGridViewColumnSortMode.Programmatic;
column.HeaderText = "Some column";

dataGridView.Columns.Add(column);
dataGridView.Sort(dataGridView.Columns[0], ListSortDirection.Ascending);

string itemStatus = dataGridView.AccessibilityObject.GetPropertyValue(NativeMethods.UIA_ItemStatusPropertyId)?.ToString();
string expectedStatus = "Sorted ascending by Some column.";
Assert.Equal(expectedStatus, itemStatus);
}
}
}

0 comments on commit 65a813c

Please sign in to comment.