急需按网格任意列排序的dbgrid第三方控件,请帮忙!!!!!!!!(50分)

  • 主题发起人 主题发起人 ddynet
  • 开始时间 开始时间
D

ddynet

Unregistered / Unconfirmed
GUEST, unregistred user!
急需按网格任意列排序的dbgrid第三方控件,请帮忙!!!!!!!!急需按网格任意列排序的dbgrid第三方控件,请帮忙!!!!!!!!
 
在 DBGRid 的 OnTitleClick 事件中改变相应数据集的 IndexFieldName 也可以实现
 
同意jsxjd的说法,排序不是DBGrid一类控件的事,但是可以用它的列头点击事件,让DATASET相应的列排序
如果不是用绑定的控件,Grid一类的控件才有可能提供排序的功能
Ehlib不错,可以在点击后显示向上向下的箭头(别告诉我说DBGrid也有,我从未用过原生的DBGrid,呵呵)
 
不要写代码的,vc中就可以嘛。谁有什么控件?????
 
哈哈,我刚解决这个问题,给全分啊:
procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var desf:String; i:integer;
begin
with ClientDataSet1.IndexDefs do
begin
i:=ClientDataSet1.IndexDefs.IndexOf('dataset_index');
if i>=0 then
if ClientDataSet1.IndexDefs.Items.Fields=Column.FieldName then
if ClientDataSet1.IndexDefs.Items.DescFields='' then
desf:=Column.FieldName;
Clear;
with AddIndexDef do
begin
Name:='dataset_index';
Fields:=Column.FieldName;
DescFields:=desf;
end;
end;

if ClientDataSet1.IndexName='dataset_index' then
ClientDataSet1.DeleteIndex('dataset_index');
ClientDataSet1.IndexName:='dataset_index';

end;
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var i:integer;
begin
{ if (DataCol=0)and(DBGrid1.DataSource.DataSet.recno>0) then
DBGrid1.Canvas.TextRect(Rect,Rect.Left+1,Rect.Top+1,IntToStr(DBGrid1.DataSource.DataSet.recno))
else
DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);}
DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
i:=ClientDataSet1.IndexDefs.IndexOf('dataset_index');
if i>=0 then
if ClientDataSet1.IndexDefs.Items.Fields=Column.FieldName then
if ClientDataSet1.IndexDefs.Items.DescFields='' then //升序
begin
DBGrid1.Canvas.Pen.Color:=clBlue;
DBGrid1.Canvas.Pen.Width:=3;
DBGrid1.Canvas.MoveTo(Rect.Right-15,1);
DBGrid1.Canvas.LineTo(Rect.Right-15,15);
DBGrid1.Canvas.MoveTo(Rect.Right-15,1);
DBGrid1.Canvas.LineTo(Rect.Right-10,5);
DBGrid1.Canvas.MoveTo(Rect.Right-15,1);
DBGrid1.Canvas.LineTo(Rect.Right-20,5);
end else
begin //降序
DBGrid1.Canvas.Pen.Color:=clBlue;
DBGrid1.Canvas.Pen.Width:=3;
DBGrid1.Canvas.MoveTo(Rect.Right-15,1);
DBGrid1.Canvas.LineTo(Rect.Right-15,15);
DBGrid1.Canvas.MoveTo(Rect.Right-15,15);
DBGrid1.Canvas.LineTo(Rect.Right-10,10);
DBGrid1.Canvas.MoveTo(Rect.Right-15,15);
DBGrid1.Canvas.LineTo(Rect.Right-20,10);
end;
end;

 
给分吧,保证对
Ehlib 窑洞有下载
在OnSortMarkingChanged事件中调用 dbgsort(TDBGridEh(sender));

ADOSort:
procedure dbgSort(var dbg: TDBGridEh);
var
i: Integer;
s: string;
begin
if not dbg.DataSource.DataSet.Active then exit;
s := '';
for i := 0 to dbg.SortMarkedColumns.Count - 1 do
begin
if dbg.SortMarkedColumns.Title.SortMarker = smUpEh then
begin
if
TADOQuery(dbg.DataSource.DataSet).FieldByName(dbg.SortMarkedColumns
.FieldName).KeyFields = '' then
s := s + dbg.SortMarkedColumns.FieldName + ' DESC,'
else
s := s + TADOQuery(dbg.DataSource.DataSet).FieldByName
(dbg.SortMarkedColumns.FieldName).KeyFields + ' DESC,';
end
else
begin
if
TADOQuery(dbg.DataSource.DataSet).FieldByName(dbg.SortMarkedColumns
.FieldName).KeyFields = '' then
s := s + dbg.SortMarkedColumns.FieldName + ' ASC,'
else
s := s + TADOQuery(dbg.DataSource.DataSet).FieldByName
(dbg.SortMarkedColumns.FieldName).KeyFields + ' ASC,';
end;
end;
if s = '' then exit;
delete(s, length(s), 1);
TADOQuery(dbg.DataSource.DataSet).Sort := s;
end;
OracleSort:用ODAC控件
procedure DBGSort(var dbg: TDBGridEh);
var
i, j: Integer;
s: string;
qr: TOraQuery;
begin
qr := TOraQuery(dbg.DataSource.DataSet);
if not qr.Active then exit;
s := '';
for i := 0 to dbg.SortMarkedColumns.Count - 1 do
if dbg.SortMarkedColumns.Title.SortMarker = smUpEh then
s := s + dbg.SortMarkedColumns.FieldName + ' DESC , '
else
s := s + dbg.SortMarkedColumns.FieldName + ', ';

if s <> '' then s := ' ORDER BY ' + Copy(s, 1, Length(s) - 2);

j:=0;
for i := 0 to qr.SQL.Count - 1 do
begin
j := pos('ORDER BY', uppercase(qr.SQL.Strings));
if j > 0 then break;
end;
if j > 0 then
qr.SQL.Strings := copy(qr.SQL.Strings, 1, j - 1) + s
else
qr.SQL.Strings := qr.SQL.Strings + s;
qr.Close;
qr.Open;
end;

 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部