Prevent DataGridView from selecting a row when sorting if none of them was previously selected

I have a datagridview that may or may not have rows selected when the user sorts it by clicking on the column header. If there are rows selected, no problem occurs, but if there are 0 selected rows, the sort will automatically select the row (selection is consistent, but I'm not sure what those criteria are). How can I prevent this behavior.

If it matters, the DGV is not database bound and full row selection is enabled.

+2


source to share


1 answer


Handle the Sorted DataGridView event:



this.dataGridView1.Sorted += new System.EventHandler(dataGridView1_Sorted);

void dataGridView1_Sorted(object sender, System.EventArgs e)
{
    dataGridView1.ClearSelection();
}

      

+6


source







All Articles