views:

244

answers:

1

hello all Friends..........

how to insert data Db Grid to TlistItem with Delphi?

thanks for help?????????

+2  A: 

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;
Robert Love