Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void TMainForm::SortGrid(int Col, Direction Dir)
- {
- TStringList *buf = new TStringList;
- bool b = true;
- while (b)
- {
- b = false;
- for (int i = 1; i < StringGrid->RowCount - 1; i++)
- {
- int sign;
- try
- {
- if (Dir == dirDown) sign = StringGrid->Cells[Col][i].ToInt() > StringGrid->Cells[Col][i + 1].ToInt();
- else sign = StringGrid->Cells[Col][i].ToInt() < StringGrid->Cells[Col][i + 1].ToInt();
- }
- catch (EConvertError &error)
- {
- if ((StringGrid->Cells[Col][i] == "" || StringGrid->Cells[Col][i+1] == "") && StringGrid->Cells[Col][i] != StringGrid->Cells[Col][i+1] ) sign = true;
- else if (Dir == dirDown) sign = StringGrid->Cells[Col][i] > StringGrid->Cells[Col][i + 1];
- else sign = StringGrid->Cells[Col][i] < StringGrid->Cells[Col][i + 1];
- }
- if (sign)
- {
- buf->Assign(StringGrid->Rows[i]);
- StringGrid->Rows[i]->Assign(StringGrid->Rows[i + 1]);
- StringGrid->Rows[i + 1]->Assign(buf);
- b = true;
- }
- }
- }
- delete buf;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement