CellContentClick throws ArgumentOutOfRangeException when user clicks on the column header

Problem In a WinForm project, you’re using a DataGridView control and are handling the CellContentClick event. When the user clicks the column header, the following exception is thrown: System.ArgumentOutOfRangeException: ‘Index was out of range. Must be non-negative and less than the size of the collection.Parameter name: index’ The problem is that when the user clicks … Read more

ArgumentOutOfRangeException: InvalidArgument=Value of 0 is not valid for SelectedIndex

Problem Let’s say you’re initializing a ComboBox like this: And you get the following exception: System.ArgumentOutOfRangeException: ‘InvalidArgument=Value of ‘0’ is not valid for ‘SelectedIndex’. (Parameter ‘value’)Actual value was 0.’ You’re getting this exception because the DataSource is empty. Solution Are you expecting there to always be data? If you’re expecting there to always be data, … Read more