{"record":{"id":"6b67c7c411fbc1ff","repo":"dotnet/wpf","slug":"sr-gridrowoutofrange","errorCode":null,"errorMessage":"SR.GridRowOutOfRange","messagePattern":"SR\\.GridRowOutOfRange","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListView.cs","lineNumber":741,"sourceCode":"            {\n                return (bool) WindowScroll.GetPropertyScroll (ScrollPattern.VerticallyScrollableProperty, _hwnd);\n            }\n        }\n\n        #endregion ScrollPattern\n\n        #region Grid Pattern\n\n        // Obtain the AutomationElement at an zero based absolute position in the grid.\n        // Where 0,0 is top left\n        IRawElementProviderSimple IGridProvider.GetItem(int row, int column)\n        {\n            int maxRow = GetRowCount (_hwnd);\n            int maxColumn = GetColumnCount (_hwnd);\n\n            if (row < 0 || row >= maxRow)\n            {\n                throw new ArgumentOutOfRangeException(nameof(row), row, SR.GridRowOutOfRange);\n            }\n\n            if (column < 0 || column >= maxColumn)\n            {\n                throw new ArgumentOutOfRangeException(nameof(column), column, SR.GridColumnOutOfRange);\n            }\n\n            // GetCell\n            if (IsDetailMode (_hwnd))\n            {\n                return GetCellInDetailMode (row, column);\n            }\n\n            return GetCellInOtherModes (row, column, maxColumn, maxRow);\n        }\n\n        int IGridProvider.RowCount\n        {","sourceCodeStart":723,"sourceCodeEnd":759,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListView.cs#L723-L759","documentation":"WindowsListView's IGridProvider.GetItem throws ArgumentOutOfRangeException with SR.GridRowOutOfRange when the row parameter is negative or >= the list-view's current row count (GetRowCount). The requested grid cell is outside the control's grid extent.","triggerScenarios":"Calling GetItem(row, column) with row < 0 or row >= GetRowCount(_hwnd) — e.g. row 5 on a list that now has only 3 items after a refresh.","commonSituations":"Test scripts caching item counts from before a list refresh; iterating rows with an off-by-one bound; automating virtual-mode lists whose counts changed.","solutions":["Read GridPattern.RowCount (or the list count) immediately before calling GetItem and bound the loop with it.","Clamp or validate the row index before the call.","Catch ArgumentOutOfRangeException and re-query the current count.","Refresh the automation element after list changes before indexing."],"exampleFix":"// before\nfor (int r = 0; r <= cachedCount; r++) grid.GetItem(r, 0);\n// after\nint count = grid.Current.RowCount;\nfor (int r = 0; r < count; r++) grid.GetItem(r, 0);","handlingStrategy":"validation","validationCode":"int rows = ((GridPattern)element.GetCurrentPattern(GridPattern.Pattern)).Current.RowCount;\nif (row >= 0 && row < rows) { grid.GetItem(row, column); }","typeGuard":null,"tryCatchPattern":"try { grid.GetItem(row, col); } catch (ArgumentOutOfRangeException) { /* row no longer exists; re-query RowCount */ }","preventionTips":["Always read RowCount immediately before indexing","Use exclusive upper bounds in row loops","Re-fetch counts after any list refresh"],"tags":["ui-automation","grid-pattern","argument-out-of-range"],"backgroundTag":"argument-out-of-range","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}