Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Controlsource bug with combobox
Message
 
 
À
10/01/2001 11:57:37
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00461696
Message ID:
00461951
Vues:
9
If ID in the property is numeric - here is an answer. Combobox's native type is character. When it works with numeric field/property, it uses ListIndex. When it works with character control source, it uses column values. Combobox does not supports numeric values in the column, when you use table, query or alias as source of rows it converts all numeric values to character data type to show it in the combobox. To solve your problem just work with character representation of ID in the property, and convert it where needed to/from numeric.


>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
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.com
ICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs

It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform