var i:Integer; begin //cbbGroup.Clear; //ADOQuery1.Close; //ADOQuery1.SQL.Clear; //ADOQuery1.SQL.Add('Select count(Name) from DSC_Vehicle');//select count(distinct 列名) from 表名 //ADOQuery1.Open; // if ADOQuery1.RecordCount>0 then // begin // for i:=0 to ADOQuery1.RecordCount-1 do // begin// cbbGroup.Items.Add(ADOQuery1.FieldByName('count GroupID').AsString); // ADOQuery1.Next; // end; // end; end; 我用的是搜索完后 一条一条的加入到 box里面
能帮我做个例子嘛?多谢拉~
设置 lookupField
是LookupDisplayFields?我已经设置了,还是不行啊。是要些代码填写picklist?
object Form1: TForm1
Left = 245
Top = 155
Width = 928
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 14
object DBGridEh1: TDBGridEh
Left = 120
Top = 64
Width = 625
Height = 297
DataSource = DataSource1
Flat = False
FooterColor = clWindow
FooterFont.Charset = DEFAULT_CHARSET
FooterFont.Color = clWindowText
FooterFont.Height = -12
FooterFont.Name = 'Tahoma'
FooterFont.Style = []
RowDetailPanel.Color = clBtnFace
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -12
TitleFont.Name = 'Tahoma'
TitleFont.Style = []
Columns = <
item
AlwaysShowEditButton = True
DropDownBox.ColumnDefValues.Title.Alignment = taCenter
DropDownBox.Columns = <
item
FieldName = #22995#21517
end
item
FieldName = #32534#21495
end>
DropDownBox.Options = [dlgColumnResizeEh, dlgColLinesEh, dlgRowLinesEh, dlgAutoSortMarkingEh, dlgMultiSortMarkingEh]
DropDownBox.UseMultiTitle = True
DropDownShowTitles = True
EditButtons = <>
FieldName = 'name'
Footers = <>
LookupDisplayFields = #22995#21517';'#32534#21495
Width = 100
end
item
EditButtons = <>
FieldName = 'id'
Footers = <>
end
item
EditButtons = <>
FieldName = #32534#21495
Footers = <>
Width = 71
end
item
EditButtons = <>
FieldName = #22995#21517
Footers = <>
Width = 54
end
item
EditButtons = <>
FieldName = #24615#21035
Footers = <>
Width = 77
end
item
EditButtons = <>
FieldName = #22791#27880
Footers = <>
Width = 96
end>
object RowDetailData: TRowDetailPanelControlEh
end
end
object ADOConnection1: TADOConnection
Connected = True
ConnectionString =
'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\'#26032#24314#25991#20214#22841' (2)\db1.md' +
'b;Persist Security Info=False'
LoginPrompt = False
Mode = cmShareDenyNone
Provider = 'Microsoft.Jet.OLEDB.4.0'
Left = 24
Top = 32
end
object ADOTable1: TADOTable
Active = True
Connection = ADOConnection1
CursorType = ctStatic
TableName = 'ryb'
Left = 24
Top = 64
object ADOTable1id: TAutoIncField
FieldName = 'id'
ReadOnly = True
end
object ADOTable1DSDesigner: TWideStringField
FieldName = #32534#21495
Size = 50
end
object ADOTable1DSDesigner2: TWideStringField
FieldName = #22995#21517
Size = 50
end
object ADOTable1DSDesigner3: TWideStringField
FieldName = #24615#21035
Size = 50
end
object ADOTable1DSDesigner4: TWideStringField
FieldName = #22791#27880
Size = 50
end
object ADOTable1name: TStringField
FieldKind = fkLookup
FieldName = 'name'
LookupDataSet = ADOTable2
LookupKeyFields = #22995#21517
LookupResultField = #22995#21517
KeyFields = #22995#21517
Size = 100
Lookup = True
end
end
object ADOTable2: TADOTable
Active = True
Connection = ADOConnection1
CursorType = ctStatic
TableName = 'ryb'
Left = 24
Top = 96
end
object DataSource1: TDataSource
DataSet = ADOTable1
Left = 48
Top = 64
end
object DataSource2: TDataSource
DataSet = ADOTable2
Left = 56
Top = 104
end
end
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, GridsEh, DBGridEh, DB, ADODB;type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
ADOTable2: TADOTable;
DataSource1: TDataSource;
DataSource2: TDataSource;
ADOTable1id: TAutoIncField;
ADOTable1DSDesigner: TWideStringField;
ADOTable1DSDesigner2: TWideStringField;
ADOTable1DSDesigner3: TWideStringField;
ADOTable1DSDesigner4: TWideStringField;
ADOTable1name: TStringField;
DBGridEh1: TDBGridEh;
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}end.
表名:RYB
字段:
id:自动编号
编号:文本,50
姓名:文本,50
性别:文本,50
备注:文本,50
i:Integer;
begin
//cbbGroup.Clear;
//ADOQuery1.Close;
//ADOQuery1.SQL.Clear;
//ADOQuery1.SQL.Add('Select count(Name) from DSC_Vehicle');//select count(distinct 列名) from 表名
//ADOQuery1.Open;
// if ADOQuery1.RecordCount>0 then
// begin
// for i:=0 to ADOQuery1.RecordCount-1 do
// begin// cbbGroup.Items.Add(ADOQuery1.FieldByName('count GroupID').AsString);
// ADOQuery1.Next;
// end; // end;
end;
我用的是搜索完后 一条一条的加入到 box里面
它在Query1中,VName字段增加了VName1的查找字段,这个字段从qrVendors查找相关的数据
在DBGridEh1中使用VName1,这样显示就是那种效果了你打开例子,双击DBGridEh1对应的Query1看看它是怎么设置的
默认的是显示1列,要显示多少列就在DBGridEh1的VName1字段,设置LookupDisPlayFields属性,用分号;隔开