Foxite.COM Community Weblog

Foxite.COM Community Weblog - free weblog service for the Visual FoxPro Community.
Welcome to Foxite.COM Community Weblog Sign in | Join | Help
in
Home Blogs Forum Photos Forum Archives

Neil Tonkin



Adding UITypeEditors to Visual FoxPro

Okay, so we not really going to host .NET in VFP but we can pinch some concepts from thier PropertyGrid.

 

In my last entry we began to discuss the integration of the Extreme Property Grid ActiveX control into our FoxPro applications. I want to focus on supplementing the behaviour of the default data type support built into the grids fields. To recap, the following is typical of the code required to add a node and value to the control.

 

#DEFINE xtpGridThemeDefault       0     

#DEFINE xtpGridThemeNativeWinXP   1     

#DEFINE xtpGridThemeOffice2003    2     

#DEFINE xtpGridThemeCool          3     

#DEFINE xtpGridThemeSimple        4     

#DEFINE xtpGridThemeDelphi        5     

 

#DEFINE PropertyItemString        0      && String Item

#DEFINE PropertyItemNumber        1      && Number Item

#DEFINE PropertyItemBool          2      && Bool Item

#DEFINE PropertyItemColor         3      && Color Item

#DEFINE PropertyItemFont          4      && Font Item

#DEFINE PropertyItemDouble        5      && Double Item

#DEFINE PropertyItemDate          6      && Date Item

#DEFINE PropertyItemPicture       7      && Picture Item

 

with ThisForm.olePropertyGrid

   *!* Display the toolbar.

   .ToolBarVisible = .T.

 

   *!* Display the help pane and set its initial size

   *!* in pixels.

   .HelpVisible = .T.

   .HelpHeight = 78

  

   *!* Set the grid splitter proportion as a percentage.

   .SplitterPos = 0.35

  

   *!* Set the visual theme.

   .VisualTheme = 0

 

   *!* Clear the categories collection.

   .Categories.Clear()

 

   *!* Add a new category and make sure it is expanded.

   loSection = .AddCategory("System Paths")

   loSection.Expanded = .T.

  

   *!* This is the desription that will appear in the

   *!* help pane.

   loSection.Description = "System paths test category"

 

   *!* Add a read-only string property called Driver with its value

   *!* taken from a field in the odbcconnections table.

   loPropertyItem = loSection.AddChildItem(PropertyItemString, ;

                                           "System Files",     ;

                                           "c:\systemfiles\")

  

   loPropertyItem.Tag = 1000

 

   *!* This is the description that will appear in the

   *!* help pane.

   loPropertyItem.Description = "Select a new path."

endwith

 

Okay, so we have the ability to manually enter a path and by assigning a unique integer tag to the node we can validate its contents in the ValueChanged event.

 

Now wouldn’t it be better to supplement this behaviour with some form of UI asset that allows us to invoke a directory selector. Well the Property Grid control allows us to do this by assigning one of the following PropertyItemFlags to the node:-

 

#DEFINE ItemHasEdit               1      && Item has an edit control

#DEFINE ItemHasExpandButton 2      && Item has an expand button

#DEFINE ItemHasComboButton        4      && Item has a combo button

 

We want to add an expand button to the property grid node, this will give us a small button that displays three ellipses which can be used to display our custom dialog for directory selection.

 

Add the following code to your node creation process remember to include the three flag definitions above.

 

loPropertyItem.Flags = ItemHasExpandButton

 

When you run the form you should be presented with something that looks like the following gallery image.

 

http://weblogs.foxite.com/neiltonkin/gallery/image/22.aspx

 

If you press the expand button you will see that it doesn’t really do anything, this is because we need to inject some code to respond to the InplaceButtonDown event.

 

*** ActiveX Control Event ***

LPARAMETERS item

 

LOCAL lcNewPath

 

lcNewPath = ""

 

if item.Tag = 1000

   lcNewPath = getdir("c:\", "New Path", "Select a new path", 64)

      

   if NOT empty(lcNewPath)

      item.Value = lcNewPath

   endif

endif

 

Once again you can see we use the nodes Tag property to identify the source of the button press and then by using FoxPro’s getdir() function we allow the user to visually select a new path.

 

You are not limited to the built in FoxPro functions, you can create your own dialogs for editing any type of information in any way you see fit. This gives you similar functionality to Visual Studio which supports more complex data type enumeration and selection through its UITypeEditor classes. For example, you could build an equivalent to Visual Studio’s RegexTypeEditor so that the end-user can select how their postcodes are masked and validated.

 

Published Thursday, April 14, 2005 9:16 PM by neilton

Comments

No Comments
Anonymous comments are disabled

This Blog

Post Calendar

<April 2005>
SuMoTuWeThFrSa
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

Archives

Syndication