dotnet/wpf · error · ArgumentOutOfRangeException

SR.GridRowOutOfRange

Error message

SR.GridRowOutOfRange

What it means

IGridProvider.GetItem on the Win32 status bar proxy only supports a single row (row 0). Requesting any row other than 0 throws ArgumentOutOfRangeException with SR.GridRowOutOfRange. This reflects the fixed physical layout of a status bar: one row of panes.

Solutions

  1. Pass 0 as the row when calling GetItem on a status bar grid provider.
  2. Check IGridProvider.RowCount (always 1 for status bars) before iterating rows.
  3. Wrap GetItem in a check that skips statuses/rows greater than RowCount-1.

Example fix

// before
for (int row = 0; row < assumedRows; row++) grid.GetItem(row, col);
// after
int rows = gridProvider.RowCount;
for (int row = 0; row < rows; row++) gridProvider.GetItem(row, col);
Defensive patterns

Strategy: validation

Validate before calling

var grid = statusBar.GetCurrentPattern(GridPattern.Pattern) as GridPattern;
if (row < 0 || row >= grid.RowCount) throw new InvalidOperationException("row out of range");
var item = grid.GetItem(row, column);

Type guard

static bool IsValidRow(GridPattern g, int row) => row >= 0 && row < g.RowCount;

Try / catch

try { grid.GetItem(row, col); }
catch (ArgumentOutOfRangeException) { /* treat as no such cell */ }

Prevention

When it happens

Trigger: Calling IGridProvider.GetItem(row, column) on a status bar element with row != 0.

Common situations: Generic grid-walking automation code that iterates rows 0..RowCount-1 but is fed a wrong row bound; treating a status bar as a multi-row grid; copy-pasted grid logic from ListView/DataGridView scenarios.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/326756da75492e9e. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsStatusBar.cs:255

                    ProxySimple grip = StatusBarGrip.Create(_hwnd, this, -1);
                    return (ProxySimple)(grip ?? this);
                }
            }
            return this;
        }

        #endregion

        #region Grid Pattern

        // Obtain the AutomationElement at an zero based absolute position in the grid.
        // Where 0,0 is top left
        IRawElementProviderSimple IGridProvider.GetItem(int row, int column)
        {
            // NOTE: Status bar has only 1 row
            if (row != 0)
            {
                throw new ArgumentOutOfRangeException(nameof(row), row, SR.GridRowOutOfRange);
            }

            if (column < 0 || column >= Count)
            {
                throw new ArgumentOutOfRangeException(nameof(column), column, SR.GridColumnOutOfRange);
            }

            return CreateStatusBarPane(column);
        }

        int IGridProvider.RowCount
        {
            get
            {
                return 1;
            }
        }

View on GitHub (pinned to 81131a70a4)