Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Putting a Combobox in a grid
Message
From
22/07/2000 18:37:02
 
 
To
22/07/2000 18:19:21
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
00395897
Message ID:
00395908
Views:
8
>It's telling me that I can't have nested classes in methods. Where else do I write the class? Here's my code so far:
>
>Thisform.AddObject('Combo1','GridCombo')
>
>DEFINE CLASS GridCombo AS COMBOBOX
> RowSourceType = 1
> RowSource = 'Loan,Purchase,Missing'
>
>ENDDEFINE
>
>Where do I put it?

In a VCX that's included in your SET CLASSLIB, or a separate procedure file, not part of a class, searched in your SET PROCEDURE list. It can't be defined in-line. The simple alternative would be after issuing the AddObject for the Column, you could set the properties for the control.

BTW, you don't want to issue an AddObject for the Form, you must do an AddObject() using the Column of the Grid, eg thisform.MyGrid.Column1.AddObject(blah blah blah). You're adding the Combo to the Form witht he code you show above.

Rather than doing this from scratch, if you don't understand it, why not download some of the sample classes in the Files section that implement variants of controls in Columns of Grids? Or look in the on-line help for VFP - there's sample code that demonstrates adding a ComboBox instance to a Grid in Chapter 10 of the Programmer's Guide, under the completely unlikely heading To programmatically add controls to a grid column (impossible to figure out what they're talking about from the description... < BEG >) The portion of the help file text that describes this:
To programmatically add controls to a grid column

In the Init event of the grid, use the AddObject method to add the control to the grid column and set the CurrentControl property of the column.
For example, the following lines of code in the Init event of a grid add two controls to a grid column and specify one of them as the current control:

THIS.grcColumn1.AddObject("spnQuantity", "SPINNER")
THIS.grcColumn1.AddObject("cboQuantity", "COMBOBOX")
THIS.grcColumn1.CurrentControl = "spnQuantity"
* The following lines of code make sure the control is visible
* and is diplayed in every row in the grid
THIS.grcColumn1.spnQuantity.Visible = .T.
THIS.grcColumn1.Sparse = .F.

In this example, Column1 has three possible current control values:

spnQuantity
cboQuantity
Text1 (the default control)
Note Properties set on the Grid level are not passed on to the columns or headers. In the same way, you must set properties of the headers and contained controls directly; they do not inherit their properties from settings at the Column level.

Tip For the best display of combo boxes in grid columns, set the following combo box properties:

BackStyle = 0 && Transparent
Margin = 0
SpecialEffect = 1 && Plain
BorderStyle = 0 && None


Yes, this means I recommend that you RTFM!

>
>>>If I just addobject('myobjectname', 'classname') and change currentcontrol to myobjectname, shouldn't I :
>>>
>>>1. be able to do that, and.......
>>
>>You can, but if you don't set any properties for the ComboBox to tell it at least the RowSource and RowSourceType, specify that the Sparse property is true, define the columns properly, it will not do anything. Dropping a control that requires configuration in a column doesn't do anything for you.
>>
>>>2. get a standard form of whatever classname I entered in addobject?
>>>
>>
>>Yep, you can drop an instance of any object class, either a VFP basclass or one from your own class libraries, in there, but it won't configure it. It doesn't know what behaviors to use, or any of the things that would require non-default values to be set. IOW, AddObject() places the control there, but doesn't tell it how to act. You still have to do that.
>>
>>>
>>>
>>>>>How do you replace the textbox control with a combobox control for the column of a grid?
>>>>>
>>>>
>>>>Use the Column's AddObject() method to add an instance of a ComboBox control, set the properties of the ComboBox, and then set the Column's CurrentControl property to select the ComboBox control you've added.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform