Dans le contrôle ObjectListView (http://objectlistview.sourceforge.net/html/cookbook.htm), j'essaie d'ajouter un trieur personnalisé où il ignore les préfixes "The" et "A".ObjectListView: Sorter personnalisé
J'ai réussi à le faire avec un ListView régulier, mais maintenant que je suis passé à ObjectListView (beaucoup plus de fonctionnalités et de facilité), je ne peux pas sembler faire la même chose.
Voici le comparateur principal dans le code ObjectListView je pense ...
public int Compare(object x, object y)
{
return this.Compare((OLVListItem)x, (OLVListItem)y);
}
Sorter original pour croissant, à titre d'exemple (Ignorer "A" et "The")
public class CustomSortAsc : IComparer
{
int IComparer.Compare(Object x, Object y)
{
string[] px = Convert.ToString(x).Split(' ');
string[] py = Convert.ToString(y).Split(' ');
string newX = "";
string newY = "";
for (int i = 0; i < px.Length; i++)
{
px[i] = px[i].Replace("{", "");
px[i] = px[i].Replace("}", "");
}
for (int i = 0; i < py.Length; i++)
{
py[i] = py[i].Replace("{", "");
py[i] = py[i].Replace("}", "");
}
if ((px[1].ToLower() == "a") || (px[1].ToLower() == "the"))
{
if (px.Length > 1)
{
for (int i = 2; i < px.Length; i++)
newX += px[i];
}
}
else
{
for (int i = 1; i < px.Length; i++)
newX += px[i];
}
if ((py[1].ToLower() == "a") || (py[1].ToLower() == "the"))
{
if (py.Length > 1)
{
for (int i = 2; i < py.Length; i++)
newY += py[i];
}
}
else
{
for (int i = 1; i < py.Length; i++)
newY += py[i];
}
return ((new CaseInsensitiveComparer()).Compare(newX, newY));
}
Pouvez-vous ajouter plus d'informations, comme quel type de résultat obtenez-vous, comment raccordez-vous CustomSortAsc à la liste, etc.? – Ludovic