Datagrid : déplacer une colonne

cs_thinat Messages postés 1 Date d'inscription mardi 7 décembre 2004 Statut Membre Dernière intervention 14 janvier 2005 - 14 janv. 2005 à 23:52
Arthenius Messages postés 1182 Date d'inscription mercredi 21 janvier 2004 Statut Membre Dernière intervention 6 septembre 2011 - 17 janv. 2005 à 09:49
Bonjour



comment déplacer une colonne dans un datagrid (drag and drop d'une colonne dans un même datagrid)



merci pour vos réponses



thinat

1 réponse

Arthenius Messages postés 1182 Date d'inscription mercredi 21 janvier 2004 Statut Membre Dernière intervention 6 septembre 2011 14
17 janv. 2005 à 09:49
un debut de reponse trouver sur le net :


[C#]

public void MoveColumn(DataGrid _dataGrid, string _mappingName, int fromCol, int toCol)

{

if(fromCol == toCol) return;



DataGridTableStyle oldTS = _dataGrid.TableStyles[_mappingName];

DataGridTableStyle newTS = new DataGridTableStyle();

newTS.MappingName = _mappingName;



for(int i = 0; i < oldTS.GridColumnStyles.Count; ++i)

{

if(i != fromCol && fromCol < toCol)

newTS.GridColumnStyles.Add(oldTS.GridColumnStyles[i]);

if(i == toCol)

newTS.GridColumnStyles.Add(oldTS.GridColumnStyles[fromCol]);

if(i != fromCol && fromCol > toCol)

newTS.GridColumnStyles.Add(oldTS.GridColumnStyles[i]);

}



_dataGrid.TableStyles.Remove(oldTS);

_dataGrid.TableStyles.Add(newTS);

}



//sample usage

private void button1_Click(object sender, System.EventArgs e)

{

MoveColumn(myDataGrid, "Customers", 3, 1);

}


Arthenius

"Il n'y a pas de mauvais développeurs,...
mais uniquement de mauvais utilisateurs..."
0
Rejoignez-nous