1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| private int SortedColumnIndex =-1 ;
private string NextSortOrder1 = "ASC" ; // une variable par col cachée associée à une col customisée
private void dataGridView1_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.ColumnIndex==Le_numero_de_colonne_custom1) SortedColumnIndex = e.ColumnIndex;
}
private void dataGridView1_Sorted(object sender, EventArgs e)
{
if (SortedColumnIndex == Le_numero_de_colonne_custom1)
{
SortedColumnIndex = -1 ; // pour éviter de boucler sur l'event Sorted
MyDataGridView.BindingSource.Sort="Le_nom_de_colonne_cachee1,"+NextSortOrder1 ;
NextSortOrder1=NextSortOrder1=="ASC" ? "DESC" : "ASC" ;
}
else NextSortOrder1="ASC" ;
} |
Partager