Delphi7 TMS TDBAdvGrid 单击列标题时对数据进行排序
我是 Delphi 的新手,我需要建议。
我正在使用 TMS TDBAdvGrid,当用户单击列标题时,我需要对数据进行排序。我设置了网格的排序设置,并为 onclicksort 事件编写了代码,但它不起作用。
网格的排序设置:
SortSettings.Show = True;
SortSettings.IgnoreBlanks = True;
SortSettings.BlankPos = blLast;
onclicksort事件:
try
try
if FSortISWorking then
Exit;
FSortISWorking := true;
if ACol < 0 then
begin
grid.BeginUpdate;
grid.SortSettings.Column := ACol;
Application.ProcessMessages;
grid.QSort;
grid.EndUpdate;
end;
except on e: Exception do
begin
// log the error
end;
end;
finally
FSortISWorking := false;
end;
网格不直接链接到数据库。数据被加载到内存(TClientDataSet)中,我只需要在内存中对数据进行排序,而不需要再次查询数据库。
谢谢
I'm a newbie into Delphi and i need an advice.
I'm using a TMS TDBAdvGrid and i need to sort the data when the user is clicking the header of a column. I setup the sort settings of the grid and i write code for the onclicksort event, but it is not working.
The sort settings of the grid:
SortSettings.Show = True;
SortSettings.IgnoreBlanks = True;
SortSettings.BlankPos = blLast;
the onclicksort event:
try
try
if FSortISWorking then
Exit;
FSortISWorking := true;
if ACol < 0 then
begin
grid.BeginUpdate;
grid.SortSettings.Column := ACol;
Application.ProcessMessages;
grid.QSort;
grid.EndUpdate;
end;
except on e: Exception do
begin
// log the error
end;
end;
finally
FSortISWorking := false;
end;
The grid is not linked directly to the database. The data is loaded into memory (TClientDataSet) and i need to sort the data only in memory, without another query to the database.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我尝试了你的例子,这为我解决了这个问题:
I tried your example and this solved the issue for me:
为了解决此问题,您必须对网格后面的数据集进行排序。这里有一般如何执行此操作的信息:http://delphi.about.com/od/usedbvcl/l/aa042203a.htm。
下面有一个示例:
如果您想在此处订购 clientdataset,您可以这样做:
http:// edn.embarcadero.com/article/29056
致以诚挚的问候,
拉杜
In order to resolve this problem you must order the dataset behind your grid. here you have how to do this in general:http://delphi.about.com/od/usedbvcl/l/aa042203a.htm.
bellow you have an example:
if you want to order your clientdataset here you have how to do it:
http://edn.embarcadero.com/article/29056
best regards,
Radu