| | |
Sorting a ListBox
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: May 2008
Posts: 5
Reputation:
Solved Threads: 0
Hi happy people
I've bin trying to sort items in a list box, the problem is obviously: It doesn't work
Please, any modifications to the code below is fully and unconditionally allowed.
I've bin trying to sort items in a list box, the problem is obviously: It doesn't work
Please, any modifications to the code below is fully and unconditionally allowed.
C++ Syntax (Toggle Plain Text)
void __fastcall TForm1::btnSortClick(TObject *Sender) { //sort ascending if (rdAscending->Checked){ bool swopped = true; int iEnd; int arr = lstWords->Count; //ShowMessage(arr); iEnd = arr -1; while (swopped) { swopped = false; for (int c=0; c < iEnd; c++) { AnsiString a = lstWords->Items->Strings[c]; AnsiString b = lstWords->Items->Strings[c+1]; if (a > b) { AnsiString txt = lstWords->Items->Strings[c]; lstWords->Items->Strings[c] = lstWords->Items->Strings[c+1]; lstWords->Items->Strings[c+1] = txt; swopped = true; iEnd--; } } } 'Let us do what we do best!' } //sort descending else if (rdDescending->Checked){ bool swopped = true; int iEnd; int arr = lstWords->Count; iEnd = arr -1; while (swopped) { swopped = false; for (int c=0; c < iEnd; c++) { AnsiString a = lstWords->Items->Strings[c]; AnsiString b = lstWords->Items->Strings[c+1]; if (a < b) { AnsiString txt = lstWords->Items->Strings[c]; lstWords->Items->Strings[c] = lstWords->Items->Strings[c+1]; lstWords->Items->Strings[c+1] = txt; swopped = true; iEnd--; } } } } else ShowMessage( "Select either [Ascending] or [Descending]! \nPlease Try Again!"); }
![]() |
Similar Threads
- Starting Python (Python)
- Sorting has me out of sorts. (Visual Basic 4 / 5 / 6)
- Sorting in date order (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: creating a infinate loop
- Next Thread: Compiler for Xda Exec (Windows Mob v5)
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion count database delete deploy desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph homeworkhelp homeworkhelper iamthwee ifstream input int integer lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





