VFP里的组合框为什么输入数据不能保存到表
有一个组合框 combo1的int属性的代码如下
thisform.combo1.rowsourcetype=0
thisform.combo1.additem (" ")
thisform.combo1.additem ("魏")
thisform.combo1.additem ("李")
combo1的keypress代码如下
LPARAMETERS nKeyCode, nShiftAltCtrl
if nKeyCode=13
if !empty(this.displayvalue)
this.additem(this.displayvalue)
endif
endif
Rowsource Type 6字段
手工输入到COMBO1的数据无法保存,选择的倒可以,请问怎么解决?
[解决办法]
将以下代码粘到 vfp 的 程序(Prg)中运行看一下效果吧:
Public oform1oform1=Newobject("form1")oform1.ShowReturnDefine Class form1 As Form DoCreate = .T. Caption = "Form1" Name = "Form1" Add Object combo1 As ComboBox With ; RowSourceType = 6, ; RowSource = "t1.name", ; Height = 24, ; Left = 252, ; Top = 36, ; Width = 100, ; Name = "Combo1" Add Object grid1 As Grid With ; DeleteMark = .F., ; Height = 200, ; Left = 24, ; ReadOnly = .T., ; Top = 36, ; Width = 216, ; Name = "Grid1" Procedure Load Create Cursor t1 (Name c(10)) Insert Into t1 Values ('张三') Insert Into t1 Values ('李四') Locate Endproc Procedure combo1.KeyPress Lparameters nKeyCode, nShiftAltCtrl If nKeyCode=13 If Messagebox('确认要将此内容【'+Alltrim(This.DisplayValue)+'】添加到表中吗?',4+32+256,'信息提示')=6 Insert Into t1 Values (Alltrim(This.DisplayValue)) Endif Endif EndprocEnddefine