{"record":{"id":"4da0875f62c45e89","repo":"dotnet/wpf","slug":"sr-gridrowoutofrange-windowslistviewgroup","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/WindowsListViewGroup.cs","lineNumber":366,"sourceCode":"            }\n\n            return false;\n        }\n\n        #endregion Interface Methods\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, ID);\n            int maxColumn = GetColumnCount(_hwnd, ID);\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            if (WindowsListView.IsDetailMode (_hwnd))\n            {\n                return GetCellInDetailMode (row, column);\n            }\n\n            return GetCellInOtherModes (row, column, maxColumn);\n        }\n\n        int IGridProvider.RowCount\n        {\n            get","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListViewGroup.cs#L348-L384","documentation":"WindowsListViewGroup's IGridProvider.GetItem validates the requested row against GetRowCount and throws ArgumentOutOfRangeException with SR.GridRowOutOfRange when row < 0 or row >= maxRow. Grid cell coordinates must fall within the group's current row/column extents.","triggerScenarios":"Calling GridPattern.GetItem(row, column) on a ListView group item with row < 0 or row >= GetRowCount(_hwnd, ID), e.g. using list-count based assumptions after rows were removed.","commonSituations":"Automation clients that cached GridPattern.RowCount earlier and iterate with the old count after the ListView data changed; zero-based vs one-based indexing mistakes.","solutions":["Re-read GridPattern.Current.RowCount immediately before iterating rows.","Validate 0 <= row < RowCount before GetItem.","Use a loop bounded by the freshly queried RowCount rather than hardcoded sizes."],"exampleFix":"// before\nfor (int r = 0; r < cachedRows; r++) grid.GetItem(r, 0);\n// after\nint maxRow = grid.Current.RowCount;\nfor (int r = 0; r < maxRow; r++) grid.GetItem(r, 0);","handlingStrategy":"validation","validationCode":"int maxRow = grid.Current.RowCount;\nif (row < 0 || row >= maxRow) return null;","typeGuard":"bool IsValidRow(int row, int maxRow) => row >= 0 && row < maxRow;","tryCatchPattern":"try { cell = grid.GetItem(row, col); }\ncatch (ArgumentOutOfRangeException) { cell = null; }","preventionTips":["Refresh RowCount before every grid iteration.","Never assume fixed row counts; use zero-based bounds checks."],"tags":["uiautomation","grid-pattern","argument-out-of-range"],"backgroundTag":"index-out-of-range","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}