{"record":{"id":"85579c8fa384b928","repo":"dotnet/wpf","slug":"sr-gridcolumnoutofrange","errorCode":null,"errorMessage":"SR.GridColumnOutOfRange","messagePattern":"SR\\.GridColumnOutOfRange","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListView.cs","lineNumber":746,"sourceCode":"        #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        {\n            get\n            {\n                return GetRowCount (_hwnd);\n            }\n        }","sourceCodeStart":728,"sourceCodeEnd":764,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListView.cs#L728-L764","documentation":"WindowsListView's IGridProvider.GetItem throws ArgumentOutOfRangeException with SR.GridColumnOutOfRange when the column parameter is negative or >= GetColumnCount(_hwnd). The column index does not exist in the list-view's grid (only meaningful in details view).","triggerScenarios":"Calling GetItem(row, column) with column < 0 or column >= GetColumnCount — e.g. column 3 when the list-view shows only 2 columns, or in non-details views where the column count is limited.","commonSituations":"Column sets changed (columns added/removed) after the script cached them; switching to a view mode with fewer columns; iterating columns with wrong bounds.","solutions":["Query GridPattern.ColumnCount right before GetItem and validate the column index.","Handle view-mode changes: re-fetch column count after switching views.","Catch ArgumentOutOfRangeException and skip missing columns.","Cache column indexes by header name and resolve them dynamically."],"exampleFix":"// before\nvar cell = grid.GetItem(row, 3);\n// after\nif (3 < grid.Current.ColumnCount) { var cell = grid.GetItem(row, 3); }","handlingStrategy":"validation","validationCode":"int cols = ((GridPattern)element.GetCurrentPattern(GridPattern.Pattern)).Current.ColumnCount;\nif (column >= 0 && column < cols) { grid.GetItem(row, column); }","typeGuard":null,"tryCatchPattern":"try { grid.GetItem(row, col); } catch (ArgumentOutOfRangeException) { /* column not present in current view */ }","preventionTips":["Re-query ColumnCount after view-mode or column changes","Map columns by header name at runtime instead of hard-coding indexes","Remember non-details views expose fewer/no grid columns"],"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"}