DbgridEh 对应数据集ADOTable1,其中有个字段 部门编码,另外增加查找字段比如 部门名称

ADOTable2对应查找数据集,包含 部门编码和 部门名称字段。

ADOTable1 打开后,再运行

ADOTable2.Close;

ADOTable2.Open;

后记录不是在第一个,需要再

ADOTable2.First;

否则 ADOTable2.Eof 为 true

如果ADOTable1对应的是普通的DBGRID,则不需要 ADOTable2.First;

奇怪了。

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DBGridEhGrouping, ToolCtrlsEh, DBGridEhToolCtrls, DynVarsEh, DB,
ADODB, EhLibVCL, GridsEh, DBAxisGridsEh, DBGridEh, StdCtrls, Grids, DBGrids; type
TForm1 = class(TForm)
DBGridEh1: TDBGridEh;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
ADOTable2: TADOTable;
DataSource1: TDataSource;
DataSource2: TDataSource;
ADOTable1name: TWideStringField;
ADOTable1bmid: TIntegerField;
ADOTable1bmname: TStringField;
Button1: TButton;
DBGrid1: TDBGrid;
DBGrid2: TDBGrid;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject);
begin
ADOTable2.Close;
ADOTable2.Open;
if ADOTable2.Eof then
ShowMessage('Eof')
else
ShowMessage('Not Eof')
end; procedure TForm1.FormCreate(Sender: TObject);
begin
ADOTable1.Open;
end; end.
object Form1: TForm1
Left =
Top =
Caption = 'Form1'
ClientHeight =
ClientWidth =
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch =
TextHeight =
object DBGridEh1: TDBGridEh
Left =
Top =
Width =
Height =
DataSource = DataSource1
DynProps = <>
IndicatorOptions = [gioShowRowIndicatorEh]
TabOrder =
object RowDetailData: TRowDetailPanelControlEh
end
end
object Button1: TButton
Left =
Top =
Width =
Height =
Caption = 'Button1'
TabOrder =
OnClick = Button1Click
end
object DBGrid1: TDBGrid
Left =
Top =
Width =
Height =
DataSource = DataSource2
TabOrder =
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -
TitleFont.Name = 'Tahoma'
TitleFont.Style = []
end
object DBGrid2: TDBGrid
Left =
Top =
Width =
Height =
DataSource = DataSource1
TabOrder =
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -
TitleFont.Name = 'Tahoma'
TitleFont.Style = []
end
object ADOConnection1: TADOConnection
Connected = True
ConnectionString =
'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\XE Projects\Ehli' +
'b\Debug\Win32\db1.mdb;Persist Security Info=False'
LoginPrompt = False
Mode = cmShareDenyNone
Provider = 'Microsoft.Jet.OLEDB.4.0'
Left =
Top =
end
object ADOTable1: TADOTable
Connection = ADOConnection1
CursorType = ctStatic
TableName = 'person'
Left =
Top =
object ADOTable1name: TWideStringField
FieldName = 'name'
Size =
end
object ADOTable1bmid: TIntegerField
FieldName = 'bmid'
end
object ADOTable1bmname: TStringField
FieldKind = fkLookup
FieldName = 'bmname'
LookupDataSet = ADOTable2
LookupKeyFields = 'bmid'
LookupResultField = 'bmname'
KeyFields = 'bmid'
Lookup = True
end
end
object ADOTable2: TADOTable
Connection = ADOConnection1
CursorType = ctStatic
TableName = 'bm'
Left =
Top =
end
object DataSource1: TDataSource
DataSet = ADOTable1
Left =
Top =
end
object DataSource2: TDataSource
DataSet = ADOTable2
Left =
Top =
end
end
04-23 23:57