{"record":{"id":"18ab79276d49095c","repo":"dotnet/wpf","slug":"sr-gridcolumnoutofrange-windowslistviewgroup","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/WindowsListViewGroup.cs","lineNumber":371,"sourceCode":"        #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\n            {\n                return GetRowCount (_hwnd, ID);\n            }\n        }\n","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsListViewGroup.cs#L353-L389","documentation":"Same IGridProvider.GetItem path as the row check, but for the column: WindowsListViewGroup.GetItem throws ArgumentOutOfRangeException with SR.GridColumnOutOfRange when column < 0 or column >= GetColumnCount(_hwnd, ID). In detail mode the column maps to a ListView subitem, so only existing columns are addressable.","triggerScenarios":"Calling GridPattern.GetItem(row, column) with column < 0 or column >= GetColumnCount, e.g. iterating 0..ColumnHeader.Count of the full ListView when this group exposes fewer columns, or addressing a column that only exists in detail mode.","commonSituations":"Clients assuming the grid always has a fixed number of columns while the control is in a view mode with fewer subitems; off-by-one loops using <= ColumnCount.","solutions":["Query GridPattern.Current.ColumnCount (or GetColumnCount) fresh before each GetItem loop.","Validate 0 <= column < ColumnCount before calling GetItem.","Guard view-mode dependent columns: only access extra columns when IsDetailMode is true."],"exampleFix":"// before\nfor (int c = 0; c <= headers; c++) grid.GetItem(r, c);\n// after\nint maxCol = grid.Current.ColumnCount;\nfor (int c = 0; c < maxCol; c++) grid.GetItem(r, c);","handlingStrategy":"validation","validationCode":"int maxCol = grid.Current.ColumnCount;\nif (column < 0 || column >= maxCol) return null;","typeGuard":"bool IsValidColumn(int col, int maxCol) => col >= 0 && col < maxCol;","tryCatchPattern":"try { cell = grid.GetItem(row, col); }\ncatch (ArgumentOutOfRangeException) { cell = null; }","preventionTips":["Read ColumnCount fresh; columns vary by view mode.","Use < (not <=) in loops over column counts."],"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"}