Sortieren für Profis?
-
Hallo miteinander. Ich habe ein Listview mit X und Y Werten welche quasi so ein Gitter repräsentieren sollen.
Querstriche bitte denken.|E| | | | | | |D| | | |C| |B| | | | |A|
Ich möchte jetzt das A=1 wird, B=2,C=3,D=4 und E=5.. aber ich bekomme es nicht hin. Es soll also von unten rechts angefangen werden und nach oben links gehen. Wäre echt lieb wenn wer Schützenhilfe leisten könnte.
struct Points { int x; int y; int index; }; struct qSort:public binary_function<Points,Points,bool> { bool operator () (const Points& Value1,const Points& Value2)const {return ((Value1.y<Value2.y) && (Value1.x<Value2.x));}; }; void __fastcall TForm2::ResyncNumber() { typedef std::vector<Points> myPoints; myPoints mp; Points pos; for (int i=0;i<ListView1->Items->Count;i++) { pos.index = i; pos.x = StrToInt(ListView1->Items->Item[i]->SubItems->Strings[0]); pos.y = StrToInt(ListView1->Items->Item[i]->SubItems->Strings[1]); mp.push_back(pos); } if (mp.size()>0) { std::sort(mp.begin(), mp.end(), qSort()); std::vector<Points>::const_iterator Iter=mp.begin(); int nummer = 1; do { ListView1->Items->Item[(*Iter).index]->Caption = IntToStr(nummer); nummer++; } while(++Iter != mp.end()); } mp.clear(); }
-
Kumpel hat geholfen mit anderer Methode
pos.index = i; x = StrToInt(ListView1->Items->Item[i]->SubItems->Strings[0]); y = StrToInt(ListView1->Items->Item[i]->SubItems->Strings[1]); pos.v = y*(xmax+1)+x;
und dann nach pos.v sortieren klappt super.
xmax ist die Spaltenanzahl.
-
~qSort schrieb:
Kumpel hat geholfen mit anderer Methode
pos.index = i; x = StrToInt(ListView1->Items->Item[i]->SubItems->Strings[0]); y = StrToInt(ListView1->Items->Item[i]->SubItems->Strings[1]); pos.v = y*(xmax+1)+x;
und dann nach pos.v sortieren klappt super.
xmax ist die Spaltenanzahl.Köntest du mir den code vileicht scicken?
Skype, E-Mail:
in meiner signatur