1 自动就是可以调节的
2 不可以,要用代码实现
3 OnSelectCell
4 要用代码实现
2 不可以,要用代码实现
3 OnSelectCell
4 要用代码实现
解决方案 »
- Delphi 怎么样调用这个dll里面的函数?
- 怎样删除treeview中一项下面的所有子项,主要怎么删除数据表中的内容,
- 国庆散分------非常久没来看看了,兄弟们有谁还在? zdcnow
- 北京爱琴海第一次公开招聘,应届毕业生优先
- 用activexfrom开发的控件,打包成cab后在客户端注册不上是为何
- 如何改变TEdit,TComboBox控件Enabled:=False时字体颜色(不用控件)
- [抢分]怎样在Delphi的IDE中不让光标到处跑
- “流“这个东东怎么用?
- DELPHI参数传递
- 如果用TreeView自动来实现管理财务软件的科目管理?
- 很喜欢Delphi,我乐意投入我的的精力去研究它,请问。。。
- delpi中的ftp控件能不能通过防火墙传送文件
2、能不能清空stringgrid中的内容?
for j = 0 to Grid.ColCount-1 do
Grid.Cells[i,j] := '';
不可能的。
拖动是goColMoving
你再检查一下Options.goColSizing是否为true
另外:固定列不能移动或改变大小
参看函数DrawButtonFace
function DrawButtonFace(Canvas: TCanvas; const Client: TRect;
BevelWidth: Integer; Style: TButtonStyle; IsRounded, IsDown,
IsFocused: Boolean): TRect;
procedure GridQuickSort(Grid: TStringGrid; ACol: Integer; Order: Boolean ; NumOrStr: Boolean);
(******************************************************************************)
(* 函数名称:GridQuickSort *)
(* 函数功能:给 StringGrid 的 ACol 列快速法排序 _/_/ _/_/ _/_/_/_/_/ *)
(* 参数说明: _/ _/ _/ *)
(* Order: True 从小到大 _/ _/ *)
(* : False 从大到小 _/ _/ *)
(* NumOrStr : true 值的类型是Integer _/_/ _/_/ *)
(* : False 值的类型是String *)
(* 函数说明:对于日期,时间等类型数据均可按字符方式排序, *)
(* *)
(* *)
(* Author: YuJie 2001-05-27 *)
(* Email : [email protected] *)
(******************************************************************************)
procedure MoveStringGridData(Grid: TStringGrid; Sou,Des :Integer );
var0D
TmpStrList: TStringList ;
K : Integer ;
0A begin
try
TmpStrList :=TStringList.Create() ;
TmpStrList.Clear ;
for K := Grid.FixedCols to Grid.ColCount -1 do
TmpStrList.Add(Grid.Cells[K,Sou]) ;
Grid.Rows [Sou] :3D Grid.Rows [Des] ;
for K := Grid.FixedCols to Grid.ColCount -1 do
Grid.Cells [K,Des]:= TmpStrList.Strings[K] ;
finally
TmpStrList.Free ;
end;
end; procedure QuickSort(Grid: TStringGrid; iLo, iHi: Integer);
var
0A Lo, Hi : Integer;
Mid: String ;
begin0D
Lo := iLo ;
Hi := iHi ;
Mid :3D Grid.Cells[ACol,(Lo + Hi) div 2];
repeat
if Order and not NumOrStr then //按正序、字符排
begin
while Grid.Cells[ACol,Lo] < Mid do Inc(Lo);
while Grid.Cells[ACol,Hi] > Mid do Dec(Hi);
end ;0D
if not Order and not NumOrStr then //按反序、字符排
begin
while Grid.Cells[ACol,Lo] > Mid do Inc(Lo);
while Grid.Cells[ACol,Hi] < Mid do Dec(Hi);
end; if NumOrStr then
begin
if Grid.Cells[ACol,Lo] = '' then Grid.Cells[ACol,Lo] :3D '0' ;
if Grid.Cells[ACol,Hi] = '' then Grid.Cells[ACol,Hi] := '0' ;
0A if Mid = '' then Mid := '0' ;
if Order then
begin //按正序、数字排
while StrToFloat(Grid.Cells[ACol,Lo]) < StrToFloat(Mid) do Inc(Lo);
while StrToFloat(Grid.Cells[ACol,Hi]) > StrToFloat(Mid) do Dec(Hi);
end else
begin //按反序、数字排
while StrToFloat(Grid.Cells[ACol,Lo]) > StrToFloat(Mid) do Inc(Lo);
while StrToFloat(Grid.Cells[ACol,Hi]) < StrToFloat(Mid) do Dec(Hi);
end;
end ;
if Lo <= Hi then
begin
MoveStringGridData(Grid, Lo, Hi) ;
0A Inc(Lo);
Dec(Hi);
end;
0A until Lo > Hi;
if Hi > iLo then QuickSort(Grid, iLo, Hi);
if Lo < iHi then QuickSort(Grid, Lo, iHi);
end;begin
try
QuickSort(Grid, Grid.FixedRows, Grid.RowCount - 1 ) ;
except
on E: Exception do
Application.MessageBox(Pchar('系统在排序数据的时候遇到异常:'#13+E.message+#13'请重试,如果该问题依然存在请与程序供应商联系!'),'系统错误',MB_OK+MB_ICONERROR) ;
0A end;
end;procedure StringGridTitleDown(Sender: TObject;Button: TMouseButton; X, Y: Integer);
(******************************************************************************)
(* 函数名称:StringGridTitleDown *)
(* 函数功能:取鼠标点StringGrid 的列 _/_/ _/_/ _/_/_/_/_/ *)
(* 参数说明: _/ _/ _/ *)
(* Sender _/ _/ *)
(* _/ _/ *)
(* _/_/ _/_/ *)
0A(* *)
(* *)
(* Author: YuJie 2001-05-27 *)
(* Email : [email protected] *)
(******************************************************************************)
var
I: Integer ;
begin
if (Y > 0 ) and (y < TStringGrid(Sender).DefaultRowHeight * TStringGrid(Sender).FixedRows ) then
begin
if Button = mbLeft then
begin
I := X div TStringGrid(Sender).DefaultColWidth ;
//这个i 就是要排序得行了
// 下面调用上面的排序函数就可以了,
GridQuickSort(TStringGrid(Sender), I, False, True) ;
end;
end;
end;
用上面的两个函数就能解决你的问题了。在TStringGrid 的MouseDown事件中调用
StringGridTitleDown 函数就可以。你可能要修改一下StringGridTitleDown函数
来修改排序得方式及其字符类型。
提醒你一下对于日期、时间、布尔等类型数据均可按字符方式排序。例如:
procedure TForm_Main.StringGrid1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
StringGridTitleDown(Sender,Button,X,Y);
end;
来自:久久, 时间:2001-6-18 19:02:00, ID:571876
续上我这里有Demo你要的话我可以发给你。多少分你看着给吧。
来自:dadabox, 时间:2001-6-18 19:05:00, ID:571882
久久哥,我要DEMO,请发给我。若能解决我的问题,我全部分都给你。因为上面那位还没有
将控件发给我的。
来自:duckstar, 时间:2001-6-19 8:18:00, ID:572389
控件已经发出,请查收。分我不要的,因为我也没有解决问题,如果解决
了请给我发一个DEMO,我也想知道怎样能实现。久久的函数不能解决问题吗?
我一会试试。
来自:duckstar, 时间:2001-6-19 8:32:00, ID:572402
我试了一下,
(******************************************************************************)
(* 函数名称:GridQuickSort *)
(* 函数功能:给 StringGrid 的 ACol 列快速法排序 _/_/ _/_/ _/_/_/_/_/ *)
(* 参数说明: _/ _/ _/ *)
(* Order: True 从小到大 _/ _/ *)
(* : False 从大到小 _/ _/ *)
(* NumOrStr : true 值的类型是Integer _/_/ _/_/ *)
(* : False 值的类型是String *)
(* 函数说明:对于日期,时间等类型数据均可按字符方式排序, *)
(* *)
(* *)
(* Author: YuJie 2001-05-27 *)
(* Email : [email protected] *)
(******************************************************************************)
procedure MoveStringGridData(Grid: TStringGrid; Sou,Des :Integer );
var
TmpStrList: TStringList ;
K : Integer ;
begin
try
TmpStrList :=TStringList.Create() ;
TmpStrList.Clear ;
for K := Grid.FixedCols to Grid.ColCount -1 do
TmpStrList.Add(Grid.Cells[K,Sou]) ;
Grid.Rows [Sou] := Grid.Rows [Des] ;
for K := Grid.FixedCols to Grid.ColCount -1 do
Grid.Cells [K,Des]:= TmpStrList.Strings[K] ;
finally
TmpStrList.Free ;
end;
end; procedure QuickSort(Grid: TStringGrid; iLo, iHi: Integer);
var
Lo, Hi : Integer;
Mid: String ;
begin
Lo := iLo ;
Hi := iHi ;
Mid := Grid.Cells[ACol,(Lo + Hi) div 2];
repeat
if Order and not NumOrStr then //按正序、字符排
begin
while Grid.Cells[ACol,Lo] < Mid do Inc(Lo);
while Grid.Cells[ACol,Hi] > Mid do Dec(Hi);
end ;
if not Order and not NumOrStr then //按反序、字符排
begin
while Grid.Cells[ACol,Lo] > Mid do Inc(Lo);
while Grid.Cells[ACol,Hi] < Mid do Dec(Hi);
end; if NumOrStr then
begin
if Grid.Cells[ACol,Lo] = '' then Grid.Cells[ACol,Lo] := '0' ;
if Grid.Cells[ACol,Hi] = '' then Grid.Cells[ACol,Hi] := '0' ;
if Mid = '' then Mid := '0' ;
if Order then
begin //按正序、数字排
while StrToFloat(Grid.Cells[ACol,Lo]) < StrToFloat(Mid) do Inc(Lo);
while StrToFloat(Grid.Cells[ACol,Hi]) > StrToFloat(Mid) do Dec(Hi);
end else
begin //按反序、数字排
while StrToFloat(Grid.Cells[ACol,Lo]) > StrToFloat(Mid) do Inc(Lo);
while StrToFloat(Grid.Cells[ACol,Hi]) < StrToFloat(Mid) do Dec(Hi);
end;
end ;
if Lo <= Hi then
begin
MoveStringGridData(Grid, Lo, Hi) ;
Inc(Lo);
Dec(Hi);
end;
until Lo > Hi;
if Hi > iLo then QuickSort(Grid, iLo, Hi);
if Lo < iHi then QuickSort(Grid, Lo, iHi);
end;begin
try
QuickSort(Grid, Grid.FixedRows, Grid.RowCount - 1 ) ;
except
on E: Exception do
Application.MessageBox(Pchar('系统在排序数据的时候遇到异常:'#13+E.message+#13'请重试,如果该问题依然存在请与程序供应商联系!'),'系统错误',MB_OK+MB_ICONERROR) ;
end;
end;procedure StringGridTitleDown(Sender: TObject;Button: TMouseButton; X, Y: Integer);
(******************************************************************************)
(* 函数名称:StringGridTitleDown *)
(* 函数功能:取鼠标点StringGrid 的列 _/_/ _/_/ _/_/_/_/_/ *)
(* 参数说明: _/ _/ _/ *)
(* Sender _/ _/ *)
(* _/ _/ *)
(* _/_/ _/_/ *)
(* *)
(* *)
(* Author: YuJie 2001-05-27 *)
(* Email : [email protected] *)
(******************************************************************************)
var
I: Integer ;
begin
if (Y > 0 ) and (y < TStringGrid(Sender).DefaultRowHeight * TStringGrid(Sender).FixedRows ) then
begin
if Button = mbLeft then
begin
I := X div TStringGrid(Sender).DefaultColWidth ;
//这个i 就是要排序得行了
// 下面调用上面的排序函数就可以了,
GridQuickSort(TStringGrid(Sender), I, False, True) ;
end;
end;
end;
用上面的两个函数就能解决你的问题了。在TStringGrid 的MouseDown事件中调用
StringGridTitleDown 函数就可以。你可能要修改一下StringGridTitleDown函数
来修改排序得方式及其字符类型。
提醒你一下对于日期、时间、布尔等类型数据均可按字符方式排序。例如:
procedure TForm_Main.StringGrid1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
StringGridTitleDown(Sender,Button,X,Y);
end;
来自:久久, 时间:2001-6-18 19:02:00, ID:571876
续上我这里有Demo你要的话我可以发给你。多少分你看着给吧。
来自:dadabox, 时间:2001-6-18 19:05:00, ID:571882
久久哥,我要DEMO,请发给我。若能解决我的问题,我全部分都给你。因为上面那位还没有
将控件发给我的。
来自:duckstar, 时间:2001-6-19 8:18:00, ID:572389
控件已经发出,请查收。分我不要的,因为我也没有解决问题,如果解决
了请给我发一个DEMO,我也想知道怎样能实现。久久的函数不能解决问题吗?
我一会试试。
来自:duckstar, 时间:2001-6-19 8:32:00, ID:572402
我试了一下,程序基本能通过,功能也可以实现,但以下语句似乎要做改动:将 Grid.Cells [K,Des]:= TmpStrList.Strings[K] ;
^^^^^^^
改为 Grid.Cells [K,Des]:= TmpStrList.Strings[K-1] ;
^^^^^^^^
因为StringList默认是从Strings[0]开始的,否则可能导致
"List index out of bounds(?)"错误。
for i := 0 to TStringGrid(Sender).ColCount -1 do begin
X := X - TStringGrid(Sender).ColWidths[i];
if X <=0 then break;
end;
GridQuickSort(TStringGrid(Sender), I, False, True) ;