<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6001.18148" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial color=#000000 size=2>If its a DBGrid then you need to 
either</FONT></DIV>
<DIV><FONT face=Arial color=#000000 size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial color=#000000 size=2>-Change the order of the dataset 
records&nbsp; - which means defining an index,</FONT></DIV>
<DIV><FONT face=Arial color=#000000 size=2>-Or use a grid like the CSDBGrid 
(freeware&nbsp; been around forever) that allows you to click on the column 
headers to sort, like Windows Explorer.</FONT></DIV>
<DIV><FONT face=Arial color=#000000 size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial color=#000000 size=2>If its a stringgrid then You can sort 
a stringgrid nicely as well by sorting the data:</FONT></DIV>
<DIV><FONT face=Arial color=#000000 size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial color=#000000 size=2>here is an example:</FONT></DIV>
<DIV><FONT face=Arial color=#000000 size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial color=#000000 size=2>procedure xcSortGrid(var PGrid: 
TStringGrid; SortColumn1: Integer; SortColumn2: integer; AscDesc: char; 
CaseInSensitive: Boolean);<BR>var<BR>&nbsp; TmpSortList: TStringList;<BR>&nbsp; 
olddefrow, newdefrow: integer; //keep same data row as default<BR>&nbsp; oldrow, 
datalhs, ptr, colptr, rowptr: integer;<BR>&nbsp; keydata1, keydata2, tempstr: 
string;<BR>&nbsp; firstrow: integer; //first row after fixed rows<BR>&nbsp; 
lAscDesc: char;<BR>&nbsp; tempcells: array of array of 
string;<BR>begin<BR>&nbsp; if PGrid.rowcount &lt; 2 then exit; //nothing to 
sort<BR>&nbsp; TmpSortList := TStringList.Create;<BR>&nbsp; TmpSortList.sorted 
:= false;<BR>&nbsp; olddefrow := -1;<BR>&nbsp; NewDefRow := -1;<BR>&nbsp; if 
PGrid.row &gt; 0 then oldDefRow := PGrid.row;<BR>&nbsp; firstrow := 0;<BR>&nbsp; 
if PGrid.FixedRows &gt; 0 then<BR>&nbsp;&nbsp;&nbsp; firstrow := 
PGrid.FixedRows; //1 fixed row-&gt; 1=1st data row<BR>&nbsp; for ptr := firstrow 
to PGrid.rowcount - 1 do<BR>&nbsp; begin<BR>&nbsp;&nbsp;&nbsp; //put sort col 
plus orig pointer into stringlist<BR>&nbsp;&nbsp;&nbsp; keydata1 := 
PGrid.cells[SortColumn1, ptr];<BR>&nbsp;&nbsp;&nbsp; keydata2 := 
PGrid.cells[SortColumn2, ptr];<BR></FONT><FONT face=Arial color=#000000 
size=2></FONT></DIV>
<DIV><FONT face=Arial color=#000000 size=2>&nbsp;&nbsp;&nbsp; tempstr := 
keydata1 + keydata2;<BR>&nbsp;&nbsp;&nbsp; if CaseInsensitive = true then 
uppercase(tempstr);<BR>&nbsp;&nbsp;&nbsp; xcstrpad(tempstr, 
60);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //this pads string 
to 60 chars long<BR>&nbsp;&nbsp;&nbsp; tempstr := tempstr + 
inttostr(ptr);<BR>&nbsp;&nbsp;&nbsp; TmpSortList.Add(tempstr);<BR>&nbsp; 
end;<BR>&nbsp; //sort it<BR>&nbsp; TmpSortList.sorted := true;<BR>&nbsp; //now 
copy original cells to tempcells dynamic array<BR>&nbsp; //this is to keep 
original data as grid is now being overwritten<BR>&nbsp; setlength(tempcells, 
PGrid.colcount, PGrid.rowcount);<BR>&nbsp; for rowptr := firstrow to 
PGrid.rowcount - 1 do<BR>&nbsp; begin<BR>&nbsp;&nbsp;&nbsp; for colptr := 0 to 
PGrid.colcount - 1 do<BR>&nbsp;&nbsp;&nbsp; 
begin<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tempcells[colptr, rowptr] := 
PGrid.cells[colptr, rowptr];<BR>&nbsp;&nbsp;&nbsp; end;<BR>&nbsp; end;<BR>&nbsp; 
//now write tempcells back to grid - note grid may have more than sorted list 
if<BR>&nbsp; //fixed rows, so 2 counters, ptr (list) and rowptr(grid)<BR>&nbsp; 
lAscDesc := upcase(AscDesc);<BR>&nbsp; if lAscDesc = 'A' then<BR>&nbsp; 
begin<BR>&nbsp;&nbsp;&nbsp; for ptr := 0 to TmpSortList.Count - 1 
do<BR>&nbsp;&nbsp;&nbsp; begin<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tempstr := 
copy(TmpSortList[ptr], 61, 10);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oldrow := 
strtoint(tempstr);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if oldrow = oldDefRow then 
NewDefRow := ptr;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //oldptr is orig row number, 
ptr is new row number<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rowptr := ptr + 
firstrow;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for colptr := 0 to PGrid.colcount - 
1 do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
begin<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PGrid.cells[colptr, rowptr] 
:= tempcells[colptr, oldrow];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
end;<BR>&nbsp;&nbsp;&nbsp; end;<BR>&nbsp; end<BR>&nbsp; else<BR>&nbsp; 
begin<BR>&nbsp;&nbsp;&nbsp; for ptr := TmpSortList.count - 1 downto 0 
do<BR>&nbsp;&nbsp;&nbsp; begin<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tempstr := 
copy(TmpSortList[ptr], 61, 10);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oldrow := 
strtoint(tempstr);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if oldrow = oldDefRow then 
NewDefRow := ptr;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //oldptr is orig row number, 
ptr is new row number<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rowptr := ptr + 
firstrow;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for colptr := 0 to PGrid.colcount - 
1 do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
begin<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PGrid.cells[colptr, rowptr] 
:= tempcells[colptr, oldrow];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
end;<BR>&nbsp;&nbsp;&nbsp; end;<BR>&nbsp; end;<BR>&nbsp; 
TmpSortList.free;<BR>&nbsp; tempcells := nil;<BR>&nbsp; if (OldDefRow &gt; 0) 
and (NewDefRow &gt; FirstRow) then PGrid.row := NewDefRow;<BR>&nbsp; //in case 
row not set, makes sure is valid...otherwise grid can sort of scroll<BR>&nbsp; 
//or duplicate fixed row...<BR>&nbsp; if (PGrid.Row &lt; firstrow) or (PGrid.Row 
&gt; PGrid.RowCount - 1) then PGrid.Row := firstrow + 
1;<BR>end;<BR></FONT></DIV>
<DIV><FONT face=Arial color=#000000 size=2></FONT>&nbsp;</DIV>
<DIV>John</DIV>
<DIV>&nbsp;</DIV></BODY></HTML>