From: Peter T. <pe...@us...> - 2003-11-21 11:06:35
|
Update of /cvsroot/jvcl/dev/JVCL3/run In directory sc8-pr-cvs1:/tmp/cvs-serv32563/JVCL3/run Modified Files: JvStringGrid.pas Log Message: - Sorting fixes Index: JvStringGrid.pas =================================================================== RCS file: /cvsroot/jvcl/dev/JVCL3/run/JvStringGrid.pas,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** JvStringGrid.pas 15 Nov 2003 18:56:58 -0000 1.7 --- JvStringGrid.pas 21 Nov 2003 11:06:30 -0000 1.8 *************** *** 400,404 **** i, j: integer; begin ! i := FixedRows; j := RowCount - 1; while i < j do --- 400,407 ---- i, j: integer; begin ! if Fixed then ! i := 0 ! else ! i := FixedRows; j := RowCount - 1; while i < j do *************** *** 414,418 **** i, j: integer; begin ! i := FixedRows; Result := i; j := RowCount - 1; --- 417,424 ---- i, j: integer; begin ! if Fixed then ! i := 0 ! else ! i := FixedRows; Result := i; j := RowCount - 1; *************** *** 427,435 **** end; end; begin if (Column >= 0) and (Column < ColCount) and (SortType <> stNone) then begin ! LStart := FixedRows; lEnd := RowCount - 1; if BlankTop then --- 433,473 ---- end; end; + procedure MoveBlankBottom; + var + i, j: integer; + DoSort: boolean; + begin + if Fixed then + i := 0 + else + i := FixedRows; + DoSort := false; + // avoid empty columns + for j := i to RowCount - 1 do + if Cells[Column, j] <> '' then + begin + DoSort := true; + Break; + end; + if not DoSort then Exit; + // this is already sorted, so blank items should be at top + while Trim(Cells[Column, i]) = '' do + begin + InsertRow(RowCount).Assign(Rows[i]); + DeleteRow(i); + Inc(j); + if j >= RowCount then Exit; + end; + end; begin + // (p3) NB!! sorting might trigger the OnExitCell, OnGetEditText and OnSetEditText events! + // make sure you don't do anything in these events if (Column >= 0) and (Column < ColCount) and (SortType <> stNone) then begin ! if Fixed then ! LStart := 0 ! else ! LStart := FixedRows; lEnd := RowCount - 1; if BlankTop then *************** *** 438,441 **** --- 476,481 ---- begin QuickSort(LStart, lEnd); + if not BlankTop then + MoveBlankBottom; if not Ascending then InvertGrid; *************** *** 1035,1039 **** if RowHeights[ARow] < 0 then RowHeights[ARow] := AHeight; end; - end. --- 1075,1078 ---- |