话题2435599的标题是: dephi7 + simpledataset + mysql +DbGridEh 怎样实现点击DbGridEh的Title时进行升序以及降序排序? (50分)
分类:数据库-C/S型 shayang (2004-02-04 14:02:00)
dephi7 + simpledataset + mysql +DbGridEh 怎样实现点击DbGridEh的Title时进行升序以及降序排序?(千万别从某处简单的找一个来,网上一般是用ado的,我这个好象不太一样)
江南大米 (2004-02-04 14:26:00)
用dxExpressDbGrid的话直接选择属性就可以排序的!
simpledataset没有用过!
shayang (2004-02-04 14:30:00)
我需要用DbGridEh里的象Excel一样可以块复制、块剪切……的功能
MYSBS (2004-02-07 8:54:00)
我这个是我自己的,不是网上的,三层。客户端ClientDataSet的排序,公用排序程序,供你参考。(在ClientDataSet的OnTitleButtonClick事件调用)
procedure TSysdb.sys_DoSorting(cdsName: TClientDataset;
AFieldName: string;
SortType: string = '');
const
NONSORTABLE: set of TFieldType = [ftBlob, ftMemo, ftOraBlob, ftOraCLob];
begin
with cdsNamedo
begin
if IsEmpty or (FieldByName(AFieldName).DataType in NONSORTABLE)
or (FieldByName(AFieldName).FieldKind <> fkData) then
Exit;
if (IndexFieldNames = AFieldName) then
begin
IndexDefs.Update;
if (SortType = '') or (SortType = 'DESC') then
begin
if IndexDefs.IndexOf('DESC') > -1 then
begin
DeleteIndex('DESC');
IndexDefs.Update;
end;
AddIndex('DESC', AFieldName, [ixDescending, ixCaseInsensitive], '', '', 0);
IndexName := 'DESC';
end
else
begin
if IndexDefs.IndexOf('ASC') > -1 then
begin
DeleteIndex('ASC');
IndexDefs.Update;
end;
AddIndex('ASC', AFieldName, [ixCaseInsensitive], '', '', 0);
IndexName := 'ASC';
end;
end
else
begin
IndexFieldNames := AFieldName;
end;
end;
end;
MYSBS (2004-02-07 8:53:00)
这个让你排序时,在Title显示向上和向下的图标。(在ClientDataSet的CalcTitleImage事件调用)
procedure TSysdb.OnCalcTitleImage(Sender: TObject;
Field: TField;
var TitleImageAttributes: TwwTitleImageAttributes);
begin
with (Sender as twwdbgrid)do
begin
TitleImageList := ImageList2;
if Field.FieldName = TClientDataset(Datasource.Dataset).indexfieldnames then
begin
TitleImageAttributes.ImageIndex := 0;
end
else
if TClientDataset(Datasource.Dataset).indexname = 'DESC' then
begin
TClientDataset(Datasource.Dataset).indexdefs.Update;
if TClientDataset(Datasource.Dataset).indexdefs.Find('DESC').Fields = Field.Fieldname then
TitleImageAttributes.ImageIndex := 1;
end;
end;
end;
shayang (2004-02-07 22:44:00)
接受答案了.
MYSBS的回答最终被接受。