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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grid Class using Class Designer 2

Status
Not open for further replies.

itflash

Programmer
Jul 18, 2001
535
0
0
GB

Hi all

I want to create a grid class using the visual designer.

In this class, I want to put some standard code in the header object - on click.

However, I never know how many columns I will need.

Therefore, how do I code/design this so the header will always have this specific code? - using the visual designer.

Thanks
Peter
 
itflash

I believe this can only be accomplish by code if your grid class has no columns or not the right amount of columns. Although your grid can be designed via the class designer, your code in the header would have to added programmatically (faq184-2164). Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi Peter,

Look in to this FAQ... by MikeGagnon
Adding procedures at runtime for grid objects
faq184-2164

You can use that as your approach..
In the Grids Init Event..
You can add object as many header objects as there are columns and also make that as your current control in the place of existing header objects. Make sure you also set the Headers Caption properties etc of added obejcts as per the other Header object before removing them.. or disregarding them.

:) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com

 


Thanks for the replies.



Was just trying out some things - basic style.


If i put this in the init event of the class grid (in the designer) - i get a read only error

for each oColumn in this.Columns
oColumn.header1.click="messagebox('hello')"
endfor

<this does depned on headers being called header1. Anyway around this?>


Also, i cannot define a class in the init within the class designer. It gives an error saying it cannot be done.


Therefore, do I have to do it @ form level?

Thanks
 
itflash

for each oColumn in this.Columns
oColumn.header1.click=&quot;messagebox('hello')&quot;
endfor


Shouldn't this read for each oColumn in this.Columns.count?

But can I ask why you do not want to define your grid class programmatically?

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
But can I ask why you do not want to define your grid class programmatically?


I am not expert in Foxpro and feel more comfortable seeing the grid on the form and positioning/configuing it that way.

I could if I wanted to, but do prefer seeing the grid on the form @ design time.

 
itflash

I am not expert in Foxpro

But sometimes going outside of your confort zone makes you a better programmer, and allows you to be more versatile.


I could if I wanted to, but do prefer seeing the grid on the form @ design time.

The problem with that concept is, it sounds like you just want to create a grid class (with no columns) and re-use it anywhere its needed, but it has to have some functionality that you want to add at runtime. Difficult.
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
FWIW, the ability to designate a custom Header class for a column (as well as custom pages in pageframes, etc.) in one of the new features of VFP 8.0, which was released to manufacturing last week. Instead of spending a lot of time getting this to work in prior versions, if you can wait for 8, it would worth your while.

Hope that helps!

-- Ed
-- Get great VFP support in a new forum filled with Microsoft MVPs!
--
 

Thanks Ed - that is useful to know.

Mike -

But sometimes going outside of your confort zone makes you a better programmer, and allows you to be more versatile.

Very true. My main problem is time - always trying to do things quickly to get paid.

Question about class prg
Do you have a standard prg for creating a specific class, like your faq or do you copy and paste the code into every form?

Also, is there no way around using the class designer.
when I try to set the click property, it says it is read only - based on the suggestion by ramani.

Thanks
 
Do you have a standard prg for creating a specific class, like your faq or do you copy and paste the code into every form?

Most of my FAQs come from designing the solutions visually, and loading the form (or whatever) in the class browser and viewing the code, copy and paste. It works for most classes (except for grids on a form), and I paste in a program and test it. Its the easiest way to suggest things on this site without having the possibility to upload a physical file. Also with VFP7's intellisense its hard to miss.

Also, is there no way around using the class designer.

Yes you have to establing the columncount in the class.


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 

Thanks for the reply.

Mike -

sorry, when asking about prg, i meant generally when you program your applications - so you dont repeat code.
Do you have one prg per grid?

Regarding class:

In the class designer - init of grid.
I have this alternative:

FOR nCnt=1 TO this.ColumnCount
this.Columns(nCnt).header1.click=&quot;messagebox('hello')&quot;
ENDFOR

but it still says - when i run a form - that the click is readonly and does not allow me to change it.
Any ideas?

Thanks
 
itFlash

sorry, when asking about prg, i meant generally when you program your applications - so you dont repeat code.
Do you have one prg per grid?


Sorry, I misunderstood. I have a few criteria(s?), when it coes to class.
[ol][li]If the object in question will be re-used more then once (which I believe in your case it will), then I consider a class.[/li]
[li]If the class will remain constant (ie: a locate record type, being used on all forms). The I consider a visual class, since all I have to do is send some paramaters to the init to determine the ALIAS() and the value to locate.[/li]
[li]If the class will change drastically, from one use to another, I have two choices.
[ul][li]DEFINE the class programmatically multiple time in the main program, changing the functions as required.[/li]
[li]Or create an actual object (no class) everytime I need it. That is the last resort.[/li][/ul][ol]
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 


Great - thanks

Any way I can resolve my other issue using the visual designer like ramanis suggestion?


Thanks
 


to get passed the readonly error - use a prg for the header click addobject and call it from your init of grid

...so many different ways to do things....



Thanks guys
ITflash
[thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top