procedure GridSort(StrGrid: TStringGrid; NoColumn: Integer); var Line, PosActual: Integer; Row: TStringList; Renglon :TStringList; begin Renglon := TStringList.Create; Row := TStringList.Create; for Line := 0 to StrGrid.RowCount-1 do begin PosActual := Line; Row.Assign(StrGrid.Rows[PosActual]); while True do begin if (PosActual = 0) or (Row.Strings[NoColumn] >= StrGrid.Cells[NoColumn,PosActual-1]) then break; StrGrid.Rows[PosActual] := StrGrid.Rows[PosActual-1]; Dec(PosActual); end; if (Row.Strings[NoColumn] < StrGrid.Cells[NoColumn,PosActual]) then StrGrid.Rows[PosActual].Assign(Row); end; Row.Free; Renglon.Free; end; 

The code above sorts one column by GridSort(StringGrid1, 1); And it works like this:
How sorting works

It is possible to modify the code so that I select the cell "KSK12" in the first column (that is, any non-alphabetical group), and he brought me the first lines with "KSK12" and alphabetical names, and then other groups went. And how to make, that did not affect the fixed lines?

  • In short: yes, it is possible. What difficulties did you have with modifying a few code sorting conditions from the answer to your previous question, in fact - it is almost the same from this question? ru.stackoverflow.com/q/526491/192901 - kami
  • SgSort (StringGrid1, 1); 'List index out of bounds (28)' - Nick
  • one
    Please supplement your question with necessary information: 1. Your version of the code, which should perform the task set in the question. 2. An indication in this code of the place where the error occurs. The current submitted code, to put it mildly, is not particularly clear and it does not reflect your attempt to solve the problem. And after - what was the bad code suggested in the answer to the previous question? - kami

0