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

WinForms: How to handle DataGridViewButtonColumn click event

There’s not a direct way to handle the DataGridViewButtonColumn button click event. Instead, you have to: Handle the DataGridView.CellContentClick event. Check if they clicked the button column. Execute the button click handling logic, passing in the bound data item. In this article I’ll show a step-by-step example of how to handle the button click. Example … Read more