Insert data DBGrid to TlistItem
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;
精彩评论