Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Big problem, please help!
Message
From
20/04/1998 12:22:52
 
 
To
18/04/1998 20:23:38
Raul Davila
Davila Programming Services
Toa Alta, Puerto Rico
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00093210
Message ID:
00093430
Views:
26
Yes, this is a common problem. It's pretty easy to deal with, however. Here's the theory of how to deal with it: The list sychs correctly if it the control source is of character type instead of numeric. And if you are bound to a numeric key field, it will return the proper character value, say "5" instead of returning the list value 4 to a numeric variable. Therefore the solution is to create a new class of combo boxes with a character value for the controlsource. The combo class then converts the value to numeric and saves that value to your variable or parent table key field. Here's all the code I use:

1. Subclass your basic combo box to class cboNumber.
2. Add the following methods and properties:


Property Initial Value
-------- -------------
r_cControlSource {None}
r_cNumVal {None}
r_lVariable .F.

Method: m_ChangeValue


3. Set the ControlSource property to: This.r_cNumVal

4. Add the following code to methods:

* Refresh Method:
This.r_cNumVal = Alltrim(Str(Eval(This.r_cControlSource)))

* Valid Method
IF Eval(This.r_cControlSource) # Val(This.r_cNumVal)
=This.m_ChangeValue(Val(This.r_cNumVal))
ENDIF

* m_changevalue Change the value of a field or variable
* named in .r_cControlSource
* ANW 12/97
Parameter p_xNewValue
Local l_c
If This.r_lVariable
l_c = This.r_cControlSource
&l_c = p_xNewValue && It's a variable
ELSE
l_c = This.r_cControlSource
IF AT('.',l_c) > 0
l_c = "REPLACE " + Right(l_c,len(l_c)-at('.',l_c))+ ;
" WITH p_xNewValue" + ' IN ' + left(l_c,at('.',l_c)-1)
&l_c
ELSE
REPLACE (This.r_cControlSource) WITH p_xNewValue
ENDIF
ENDIF

5. Implementation: Replace all your combo boxes which have these key values with a combobox of class cboNumber. Set your properties just like you usually would:
BoundColumn, RowSource, RowSourceType, ColumnWidths. But DO NOT change the ControlSource property. Instead, change r_cControlSource. Also, if
r_cControlSource is a variable, not a field value, set Combo.r_lValiable to .T.

The only problem you have to worry about now is that this solution doesn't work well in a grid. I have a grid solution but it is less elegant. Also, you could probably figure out a way to determine whether r_cControlSource is a field or a variable without an explicit reference like that. But I leave that to sharper minds.

Adam
Previous
Reply
Map
View

Click here to load this message in the networking platform