【问题标题】:Tlistview - There is any component like Tlistview but with DB access?Tlistview - 有没有像 Tlistview 这样的组件但具有数据库访问权限?
【发布时间】:2013-05-16 14:06:55
【问题描述】:

我一直在尝试做一个有创意的东西来避免dbgrids,我找到了Tlistview(使用来自alphaskinstslistview的那个),这似乎是一个不错的方法!

问题是,我不想在每个tlistview 上编写事件onclick 以根据我在tlistview 上选择的项目定位record/dataset .. 我正在这样做tlistview item's caption.. 可能有相同名称的记录

这是我要避免的代码之一:

with q_find_process do
begin
  close;
  sql.Clear;
  sql.Add('Select * from t_process where process_name like '+quotedstr(streeview1.Selected.Text)+');
  open;
end;

不,我不想将记录的 ID 放在项目标题上..!

有什么想法吗?

有没有人知道显示大量记录的其他方式,而不仅仅是文本文本和更多文本?我不知道工具面板上的所有组件,也许有人可以给我推荐其他的..

【问题讨论】:

标签: delphi records dbgrid tlistview


【解决方案1】:

我有时会使用从数据库表中加载的列表视图 - 仅用于少量数据。我不明白你的意思 我不想在每个 tlistview 上编写事件 onclick 以根据我在 tlistview 上选择的项目定位记录/数据集,所以我要去向你展示我是如何解决这个问题的。

基本上,我创建了一个包含每条记录的主键的子项。所有的用户界面代码都使用了两个列表视图,最后更新了数据库。在加载和存储之间没有与数据库的交互(这可能是我避免你的“点击”问题的地方)。每个字段的宽度在 Object Inspector 中设置;最终子项的宽度为 0(即不显示)。

加载列表视图:

 srclist.items.clear;
 with qSrcList do
  begin
   close;
   params[0].asdate:= dt;  // use date of deposit
   open;
   while not eof do
    begin
     ListItem:= srclist.Items.Add;
     ListItem.Caption:= fieldbyname ('kabnum').asstring;
     ListItem.SubItems.Add (fieldbyname ('price').asstring);
     ListItem.SubItems.Add (fieldbyname ('duedate').asstring);
     ListItem.SubItems.Add (fieldbyname ('docket').asstring);
     ListItem.SubItems.Add (fieldbyname ('id').asstring);
     next
    end;
   close
  end;

保存数据:

 with dstlist do
  for index:= 1 to items.count do
   with qInsert do
    begin
     dstlist.itemindex:= index - 1;
     lvitem:= dstlist.selected;
     parambyname ('p1').asinteger:= deposit;
     parambyname ('p2').asinteger:= strtoint (lvitem.SubItems[3]);
     parambyname ('p3').asfloat:= strtofloat (lvitem.SubItems[0]);
     execsql;
    end;

我希望这对您有所帮助。这段代码的上下文(不是很重要)是在一个金融应用程序中,用户希望用支票填充银行存款表格。 SrcList 保存尚未存入的支票(每个给定日期只有几张),DstList 保存已连接到给定存款表格的支票。

【讨论】:

  • 好吧,我接受了它,因为“lvitem.SubItems[3]”可以用来保存 ID 并被隐藏(至少使用 viewstyle=vsIcon),所以它是一个不错的方法。我说我不想做“onclick on each tlistview”,因为我想要一个像 DBgrid 这样的控件,当我们单击记录时,dbgrid 本身会定位数据集,但是我仍然需要编码每个 tlistview 上的事件 :),但现在同名记录没有问题了!谢谢!
  • @FlávioGameiro:在我的程序中,viewstyle 是 vsReport。如果您右键单击列表视图,您可以定义列——它们的标题和宽度。 “subitems[3]”列的宽度为 0,因此是不可见的。
猜你喜欢
  • 2013-06-28
  • 1970-01-01
  • 2013-08-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多