参考:http://community.csdn.net/Expert/TopicView.asp?id=3517180500分求答案!!不够再加!!!(每次只能给100分,分期付款!)
内容如题!
内容如题!
解决方案 »
- 这样的价格体系该如何设置?
- idhttp 提交asp.net 的问题 急在线等
- 熟悉IXMLDOMDocument的朋友,新增节点,怎样让节点自动换行????
- 怎么把一个类转化为COM并测试?有这方面的书推存吗?
- 错误处理程序如何再返回到程序中
- 怎么调用现成的PAS文件中的函数???
- 求简化代码和处理异常的几条note
- 哪里有boundchecker for delphi 版的下载
- Delphi中DLL调用后如何完全释放?
- 如何给时间附值
- StringGrid有不有属性可以让它自己根据显示的内容调整RowCount呀
- Delphi 中使用 windows SDK 中的IPHelper 的问题?
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if (gdFocused in State) then
begin
if (DBGrid1.SelectedField.FieldName = DBComboBox1.DataField ) then
begin
DBComboBox1.Left := Rect.Left + DBGrid1.Left;
DBComboBox1.Top := Rect.Top + DBGrid1.top;
DBComboBox1.Width := Rect.Right - Rect.Left;
DBComboBox1.Height := Rect.Bottom - Rect.Top;
DBComboBox1.Visible := True;
end;
end;
end;procedure TForm1.DBGrid1ColEnter(Sender: TObject);
begin
If DBGrid1.SelectedField.FieldName <> DBComboBox1.DataField then
begin
DBComboBox1.Visible := false;
end;
1、设置数据集对应列为fkLookup,以及Lookup的相关属性
FieldKind = fkLookup{*************************}
FieldName = 'VName1'{*************************}
LookupDataSet = Query2{*************************}
LookupKeyFields = 'VendorNo'{*************************}
LookupResultField = 'VendorName'{*************************}
KeyFields = 'VNo'{*************************}
2、确保该列可读写
3、设置EhLib对应列
AlwaysShowEditButton = True{*************************}
DropDownShowTitles = True{*************************}
LookupDisplayFields = 'VendorName;City;State'{*************************}
OK下面是示例
object Form1: TForm1
Left = 192
Top = 107
Width = 783
Height = 540
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object DBGridEh1: TDBGridEh
Left = 16
Top = -192
Width = 401
Height = 697
DataSource = DataSource1
FooterColor = clWindow
FooterFont.Charset = DEFAULT_CHARSET
FooterFont.Color = clWindowText
FooterFont.Height = -11
FooterFont.Name = 'MS Sans Serif'
FooterFont.Style = []
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
Columns = <
item
EditButtons = <>
FieldName = 'VNo'
Footers = <>
end
item
AlwaysShowEditButton = True{*************************}
DropDownShowTitles = True{*************************}
DropDownWidth = -1
EditButtons = <>
FieldName = 'VName1'
Footers = <>
LookupDisplayFields = 'VendorName;City;State'{*************************}
end
item
EditButtons = <>
FieldName = 'VPreferred'
Footers = <>
end
item
EditButtons = <>
FieldName = 'PNo'
Footers = <>
end
item
EditButtons = <>
FieldName = 'PDescription'
Footers = <>
end
item
EditButtons = <>
FieldName = 'PCost'
Footers = <>
end
item
EditButtons = <>
FieldName = 'IQty'
Footers = <>
end>
end
object Query1: TQuery
Active = True
CachedUpdates = True{*************************}
DatabaseName = 'DBDEMOS'
RequestLive = True
SQL.Strings = (
'SELECT'
' Vendors.VendorNo VNo,'
' Vendors.VendorName VName,'
' Vendors.Preferred VPreferred,'
' Parts.PartNo PNo,'
' Parts.Description PDescription,'
' Parts.Cost PCost,'
' Items.Qty IQty'
''
'FROM Vendors, Parts, Items'
'WHERE Vendors.VendorNo = Parts.VendorNo AND'
' Parts.PartNo = Items.PartNo'
'ORDER BY Items.Qty, Parts.Cost')
UpdateObject = UpdateSQL1
Left = 112
Top = 40
object Query1VNo: TFloatField
CustomConstraint = '(VNo > 1000) and (VNo < 9999)'
ConstraintErrorMessage = 'Vendor No has to be between 1000 and 9999'
FieldName = 'VNo'
Origin = 'DBDEMOS."Vendors.DB".VendorNo'
DisplayFormat = 'VN 0000'
MaxValue = 9999.000000000000000000
MinValue = 1000.000000000000000000
end
object Query1VName: TStringField
FieldName = 'VName'
LookupDataSet = Query2
Origin = 'DBDEMOS."Vendors.DB".VendorName'
Size = 30
end
object Query1VPreferred: TBooleanField
FieldName = 'VPreferred'
Origin = 'DBDEMOS."Vendors.DB".Preferred'
end
object Query1PNo: TFloatField
Alignment = taLeftJustify
FieldName = 'PNo'
Origin = 'DBDEMOS."parts.DB".PartNo'
DisplayFormat = 'PN-00000'
end
object Query1PDescription: TStringField
FieldName = 'PDescription'
Origin = 'DBDEMOS."parts.DB".Description'
Size = 30
end
object Query1PCost: TCurrencyField
FieldName = 'PCost'
Origin = 'DBDEMOS."parts.DB".Cost'
end
object Query1IQty: TIntegerField
FieldName = 'IQty'
Origin = 'DBDEMOS."items.DB".Qty'
end
object Query1VName1: TStringField
FieldKind = fkLookup{*************************}
FieldName = 'VName1'{*************************}
LookupDataSet = Query2{*************************}
LookupKeyFields = 'VendorNo'{*************************}
LookupResultField = 'VendorName'{*************************}
KeyFields = 'VNo'{*************************}
Lookup = True
end
end
object Query2: TQuery
Active = True
DatabaseName = 'DBDEMOS'
SQL.Strings = (
'select * from Vendors'
'order by VendorName')
Left = 120
Top = 128
object Query2VendorNo: TFloatField
CustomConstraint = '(VendorNo > 1000) and (VendorNo < 9999)'
ConstraintErrorMessage = 'Vendor No has to be between 1000 and 9999'
FieldName = 'VendorNo'
Origin = 'DBDEMOS."Vendors.DB".VendorNo'
DisplayFormat = 'VN 0000'
MaxValue = 9999.000000000000000000
MinValue = 1000.000000000000000000
end
object Query2VendorName: TStringField
FieldName = 'VendorName'
Origin = 'DBDEMOS."Vendors.DB".VendorName'
Size = 30
end
object Query2Address1: TStringField
FieldName = 'Address1'
Origin = 'DBDEMOS."Vendors.DB".Address1'
Size = 30
end
object Query2Address2: TStringField
FieldName = 'Address2'
Origin = 'DBDEMOS."Vendors.DB".Address2'
Size = 30
end
object Query2City: TStringField
FieldName = 'City'
Origin = 'DBDEMOS."Vendors.DB".City'
end
object Query2State: TStringField
FieldName = 'State'
Origin = 'DBDEMOS."Vendors.DB".State'
end
object Query2Zip: TStringField
FieldName = 'Zip'
Origin = 'DBDEMOS."Vendors.DB".Zip'
Size = 10
end
object Query2Country: TStringField
FieldName = 'Country'
Origin = 'DBDEMOS."Vendors.DB".Country'
Size = 15
end
object Query2Phone: TStringField
FieldName = 'Phone'
Origin = 'DBDEMOS."Vendors.DB".Phone'
Size = 15
end
object Query2FAX: TStringField
FieldName = 'FAX'
Origin = 'DBDEMOS."Vendors.DB".FAX'
Size = 15
end
object Query2Preferred: TBooleanField
FieldName = 'Preferred'
Origin = 'DBDEMOS."Vendors.DB".Preferred'
end
end
object DataSource1: TDataSource
DataSet = Query1
Left = 200
Top = 40
end
object DataSource2: TDataSource
DataSet = Query2
Left = 208
Top = 136
end
object UpdateSQL1: TUpdateSQL
Left = 240
Top = 136
end
end
-------------
仓库编码 仓库名称 描述
1 1#仓库 汽车站后
2 2#仓库 迎宾路旁我的LookupKeyFields是仓库编码,LookupResultField是仓库名称,但是怎么选择后,还是显示仓库编码而不是仓库名称呢?我找不到问题所在。用DBLookUpComboBoxEh这样设置的话有个ListFieldIndex属性的,可以设置为0~xxx,分别对应不同的字段名。而这个地方没有这个属性~~帮忙看看怎么回事,大奖近在眼前了啊~~
然后在LookupDisplayFields 属性了用';'分隔,加入需要的字段就可以了吧
我都是这样用的
BDE中的TQuery默认是只读的。
你可以用其他数据集试试,如TClientDataSet。我用DBExpress做了一个例子,也是由于该列数据无法编辑而没有出现下拉的倒三角!
CachedUpdates = True{*************************}
DatabaseName = 'DBDEMOS'
RequestLive = True{*************************}
SQL.Strings = (
'SELECT'
' Vendors.VendorNo VNo,'
' Vendors.VendorName VName,'
' Vendors.Preferred VPreferred,'
' Parts.PartNo PNo,'
' Parts.Description PDescription,'
' Parts.Cost PCost,'
' Items.Qty IQty'
''
'FROM Vendors, Parts, Items'
'WHERE Vendors.VendorNo = Parts.VendorNo AND'
' Parts.PartNo = Items.PartNo'
'ORDER BY Items.Qty, Parts.Cost')
UpdateObject = UpdateSQL1{*************************}