开发者

Insert data DBGrid to TlistItem

开发者 https://www.devze.com 2022-12-08 13:07 出处:网络
How do I insert data DbGrid to TlistItem开发者_JAVA技巧 with Delphi?Data in a TdbGrid can can only be stored in a TDataSet decendant.So I suspect what your asking is how to get the information in a TD

How do I insert data DbGrid to TlistItem开发者_JAVA技巧 with Delphi?


Data in a TdbGrid can can only be stored in a TDataSet decendant. So I suspect what your asking is how to get the information in a TDataset into a TListView.

Basically this could be done with the following code.

procedure TForm13.DisplayData(Dataset: TDataSet; ListView: TListView);
var
 LI : TListItem;
 CO : TListColumn;
 I : Integer;
begin
  // Setup the Columns
  ListView.ViewStyle := vsReport;
  ListView.Columns.Clear;
  for I := 1 to DataSet.Fields.Count do
  begin
     CO := ListView.Columns.Add;
     CO.Caption := Dataset.Fields.FieldByNumber(I).DisplayLabel;
     Co.AutoSize := true;
  end;

  // Populate The Data
  Dataset.First;
  while not DataSet.EOF do
  begin
    LI := ListView.Items.Add;
    LI.Caption := Dataset.Fields.FieldByNumber(1).AsString;
    for I := 2 to DataSet.Fields.Count do
    begin
      LI.SubItems.Add(Dataset.Fields.FieldByNumber(I).AsString);
   end;
   DataSet.Next;
  end;
end;
0

精彩评论

暂无评论...
验证码 换一张
取 消