Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Controlsource bug with combobox
Message
From
10/01/2001 11:57:37
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Title:
Controlsource bug with combobox
Miscellaneous
Thread ID:
00461696
Message ID:
00461696
Views:
38
I have a scenario where I believe VFP has a bug. I want to have a combobox that displays two columns of a table's values, the second of which is a numeric ID. I set the BoundTo to .T. in order to get the ID value instead of the list index of the selected item. However, when the controlsource is a property or memory variable instead of a field in a table or cursor, VFP does not display the selected item. It also does not walk through the items properly using the up/down arrow keys.

I wrote a form class that shows this odd functionality. I need to be able to store the value to a property in the same way it stores to a table field. Is this a bug, or a "feature"???

Here is the code to reproduce. Just copy this to a .PRG and run it. There are two buttons that toggle ControlSource and BoundTo on-the-fly and show the differences.

**************************************************
LOCAL loForm

loForm = CREATE( "frmcombotest")
loForm.Show

RETURN

**************************************************
DEFINE CLASS frmcombotest AS form
Top = 0
Left = 0
Height = 193
Width = 384
DoCreate = .T.
Caption = "Combo Test"
Name = "frmComboTest"
WindowType = 1 && Modal
nempid = .F.

ADD OBJECT cboemp AS combobox WITH ;
BoundColumn = 2, ;
BoundTo = .T., ;
ColumnCount = 2, ;
RowSourceType = 2, ;
RowSource = "employee.empname, empid", ;
Height = 25, ;
Left = 12, ;
Style = 2, ;
Top = 24, ;
Width = 156, ;
Name = "cboemp"

ADD OBJECT cmdCS AS commandbutton WITH ;
Top = 12, ;
Left = 204, ;
Height = 24, ;
Width = 156, ;
Caption = "Toggle ControlSource", ;
Name = "cmdCS"

ADD OBJECT cmdBound AS commandbutton WITH ;
Top = 36, ;
Left = 204, ;
Height = 24, ;
Width = 156, ;
Caption = "Toggle BoundTo", ;
Name = "cmdBound"

ADD OBJECT edit1 AS editbox WITH ;
Height = 108, ;
Left = 12, ;
Top = 72, ;
Width = 360, ;
Name = "Edit1"

PROCEDURE Load
CLOSE DATA ALL
CREATE CURSOR employee (empid I, empname C(20))
INSERT INTO employee (empid, empname) ;
VALUES (4, "Name4")
INSERT INTO employee (empid, empname) ;
VALUES (3, "Name3")
INSERT INTO employee (empid, empname) ;
VALUES (2, "Name2")
INSERT INTO employee (empid, empname) ;
VALUES (1, "Name1")

* ControlSource A will be a property.
THISFORM.nEmpid = 3

* ControlSource B will be a field in a cursor.
CREATE CURSOR csrEmp ( empid I)
INSERT INTO csrEmp (empid) VALUES (3)
ENDPROC


PROCEDURE Init
* Toggle the initial controlsource on.
THISFORM.cmdCS.Click
ENDPROC

PROCEDURE showprops
WITH THISFORM.cboEmp
THISFORM.Edit1.Value = ;
"BoundTo = " + IIF(.BoundTo, "True", "False") + CHR(10) + ;
"ControlSource = " + .ControlSource + CHR(10) + ;
"Listindex = " + STR(.ListIndex) + CHR(10) + ;
"DisplayValue = " + .DisplayValue + CHR(10) + ;
"Value = " + STR( .Value)
THISFORM.Edit1.Refresh
ENDWITH
ENDPROC

PROCEDURE cboemp.InteractiveChange
THISFORM.ShowProps
ENDPROC

PROCEDURE cmdCS.Click
WITH THISFORM.cboemp
IF UPPER(.ControlSource) = "THISFORM.NEMPID"
.ControlSource = "csrEmp.Empid"
ELSE
.ControlSource = "THISFORM.nEmpid"
ENDIF
THISFORM.ShowProps
ENDWITH
ENDPROC

PROCEDURE cmdBound.Click
WITH THISFORM.cboemp
.BoundTo = NOT .BoundTo
THISFORM.ShowProps
ENDWITH
ENDPROC

ENDDEFINE
Next
Reply
Map
View

Click here to load this message in the networking platform