Exemple #1
0
            public override AccessibleObject?Navigate(AccessibleNavigation navigationDirection)
            {
                if (Owner is null)
                {
                    throw new InvalidOperationException(SR.DataGridViewCellAccessibleObject_OwnerNotSet);
                }

                if (Owner.OwningRow is null || Owner.DataGridView is null)
                {
                    return(null);
                }

                switch (navigationDirection)
                {
                case AccessibleNavigation.Next:
                    return((Owner.DataGridView.Columns.GetColumnCount(DataGridViewElementStates.Visible) > 0)
                            ? ParentPrivate?.GetChild(1) // go to the next sibling
                            : null);

                case AccessibleNavigation.Down:
                {
                    if (Owner.OwningRow.Index == Owner.DataGridView.Rows.GetLastRow(DataGridViewElementStates.Visible))
                    {
                        return(null);
                    }

                    int nextVisibleRow     = Owner.DataGridView.Rows.GetNextRow(Owner.OwningRow.Index, DataGridViewElementStates.Visible);
                    int actualDisplayIndex = Owner.DataGridView.Rows.GetRowCount(DataGridViewElementStates.Visible, 0, nextVisibleRow);

                    if (Owner.DataGridView.ColumnHeadersVisible)
                    {
                        // Add 1 because the first child in the data grid view acc obj is the top row header acc obj
                        actualDisplayIndex++;
                    }

                    return(Owner.DataGridView.AccessibilityObject.GetChild(actualDisplayIndex)?.GetChild(0));
                }

                case AccessibleNavigation.Up:
                {
                    if (Owner.OwningRow.Index == Owner.DataGridView.Rows.GetFirstRow(DataGridViewElementStates.Visible))
                    {
                        if (!Owner.DataGridView.ColumnHeadersVisible)
                        {
                            return(null);
                        }

                        // Return the top left header cell accessible object.
                        Debug.Assert(Owner.DataGridView.TopLeftHeaderCell.AccessibilityObject == Owner.DataGridView.AccessibilityObject.GetChild(0) !.GetChild(0));
                        return(Owner.DataGridView.AccessibilityObject.GetChild(0)?.GetChild(0));
                    }
                    else
                    {
                        int previousVisibleRow = Owner.DataGridView.Rows.GetPreviousRow(Owner.OwningRow.Index, DataGridViewElementStates.Visible);
                        int actualDisplayIndex = Owner.DataGridView.Rows.GetRowCount(DataGridViewElementStates.Visible, 0, previousVisibleRow);
                        if (Owner.DataGridView.ColumnHeadersVisible)
                        {
                            // Add 1 because the first child in the data grid view acc obj is the top row header acc obj
                            actualDisplayIndex++;
                        }

                        return(Owner.DataGridView.AccessibilityObject.GetChild(actualDisplayIndex)?.GetChild(0));
                    }
                }

                case AccessibleNavigation.Previous:
                default:
                    return(null);
                }
            }
            public override AccessibleObject Navigate(AccessibleNavigation navigationDirection)
            {
                Debug.Assert(Owner.DataGridView.RowHeadersVisible, "if the rows are not visible how did you get the row headers acc obj?");
                switch (navigationDirection)
                {
                case AccessibleNavigation.Next:
                    if (Owner.OwningRow != null && Owner.DataGridView.Columns.GetColumnCount(DataGridViewElementStates.Visible) > 0)
                    {
                        // go to the next sibling
                        return(ParentPrivate.GetChild(1));
                    }
                    else
                    {
                        return(null);
                    }

                case AccessibleNavigation.Down:
                    if (Owner.OwningRow == null)
                    {
                        return(null);
                    }
                    else
                    {
                        if (Owner.OwningRow.Index == Owner.DataGridView.Rows.GetLastRow(DataGridViewElementStates.Visible))
                        {
                            return(null);
                        }
                        else
                        {
                            int nextVisibleRow     = Owner.DataGridView.Rows.GetNextRow(Owner.OwningRow.Index, DataGridViewElementStates.Visible);
                            int actualDisplayIndex = Owner.DataGridView.Rows.GetRowCount(DataGridViewElementStates.Visible, 0, nextVisibleRow);

                            if (Owner.DataGridView.ColumnHeadersVisible)
                            {
                                // + 1 because the first child in the data grid view acc obj is the top row header acc obj
                                return(Owner.DataGridView.AccessibilityObject.GetChild(1 + actualDisplayIndex).GetChild(0));
                            }
                            else
                            {
                                return(Owner.DataGridView.AccessibilityObject.GetChild(actualDisplayIndex).GetChild(0));
                            }
                        }
                    }

                case AccessibleNavigation.Previous:
                    return(null);

                case AccessibleNavigation.Up:
                    if (Owner.OwningRow == null)
                    {
                        return(null);
                    }
                    else
                    {
                        if (Owner.OwningRow.Index == Owner.DataGridView.Rows.GetFirstRow(DataGridViewElementStates.Visible))
                        {
                            if (Owner.DataGridView.ColumnHeadersVisible)
                            {
                                // Return the top left header cell accessible object.
                                Debug.Assert(Owner.DataGridView.TopLeftHeaderCell.AccessibilityObject == Owner.DataGridView.AccessibilityObject.GetChild(0).GetChild(0));
                                return(Owner.DataGridView.AccessibilityObject.GetChild(0).GetChild(0));
                            }
                            else
                            {
                                return(null);
                            }
                        }
                        else
                        {
                            int previousVisibleRow = Owner.DataGridView.Rows.GetPreviousRow(Owner.OwningRow.Index, DataGridViewElementStates.Visible);
                            int actualDisplayIndex = Owner.DataGridView.Rows.GetRowCount(DataGridViewElementStates.Visible, 0, previousVisibleRow);
                            if (Owner.DataGridView.ColumnHeadersVisible)
                            {
                                // + 1 because the first child in the data grid view acc obj is the top row header acc obj
                                return(Owner.DataGridView.AccessibilityObject.GetChild(actualDisplayIndex + 1).GetChild(0));
                            }
                            else
                            {
                                return(Owner.DataGridView.AccessibilityObject.GetChild(actualDisplayIndex).GetChild(0));
                            }
                        }
                    }

                default:
                    return(null);
                }
            }