想在STRINGGRID里想ACCESS那样可以任意排序!!!请指教!!!
解决方案 »
- delphi读取word,并建立目录,求高手帮忙。
- 如何VB的内容改成Delphi语法
- 谁有加密算法的函数?RSA,DSA,MD5,BLOWFISH,TIGER,3DES,RC4,RC5,2FISH ... (分不够再开贴!!!!)
- 由Delphi中的图像灰度化代码看基本图像处理~~~
- 求助.DLL中使用ADO的问题.
- 大家做软件主界面是什么样式的?我想做一个图形主界面?
- 请搞过webservice的高手进来看看,谢谢!
- 求教XPMenu控件的详细用法!XPMenu自带了一张图,他的很多功能我都不会用啊!
- 如何使DBGrid中的PickList自动弹出,而不用点鼠标?
- 我有如下定义ColNum:integer,且给ColNum给了初值,有如下式:Col<>5 ,报错类型不匹配,这是为什么?
- 类(分数太多了,散100分)
- 请教如何打开一个外部程序并隐藏,,
标题:字符网格排序
说明:升序、降序;示例点击标题排序
设计:Zswang
日期:2002-04-27
支持:[email protected]
//*)///////Begin Source
function StringGridRowSwap(mStringGrid: TStringGrid;
mFromRow, mToRow: Integer): Boolean;
var
S: string;
begin
Result := False;
if (mToRow = mFromRow) then Exit;
if not Assigned(mStringGrid) then Exit;
if (mFromRow < 0) or (mFromRow >= mStringGrid.RowCount) then Exit;
if (mToRow < 0) or (mToRow >= mStringGrid.RowCount) then Exit;
try
S := mStringGrid.Rows[mFromRow].Text;
mStringGrid.Rows[mFromRow].Text := mStringGrid.Rows[mToRow].Text;
mStringGrid.Rows[mToRow].Text := S;
except
Exit;
end;
Result := True;
end; { StringGridRowSwap }function StringGridRowSort(mStringGrid: TStringGrid;
mColIndex: Integer; mDesc: Boolean = False): Boolean;
var
I, J: Integer;
begin
Result := False;
if not Assigned(mStringGrid) then Exit;
if (mColIndex < 0) or (mColIndex >= mStringGrid.ColCount) then Exit;
for I := mStringGrid.FixedRows to mStringGrid.RowCount - 2 do
for J := I + 1 to mStringGrid.RowCount - 1 do
if mDesc then
if mStringGrid.Cells[mColIndex, I] < mStringGrid.Cells[mColIndex, J] then
StringGridRowSwap(mStringGrid, I, J)
else
else if mStringGrid.Cells[mColIndex, I] > mStringGrid.Cells[mColIndex, J] then
StringGridRowSwap(mStringGrid, I, J);
Result := True;
end; { StringGridRowSort }
///////End Source///////Begin Demo
procedure TForm1.StringGrid1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
{$J+}
const
vOldCol: Integer = -1;
{$J-}
var
vCol, vRow: Integer;
begin
if Button = mbRight then Exit;
TStringGrid(Sender).MouseToCell(X, Y, vCol, vRow);
if (vRow < 0) or (vRow >= TStringGrid(Sender).FixedRows) then Exit;
StringGridRowSort(TStringGrid(Sender), vCol, vOldCol = vCol);
if vOldCol = vCol then
vOldCol := - vOldCol
else vOldCol := vCol;
end;
///////End Demo