【问题标题】:Adding Items in ListView RAD Studio Delphi 10.2在 ListView RAD Studio Delphi 10.2 中添加项目
【发布时间】:2017-09-12 17:20:59
【问题描述】:

我想显示一个带有TListView 的列表,它是由我的数据库中的数据生成的。 但我的代码只显示列表中的一项。

它应该看起来像一个简短的列表,其中包含 Adress、Name1、Name1 等文本,就像这张图片一样:

图片视图的代码:

procedure TForm2.RefreshButton1Click(Sender: TObject); 
var
 queryListClient : TFDQuery;
 ItemAdd : TListViewItem;
begin
  queryListClient := TFDQuery.Create(Nil);
  queryListClient.Connection := FDConnection1;

  queryListClient.SQL.Clear;
  queryListClient.SQL.Add('Select * from Projekt ORDER by ProjNr');
  queryListClient.Open();
  queryListClient.First;

  List_Clients1.Items.Clear;
  List_Clients1.BeginUpdate;
  while Not queryListClient.Eof do
  begin
    ItemAdd := List_Clients1.Items.Add;
    ItemAdd.Text := queryListClient.FieldByName('Name1').AsString;
    ItemAdd.Detail := queryListClient.FieldByName('Name2').AsString;
    queryListClient.Next;
  end;
  List_Clients1.EndUpdate;
  queryListClient.Close;
  queryListClient.Free;
end;

现在的样子:

【问题讨论】:

  • 除了代码中的其他问题外,发生这种情况的唯一原因是该查询真的只返回一条记录。当您使用查询工具直接在数据库上执行它时会发生什么?这张表中真的有不止一条记录吗?
  • 参见\Users\Public\Documents\Embarcadero\Studio\19.0\Samples\Object Pascal\Multi-Device Samples\User Interface\ListView\ListViewMultiDetailAppearance\ListViewMultiDetailAppearance.dproj 演示。
  • 顺便问一下,您想回答哪个问题?如何将您的控件设置为看起来像第一个屏幕截图?或者为什么您的列表中只有一项?
  • 或者,如果您想要一个细节(图片显示多个)作为您的代码尝试添加,请关注\Users\Public\Documents\Embarcadero\Studio\19.0\Samples\Object Pascal\Multi-Device Samples\User Interface\ListView\ListViewCustomBottomDetail\SampleListViewCustomBottomDetailProject.dproj demo。

标签: listview delphi firemonkey items


【解决方案1】:

您可能没有将 listview SYNC 属性链接到您的数据集(LiveBindings Designer)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-05
    • 2013-05-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多