RAD Studio VCL Reference
|
Provides indexed access to the field components that correspond to the columns.
property Fields [FieldIndex: Integer]: TField;
__property TField Fields[int FieldIndex];
Use Fields to gain direct access to the field component in the dataset for a particular column in the grid. The field for the first data column is obtained using an Index of 0, the field for the second data column using an Index of 1, and so on. The range for Index is 0... FieldCount - 1.
The first data column in the grid may not be the same as the first column in the grid. If Options includes dgIndicator, the first column in the grid is a non-scrolling column that contains the current row indicator.
The individual field components in Fields can be used to obtain information such as the value of the field on the current record, its preferred display width, or the string to draw when displaying or editing the field. Use the field component to write values directly to the dataset without using the editor in the cell.
Delphi Examples:
{ The following example copies the selected rows in a db grid to a list box. Set the db grid Options dgRowSelect, dgAlwaysShowSelection and dgMultiSelect to True. Make a multiple selecton using the CNTL key. This example requires a TDataSet associated with a TDataSource and a TDBGrid.} procedure TForm1.Button2Click(Sender: TObject); var i, j: Integer; s: string; begin if DBGrid2.SelectedRows.Count>0 then with DBGrid2.DataSource.DataSet do for i:=0 to DBGrid2.SelectedRows.Count-1 do begin GotoBookmark(DBGrid2.SelectedRows.Items[i]); for j := 0 to FieldCount-1 do begin if (j>0) then s:=s+', '; s := s + FindField(Fields.Fields[j].FieldName).AsString; end; Listbox1.Items.Add(s); s:= ''; end; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|