Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spinner,character field in grid

Status
Not open for further replies.

Gotheallblacks

Programmer
Oct 16, 2003
60
NZ
I have a character field as controlsource in a grid column with currently two dynamiccurrentcontrols set to either textbox or combobox. My question is I want to add a spinner dynamiccurrentcontrol as an option if the field is numeric.But i get an error of course for invalid type. The table also contains fields for Type(ie Y for y/n, N for Numeric input or C for character input),highvalue field and lowvalue field. I have thought of either another column containing the spinner (arrows) to increment textbox or creating a container class containing spinner.
What would be the best option or is there another better way
 
But i get an error of course for invalid type.

I'm not sure it is so obvious from your post why you would of course get an invalid type using a spinner with a numeric field datatype as it's controlsource. Could you explain further? Even a combobox or textbox would not as a matter of course give you an invalid type (type mismatch) error.

boyd.gif

 
Thanks for replying so quick .As stated above "Character field" as controlsource.But want to also use a spinner to increment if there is 'Numeric'. Ie the character field is used to also store character type as well as numeric.
 
Can you give some examples of a sample set of data such as:

"ABC121"
"GFE122"
"RST123"

...or...

"ABC"
"123"
"GFE"
"124"

...or...

"1.51"
"2.52"
"3.53"

...and how exactly you are expecting the spinner to behave given the data? The more information you can provide, the better chance that a solution will be proposed that will meet your needs. Providing advise as to the best way to proceed is sometimes difficult if certain key pieces of information are missing. It may just be a matter of creating your own spinner subclass with the ability to handle the character to numeric conversion of the data source on the fly. Or it maybe that a textbox needs to be used with a spinner sitting just to the right of it in a container would be the best way to go, but without some idea of the data it will be designed to handle and the way in which it will manipulate that data it is very difficult to help.

boyd.gif

 
Craig,Sorry if I didnt explain clearly.
The table has
Product c(15), Question c(50), def_answer c(20), Answer_type c(1), Answer c(30), Highvalue n(10), Lowvalue n(10)

The grid has three columns with grid.source(s) set to 'Question','def_answer','Answer' with only Answer enabled for data entry.
data for Answer could be
'Y'
'N'
'Midnight Blue'
'Alpha green'
'56'
'12'
'Left side'
'Back'

Answer_type determines the DynamicCurrentcontrol to use for
Answer.

if Answer_type='Y' use combo set with 'Y'and 'N'
if Answer_type='R' use combo with colour options
if Answer_type is 'C' use textbox for data entry.

and what i want is to add another control

if Answer_type='N' use DynamicCurrentcontrol as spinner in the same column with Highvalue,Lowvalue,val(def_answer) and the result saved in Answer as STR(spinner.value).

But not sure how to do this.


 
Craig

I was thinking of having to create a container class with a spinner in it but you mentioned subclassing the spinner to handle character/numeric conversion on the fly and use it as an optional dynamiccurrentcontrol

Would you be able to show me an example as this sounds like a prettier option than a separate column with just the spinner arrows next to it.

Thanks for your assistance.
 
Havn't had much luck with this. using VFP 8 sp1

Is it possible to use a spinner as a dynamiccurrentcontrol in a grid column to increment "character type" data ?



 
No, but you can increment numeric data and convert the changes back into character data for the character field. You'll want to create your own spinner class to handle this. Think of using the controlsource_assign method and the spinner's interactive change event...also an added property to hold the true controlsource. If that seems too complex and difficult then make a container and put a visible spinner in it and an invisible textbox...the invisible textbox will be hooked to the true controlsource of the column and the visible spinner will be for representing the data in numeric format and allowing the user to spin through the values...when the textbox value changes you'll set the spinner with something like val(str(this.value)) and when the spinner changes you'll set the textbox's value with something like Transform(this.value) or alltrim(str(this.value))

I'd work the whole thing up for you, but I'm a little squeezed for time, and you might have more fun doing it yourself. Hopefully the above paragraph gives you some things to go on and if you get stuck again just post back and we'll see what we can do.

boyd.gif

 
Hello GoTheAllBlacks.

New Zealander, eh ;-)

I have a character field as controlsource in a grid column with currently two dynamiccurrentcontrols set to either textbox or combobox. My question is I want to add a spinner dynamiccurrentcontrol as an option if the field is numeric.But i get an error of course for invalid type

Have you considered either having a pop up form for editing the data in the current grid row (you could pop up up from the grid's dblClick) or a set of controls on the form above the grid? This would cewrtainly simplify your problem and it would probably be an easier way for your users to enter data.

This way you could have all the controls on your form, all stacked one on top of the other and use a little code to determine which one was visible using their zOrder() methods and setting their Visible properties appropriatey.

As far as the spinner to bind to character data goes, there is a very good example that you can modify if you have a copy of 1001 Things You Wanted to Know About Visual FoxPro ( in Chapter 4:

The true time spinner (Example: CH04.VCX::spnTime)
This control looks and acts just like the time spinner you see when using the Date/Time Picker ActiveX control that ships with Visual Studio. However, it has several features that make it more generally useful than the ActiveX control. First, this control does not require that it be bound to a field of the DateTime data type. As we have said, the best format for storing user entered time is in a character field formatted to include the universal ‘:’ time separator. The control can be configured to display and recognize either a 5-character ‘hh:mm’ format or a full 8-character ‘hh:mm:ss’ format and update either appropriately. This is controlled by a single property, lShowSeconds. Finally, because this is a native Visual FoxPro control it does not suffer from the inherent problems that haunt ActiveX controls with respect to the multiple versions of specific windows DLLs, nor are there any problems associated with registering the control.

This control uses a cControlSource property for binding to an external data source and has associated methods (RefreshSpinner and UpdateControlSource) to handle the issue of converting between character (source) and numeric (internal) values and back. The UpdateControlSource method, called from the spinner's Valid method, allows the time spinner, which is really an unbound control, to behave just like one that is bound when its cControlSource property is set.


Conversely, the RefreshSpinner method updates the spinner's value from its cControlSource. In true bound controls, this function is handled automatically whenever the control is refreshed. Our RefreshSpinner method is called from the spinner's Refresh to provide this functionality.




Marcia G. Akins
 
Hi Marcia

Yes a Kiwi. Downunder the downunder. or you might say 'Orc' country :)

Yes I thought of a form to pop up and a separate control on form but didn't like it ie to many clicks and eye movements and visually not what I would like for user.

Don't have '1001 things' I've been learning programming from this forum for 2 years (part time as I have a office furniture mnfactg bus). Probably take me another 2 years and still won't know half of Vfp it seems to be Limitless and always seems to have a better way somewhere. (and while i'm here 'Great!! forum' and thanks to everybody who contributes I've learn't a lot, but always never quite enough).

I've tried Craigs suggestions but havn't got there yet.

1) Tried using 'Controlsource_assign' in subclassed spinner but still get invalid type when I set the column's controlsource. I have an iif statement setting the Dynamiccurrentcontrol to 'as per thread above'.got lost on this one. Sounds like the best option but how ??? Would like to know this one.

2) Created a Container control with invisible textbox and visible spinner and this works with the exception that the controlsource '.Answer' which is preloaded with .def_answers, doesn't pre display in the column when this control is used as 'Dynamic' (container?? invisible textbox??). It only displays with control on 'Gotfocus' and I'd like to display the answers in column before column cell is clicked to display '.Answer' and appropriate Dynammic control to allow user to change.






 
Hello GoTheAllBlacks.

My husband and I spent about a week in New Zealand in July 2003 (we spoke at OzFox in Sydney, so we took some holiday while we were in that part of the world). We went to Mata Mata and saw some hobbit holes and we went to Rotorua and saw some thermal mud ;-) Sure is pretty over there!

Yes I thought of a form to pop up and a separate control on form but didn't like it ie to many clicks and eye movements and visually not what I would like for user.

I used to feel like that, but over the years I have moved away from data entry in the grid, especially when there is a lot of information to enter. IMHO, Horizontal scrolling grids are not very friendly for data entry. My pop up forms generally have what I call "auto-add" mode so that when the user hits ENTER, the current record is saved ( and displayed in the grid in the calling form) and a new blank record is added in the pop up form.

1) Tried using 'Controlsource_assign' in subclassed spinner but still get invalid type when I set the column's controlsource. I have an iif statement setting the Dynamiccurrentcontrol to 'as per thread above'.got lost on this one. Sounds like the best option but how ??? Would like to know this one.

I suspect that this is caused by the fact that the spinner's ControlSource must be numeric. If your grid column is a bound column, it cannot be both numeric and character at the same time ;-)

Marcia G. Akins
 
Hello Marcia.

Yes its a great place to live or visit for a holiday. The 'LOTR's' and 'The last Samarai' showed most of the country. next 'King Kong' ,'River queen','the lion witch and the wardrobe'.

I agree that data entry via grid is not user friendly and use your way for other apps.

This app is a single form multipage product/price library for my customers (retailers)to select products.
They ist select a product using tree and image display
they can then print an order to me from a details page with grid (only 3 columns, no horizontal scrolling) either using default or changed answers.
Or request a quote from me by changing the default sizes and colours etc and printing to me a quote request.
These default child question/answers records are particular to that product ie 'Width ?' 'Height ?' 'Colour ?' etc....
Hence the character type in column with no new or deletes.

Yes my grid column is bound and sparse .t.

If I use option 2) in above thread Dynamiccurrentcontrol 'text','Combo', and 'Container' for type 'N' with invisible textbox and visible spinner, How do I display the source when a container, as this seems to be the only problem I have ?.







 
Hi GoTheAllBlacks.

If I use option 2) in above thread Dynamiccurrentcontrol 'text','Combo', and 'Container' for type 'N' with invisible textbox and visible spinner, How do I display the source when a container, as this seems to be the only problem I have ?.

I think that there are some known issues with using containers in grids. Off the top of my head, I do not know what they are because I just do not do things that way ;-)

You may want to have a little search in MSDN..

Good luck. And when you get the solution, I would be interested in seeing it.




Marcia G. Akins
 
Marcia

An Idea that does work.

When is a spinner not a spinner. When its a text box and two command buttons.

I created a 'container' class called 'Mytextboxspinner' with textbox and two command buttons with picture arrows up and down one above the other to look like a spinner. of course a bit of coding to do for resize in column and incorporate textspinner high and low values etc but it works and looks like a spinner.

I took out the original textbox control and make the up and down arrows invisible when using for text entry and make them visible for "Numeric text entry" and also works with Dynamiccurrentcontrol,Bound to = .t.,sparse=.t. with dropdowncombo.

Haven't finished coding yet but so far so good.





 
Hi GoTheAllBlacks.

When is a spinner not a spinner. When its a text box and two command buttons.

Yep. I have created similar classes so that I could have "combo boxes" that could be bound to items not in the internal list - used a textbox, command button and drop down list inside a container < s >. Also created a "dxrop down calendar" combo that way.



Marcia G. Akins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top