Datagridview causing IndexOutOfRangeException when clicked upon
85
Datagridview causing IndexOutOfRangeException when clicked upon -
// I guess the click event tries to get the currently selected row and do something with it,
// while dataGridViewExample.DataSource = null; clears the datasource,
// and the currently selected row becomes null.
// If you set the DataGridView.DataSource to the list,
// you don't need to reset it to null, refresh, and reset it to the list again
// (and refresh again) to see the changes. It will be enough to just refresh the DataGridView.
// You can also just try using an BindingList<T> object instead of a List<T>,
// which will automatically notify your grid of its internal changes
// (Adding and removing elements), and there's also an INotifyPropertyChanged interface you
// can implement on your MyObject class, that will make every property change in an object
// show on the grid (For any changes made to the object in the code, and not through
// the grid itself).