I am trying to implement a DataGridView that allows both selecting an entire row by clicking the row header or selecting an entire column by clicking the column header.
I've tried overriding the OnColumnHeaderMouseClick function and manually selecting the column. This only works if I set the SelectionMode to ColumnHeaderSelect before the event happens.
Any help on how to get this behavior would be greatly appreciated!
Here is the relevant code from my DataGridView:
public class CustomDataGridView : DataGridView
{
protected override void OnRowHeaderMouseClick(DataGridViewCellMouseEventArgs e)
{
this.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
base.OnRowHeaderMouseClick(e);
}
protected override void OnColumnHeaderMouseClick(DataGridViewCellMouseEventArgs e)
{
this.SelectionMode = DataGridViewSelectionMode.ColumnHeaderSelect;
base.OnColumnHeaderMouseClick(e);
}
}