Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

Tutorial 1

Bind Sample
In this sample program you will:

 Learn how to add a property grid to an application


The grid will contain items that are bound to variables. These variables store the values of the
property grid items and can be accessed without using the property grid methods and properties.
Three grids will be created, one for each node in the tree view. Some of the properties in the grid
will contain a list of data to choose from, others can be edited, and some cannot be changed at all.
2

Creating a Property Grid

Figure 1.1.
What you can
create in this
sample

Opening the Application


 Open Visual Basic and Select new project from the file menu. Select Standard EXE
from the new project dialog box and click OK

Figure 1.2.
Opening a new
project
3

Adding Controls
 Once the VB Application Wizard is finished, display the toolbox (View->Toolbox).
 Right-Click on an open area not occupied by a control and select
Components… from the pop-up menu (Bottom Left). Project->Components
will work as well.
 Select the Controls tab if it is not already selected and scroll down to the
bottom. You should see Xtreme PropertyGrid ActiveX Control module
 Make sure that the check box is selected and click OK

Figure 1.3.
Adding a new
control

 You should now have a new control added to your Toolbox which looks like this:

 Add the Microsoft Windows Common Controls 5.0 (SP2) control as in Figure 1.4.
4

Figure 1.4.
Adding a new
control

 Several new controls will be added to the toolbox. You will use the TreeView
control in this sample project

You will need to add some controls to the main form


 Add the three PropertyGrid controls to the main form.
 A TreeView
 An ImageList
 Two CommandButton controls

 Place a PropertyGrid control (blue box in Figure 1.5.) on any blank area on the
main form.
 Click on the PropertyGrid control
 Go to the properties window
 Name it wndPropertyGrid
5

Figure 1.5.
PropertyGrid
controls

 Add two more property grid controls


 Name them both wndPropertyGrid
 A message (Figure 1.6.) will be displayed asking if you want to create a control array.
Click the Yes button.
 Make sure all three property grids are the same size
 Place all them on top of each other so they appear as one (blue box in
Figure 1.5.)
 Make sure that the property grid with index zero is on top, index one in the
middle, and index two on the bottom

Figure 1.6.
Create a
control array

 Add an ImageList control (green box in Figure 1.5.) to your form


6

 Click on the control


 Go to the properties window
 Change the name to imlTreeIcons
 Change the ImageHeight to 13 and ImageWidth to 16

 Add a TreeView control (red box in Figure 1.5.) to your form


 Click on the control
 Go to the properties window (see Figure 1.7.)
 Change the Name to wndTreeView
 Indentation to 0
 LabelEdit to 1-tvwManual
 Style to 1-tvwPictureText

Figure 1.7.
wndTreeView
properties

 Add two CommandButtons (purple box in Figure 1.5.) to your form.


 Change the Name to cmdOK and cmdCanel
 Make cmdOK the default button.

Each control in the TreeView will have an icon indicating a folder is open or closed. An
arrow icon will point to the current node as in Figure 1.8.

Figure 1.8.
Arrow Icon

 Right-click on the imlTreeIcons ImageList control already created


 Select properties from the pop-up menu.
7

Figure 1.9.
Opening
ImageList
properties

 There will not be any icons in the Images: List box (red box in Figure1.10.) To add
images:
 Click on the Insert Picture… button
 Navigate to the C:\Program Files\Codejock
Software\ActiveX\Suite\samples\PropertyGrid\BindSample\Icons
directory.
 Insert arrow.bmp first, then folder.bmp, and last openfolder.bmp as in
Figure 1.10.
8

Figure 1.10.
Images Property
Pages

 The key and tag properties are not important in this project. Leave them as the
default values.
 The index of the image will be used to associate an image to different
TreeView controls.
 A MaskColor is needed to mask transparent content of an image.
 Each image has a background color of green that needs to be set as the
transparent color
 Click on the Color tab
 Click on MaskColor (red box in Figure 1.11) in the Properties box
 Select Green from the Color Palette (blue box in Figure 1.1.)
 Click the Apply button
 Click OK to finish
9

Figure 1.11.
Color Property
Pages

 To load the imlTreeIcons ImageList into the TreeView control:


 Right-click on the TreeView control
 Select properties
 Make sure the General tab is selected from the property dialog
 Select imlTreeIcons from the ImageList drop-down menu as in Figure 1.12.
 Click Apply
 Click OK

Figure 1.12.
General Property
Pages

 This will complete the form setup


10

Available Events
 Look at all of the available events the PropertyGrid controls provide. There are two
ways to do this:
#1
 Open up the object browser by hitting F2
 Select XtremePropertyGrid from the library list drop down menu

Figure 1.13.
Displaying
available events

 Select the PropertyGrid entry in the list box. Now you can see all of the
available members, methods, events, properties, functions, and subs. If you
click on a member, you will get detailed information about that member.
Here we are interested in the events available that have the lightning bolt
icon next to them.

#2
 Go to your code view by hitting F7

Figure 1.14.
Displaying
available events
11

The left drop-down is a list of your controls; the right drop-down is a list of
event procedures available for those controls.

Select the wndPropertyGridr option from the left drop down list and browse the right drop
down list for a list of event procedures available to the PropertyGrid control. You might
also take a look at the PropertyGridItems and ItemConstraints objects as you will be using
these as well. It is this second method that we will be using to add code to the different
PropertyGrid event Procedures.

The property grids will be bound to variables, which allow the property grids to store data in
variables.

 Binding works in only one direction.


 When the value of a PropertyGridItem is changed, the value of the bound variable
will be changed to the PropertyGridItem value.
 If the value of the variable is changed without using the PropertyGrid, the
PropertyGridItem value will not change (You would need to explicitly update the
PropertGridItem value with the contents of the variable)
 A variable will have to be bound to each PropertyGridItem (if a property is not
bound, a variable does not need to be declared)
 The advantage of binding is the variable can be used and manipulated without using
PropertyGridItem methods and properties.

When the binding occurs, the variable name is passed to the


method in String Notation. String Notation means the name
of the variable is placed in quotation marks, within the
quotation marks the variable name can be passed with any
combination of spaces and uppercase/lowercase letters, but
no extra characters can be added and they must appear in the
same order. For example, when binding to the variable
AssembleName you could pass the variable as
“assemblename” which is the same as “ASSEMBLE n a m
e”, but “Assemble Names” will not work because an extra
“s” is added. The reason for this is the variable name passed
in String Notation will be used as the PropertyGridItem
Caption if no caption is explicitly set.

 Declare the variables as below. There is a variable defined for each


PropertyGridItem that will be bound.
12

A variable must be declared within an object’s code if it will


be bound. This means bound variables cannot be declared in
a .bas module

Public AssembleName As String


Public OutputType As String
Public Namespace As String
Public StartupObject As String
Public ApplicationIcon As String
Public ProjectFile As String
Public ProjectFolder As String
Public OutputFile As String
Public TargetSchema As String
Public PageLayout As String
Public ClientScriptLanguage As String

Public ConditionalCompilationConstants As String


Public OptimizeCode As Boolean
Public CheckforArithmeticOverflow As Boolean
Public Alowunsafecodeblocks As Boolean
Public WarningLevel As String
Public TreatWarningsAsErrors As Boolean

 A variable has been declared for each PropertyGridItem in the property


grids.
 There are two types of variables declared, String and Boolean.
 Properties in the grid that are bound to a String variable will display the text
in the String
 Properties bound to a Boolean variable will display True or False.
 In order to keep track of what property grid is currently being displayed; an
integer variable will be used.

 The integer variable will correspond with the index number of a property
grid in the PropertyGrid control array. Declare the integer variable:
Dim nCurrentGrid As Integer

 Each variable needs to be initialized so the property grid has some data to display
when the application first opens.
 Before the property grids are created, initialize the variables in the Form_Load event
procedure.
 Assign the values as in the following:

Private Sub Form_Load()

nCurrentGrid = 0
13

AssembleName = "WindowsApplication1"
OutputType = "Windows Application"
Namespace = "WindowsApplication1"
ApplicationIcon = "App.ico"
ProjectFile = "WindowsApplication1.csproj"
ProjectFolder = "C:\Documents and Settings\User\My Documents\Visual Studio Projects\" _
+ "WindowsApplication1\"
OutputFile = "WindowsApplication1.exe"

TargetSchema = "Internet Explorer 5.0"


PageLayout = "Grid"
ClientScriptLanguage = "VBScript"

ConditionalCompilationConstants = "DEBUG;TRACE"
OptimizeCode = False
CheckforArithmeticOverflow = False
Alowunsafecodeblocks = False
WarningLevel = "Warning level 4"
TreatWarningsAsErrors = False

InitTreeView
InitGeneralProperties
InitDesignerProperties
InitBuildProperties

End Sub

 The current grid to display is initialized to 0 (0 is the first grid, 1 is the


second, and 2 is the third grind in the PropertGrid control array)
 The rest of the variables are initialized the value that will initially be displayed
for each PropertyGridItem.
 After the variables are initialized, four subroutines are called.
1. InitTreeView will create the tree in the TreeView control
2. InitGeneralProperties will add Categories and PropertyGridItems
to the first PropertyGrid control.
3. InitDesignerProperties will add Categories and PropertyGridItems
to the second PropertyGrid control.
4. InitBuildProperties will add Categories and PropertyGridItems to
the third PropertyGrid control.
 These subroutines will be created next

The InitTreeView subroutine will create all of the nodes in the TreeView control. Create the
InitTreeView subroutine
 Click somewhere on your code view window
 Click Tools>Add Procedure... from the popup menu.
14

Figure 1.15.
Add Procedure

 Type InitTreeView as the name


 The type as sub
 The scope as private
 Click OK
 Visual Basic takes you to the new subroutine.
 Start by declaring an object of type Node called NodeCommon as below

Private Sub InitTreeView()

Dim NodeCommon As Node, Node As Node, NodeConfiguration As Node


Set NodeCommon = wndTreeView.Nodes.Add(, , , "Common Properties", 2)
NodeCommon.ExpandedImage = 3
NodeCommon.Tag = 0

Set Node = wndTreeView.Nodes.Add(NodeCommon, tvwChild, , "General", 1)


Node.Tag = 0
Set Node = wndTreeView.Nodes.Add(NodeCommon, tvwChild, , "Designer", 0)
Node.Tag = 1

NodeCommon.Expanded = True

Set NodeConfiguration = wndTreeView.Nodes.Add(, , , "Configuration Properties", 2)


NodeConfiguration.Tag = 2
NodeConfiguration.ExpandedImage = 3
Set Node = wndTreeView.Nodes.Add(NodeConfiguration, tvwChild, , "Build", 0)
Node.Tag = 2

NodeConfiguration.Expanded = True

End Sub

 Create a node
 Add it to the TreeView control’s node collection
 Assign a pointer to it called NodeCommon
15

 Use the wndTreeView.Nodes.Add method to add nodes to the TreeView control.


 The wndTreeView.Nodes.Add method takes six parameters: .Add(relative,
relationship, key, text, image, selected image) The only required parameter
is text.
Set NodeCommon = wndTreeView.Nodes.Add(, , , "Common Properties", 2)

1. The relative parameter specifies a pre-existing node that the new


node will have a relationship with.
2. The relationship parameter specifies the relative placement of the
new node with the pre-existing node.
3. If no Node object is named in relative, the new node is placed in the
last position of the top node hierarchy.
4. Text is the caption that appears in the node.
5. Image is the index of an image in an associated ImageList control.
6. Selected image is the index of an image in an associated ImageList
control that is shown when the Node is selected.
 The “Common Properties” node will have child nodes so it would be a good idea to
change the image of the node when it is expanded.
 Assign the index of an image in an associated ImageList control to the
NodeCommon.ExpandedImage property

NodeCommon.ExpandedImage = 3

 Now the image next to the text will change indicating whether the node is
expanded.
 There will be three grids to display
 There must be a way to identify which grid needs to be displayed when a
node is clicked. This is done with the Tag property.

NodeCommon.Tag = 0

 The Tag returns or sets an expression that stores any extra data needed for
your program.
 The index of the appropriate grid will be assigned to each node.
 Code will be added to retrieve the node Tag each time a node is clicked and
that value will be used to determine which grid is displayed.
16

 The “Common Properties” node referenced by NodeCommon is a top level node in


the TreeView control. Child nodes need to be added; each child will represent a
different grid.
 Use the wndTreeView.Nodes.Add method passing in NodeCommon as the
relative node and tvwChild as the relationship as below:

Set Node = wndTreeView.Nodes.Add(NodeCommon, tvwChild, , "General", 1)


Node.Tag = 0
Set Node = wndTreeView.Nodes.Add(NodeCommon, tvwChild, , "Designer", 0)
Node.Tag = 1

 This will create two child nodes to the “Common Properties” node.
 The “General” node is assigned a Tag value of zero and the “Designer”
node is assigned a Tag value of one.
 By default, the top level nodes are not expanded, leaving the child node
hidden from view.
 To expand the top level node “Common Properties,” modify the Expanded
property, setting it to True.
NodeCommon.Expanded = True

 So far a tree with a top level node called “Common Properties” was created and has
two child nodes called “General” and “Designer” as in Figure 1.16.

Figure 1.16.
Common
Properties node

 Create another top level node called “Configuration Properties”


 Assign a Tag value of two
 Add one child node to the “Configuration Properties” node called “Build”
and assign a Tag value of two.
 Enter the following code, using the same steps used to create the “Common
Properties” node and child nodes
Set NodeConfiguration = wndTreeView.Nodes.Add(, , , "Configuration Properties", 2)
NodeConfiguration.Tag = 2
NodeConfiguration.ExpandedImage = 3
Set Node = wndTreeView.Nodes.Add(NodeConfiguration, tvwChild, , "Build", 0)
Node.Tag = 2

NodeConfiguration.Expanded = True

 Set the Expanded property to True.


 The above code created a top level node called “Configuration Properties”
with one child node called “Build” as in Figure 1.17.
17

Figure 1.17.
Configuration
Properties node

This will complete the tree.

A separate subroutine will be created for each property grid


 Add a subroutine like you did previously
 Call it InitGeneralProperties
 The type is Sub, and make it private. See below:
Private Sub InitGeneralProperties()

Dim Category As PropertyGridItem, ItemAssemble As PropertyGridItem


Dim Item As PropertyGridItem

Set Category = wndPropertyGrid(0).AddCategory("Application")


Set ItemAssemble = Category.AddChildItemBinded(PropertyItemString, Me, "AssembleName")
ItemAssemble.Caption = "Name of Application"

Set Item = Category.AddChildItemBinded(PropertyItemString, Me, "OutputType")


Item.Constraints.Add "Windows Application"
Item.Constraints.Add "Console Application"
Item.Constraints.Add "Class Library"
Item.ConstraintEdit = True
Item.Flags = ItemHasEdit + ItemHasComboButton
Item.Caption = "Type of Output"

Category.AddChildItemBinded PropertyItemString, Me, "Namespace"


wndPropertyGrid(0).Categories(1).Childs(3).Caption = "Default Namespace"

Category.AddChildItemBinded PropertyItemString, Me, "Startup Object"


Category.AddChildItemBinded PropertyItemString, Me, "Application Icon"

Category.Expanded = True
ItemAssemble.Selected = True

Set Category = wndPropertyGrid(0).AddCategory("Project")

Set Item = Category.AddChildItemBinded(PropertyItemString, Me, "Project File")


Item.ReadOnly = True
Set Item = Category.AddChildItemBinded(PropertyItemString, Me, "Project Folder")
Item.ReadOnly = True
Set Item = Category.AddChildItemBinded(PropertyItemString, Me, "Output File")
Item.ReadOnly = True

Category.Expanded = True
End Sub

 Start by declaring three objects of type PropertyGridItem


 Call them Category, ItemAssemble and Item.
Dim Category As PropertyGridItem, ItemAssemble As PropertyGridItem
Dim Item As PropertyGridItem
18

 Add a category named “Application” to the first property grid in the control
array.
1. Use the wndPropertyGrid(0).AddCategory(“Application”) method,
using zero to indicate the first property grid and passing in a string
value of “Application”
2. Set Category as a pointer to this property grid category.
Set Category = wndPropertyGrid(0).AddCategory("Application")

 Property items can now be added to the “Application” category.


 The “Application” category will have five property items.
 Four will be single string values; one will be a drop-down list of strings.
 To add an item that is bound to a variable, use the AddChildItemBind method as
below
Set ItemAssemble = Category.AddChildItemBinded(PropertyItemString, Me, "AssembleName")

 The AddChildItemBind method takes three parameters


1. The first specifies the type of the property
2. The second is the object that handles the variable/property
3. The third is the name of the variable that will be bound to the
PropertyGridItem passed in String Notation.

It was previously explained what String Notation is and how to use it.
 The variable name in String Notation is automatically set as the Caption of the
PropertyGridItem.
 If the Caption property of the PropertyGridItem is not set, the default String
Notation is used.
 When adding the child property item bound to the variable “AssembleName”, set a
pointer called ItemAssemble to the property item.
 This pointer will be used to change the Caption and make this property item
“Selected” at startup.
 To override the default caption, set the Caption property of the
PropertyGridItem to the desired String value.
 Now change the Caption of the “AssembleName” property item as below
ItemAssemble.Caption = "Name of Application"
19

 Changing the Caption will not change the value of the variable.
 The next property item will have several preset values the user can choose from.
 The values will be displayed in a drop-down.
 Use the AddChildBinded method to add an item with property type
PropertyItemString
 Set the handler to Me
 Bind to the variable “OutputType”
 Set a pointer to the property item called Item as in the following:
Set Item = Category.AddChildItemBinded(PropertyItemString, Me, "OutputType")

 To create a list of items, use the Item pointer to add Constraints to the
property.
 The “OutputType” property item will have three items to choose from in the
drop-down list.
 Use the Item.Constraints.Add method to add a constraint.
 The Constraints.Add method is only one parameter of type string.
 Add three constraints to the “OutputType” property as below.
Item.Constraints.Add "Windows Application"
Item.Constraints.Add "Console Application"
Item.Constraints.Add "Class Library"

 By default, the property item value can be edited by the user. To keep the user from
changing the value of the items in the constraint list, set the Item.ConstraintEdit
property to True

Item.ConstraintEdit = True

 This will keep users from changing the text of the items in the constraint list.
It also keeps them from highlighting the text or placing the cursor anywhere
in the field.
 To display the list of values in a drop-down list, set the Item.Flags property
to ItemHasComboBox.
 To allow users to highlight the text and place the cursor on the text, use the
ItemHasEdit flag. The ItemHasEdit flag has the opposite effect as the
ConstraintEdit property.
Item.Flags = ItemHasEdit + ItemHasComboButton
20

 The ItemHasEdit flag allows the user to enter a value not in the list as well as
change the values. However, the ConstraintEdit property will not allow the
text of the items in the constraint list to be changed when set to True, you
will only be able to select from one of the items in the constraint list.
 Then the Caption of the “OutputType” property item is changed to “Type of
Output”
Item.Caption = "Type of Output"

 After adding the “Namespace” property item, the Caption is set using the
PropertyGrid methods as below

Category.AddChildItemBinded PropertyItemString, Me, "Namespace"


wndPropertyGrid(0).Categories(1).Childs(3).Caption = "Default Namespace"

 Each PropertyGrid contains a collection of Categories and each category contains a


collection of PropertyGridItems
 When you add a category, add it to the collection of Categories
 Each one can be accessed by an index number assigned by the order they are
added starting at 1.
 PropertyGridItems are added to a category’s collection of
PropertyGridItems.
 The “Namespace” caption was changed by accessing the first property grid
(wndPropertyGrid(0)), the first category added (“Application”), and the
third child item added (“Namespace”) to the first category (“Application”).

 Add the two remaining property items to the “Application” category as below:

Category.AddChildItemBinded PropertyItemString, Me, "Startup Object"


Category.AddChildItemBinded PropertyItemString, Me, "Application Icon"

 To have the “Application” category expanded, displaying all of its properties, set the
Category.Expanded property equal to True

Category.Expanded = True

 When the application starts, the “Assemble Name” property should be selected
 To do this, use the ItemAssemble pointer to set the Selected property equal
to True

ItemAssemble.Selected = True

 A second category will be added to the first grid called “Project”.


 The category will start out expanded and have three item properties.
21

 Each property will be read-only, so the user can only see the value and it will
appear grayed out.
 To make an item read only: Use the Item pointer setting the ReadOnly
property to True.
 Add the code below to add the “Project” category following the same steps
used to create the “Application” category.
Set Category = wndPropertyGrid(0).AddCategory("Project")

Set Item = Category.AddChildItemBinded(PropertyItemString, Me, "Project File")


Item.ReadOnly = True
Set Item = Category.AddChildItemBinded(PropertyItemString, Me, "Project Folder")
Item.ReadOnly = True
Set Item = Category.AddChildItemBinded(PropertyItemString, Me, "Output File")
Item.ReadOnly = True

Category.Expanded = True

This will complete the InitGeneralProperties subroutine.

Create a subroutine entitled InitDesignerProperties as you created the


InitGeneralProperties subroutine.
 Add categories to the second property grid the same as before.
 Code the subroutine as below:

Private Sub InitDesignerProperties()

Dim Category As PropertyGridItem


Dim Item As PropertyGridItem

Set Category = wndPropertyGrid(1).AddCategory("Web Designers")

Set Item = Category.AddChildItemBinded(PropertyItemString, Me, "Page Layout")


Item.Constraints.Add "Grid"
Item.Constraints.Add "Flow"
Item.ConstraintEdit = True
Item.Flags = ItemHasEdit + ItemHasComboButton

Category.AddChildItemBinded PropertyItemString, Me, "Target Schema"

Category.Expanded = True
Item.Selected = True

Set Category = wndPropertyGrid(1).AddCategory("Web Scripting")

Set Item = Category.AddChildItemBinded(PropertyItemString, Me, "Client Script Language")


Item.Constraints.Add "VBScript"
Item.Constraints.Add "JScript"
Item.ConstraintEdit = True
Item.Flags = ItemHasEdit + ItemHasComboButton

Category.Expanded = True
22

End Sub

 Make sure that a 1 is used as the property grid index since these categories and items
will be added to the second grid (index started at zero)
Set Category = wndPropertyGrid(1).AddCategory("Web Designers")

 The only other difference is that the “Page Layout” values can be edited by setting
the ConstraintEdit property equal to False

Create a subroutine entitled InitBuildProperties as you created the InitGeneralProperties


subroutine.

 Adding categories and items to the second grid is exactly the same as before.
 Code the subroutine as in the following:

Private Sub InitBuildProperties()

Dim Category As PropertyGridItem


Dim Item As PropertyGridItem

Set Category = wndPropertyGrid(2).AddCategory("Code Generation")

Set Item = Category.AddChildItemBinded(PropertyItemString, Me, _


"Conditional Compilation Constants")

Category.AddChildItemBinded PropertyItemBool, Me, "Optimize Code"


Category.AddChildItemBinded PropertyItemBool, Me, "Check for Arithmetic Overflow"
Category.AddChildItemBinded PropertyItemBool, Me, "Alow unsafe code blocks"

Category.Expanded = True
Item.Selected = True

Set Category = wndPropertyGrid(2).AddCategory("Errors and Warnings")


Category.AddChildItemBinded PropertyItemString, Me, "Warning Level"
Category.AddChildItemBinded PropertyItemBool, Me, "Treat Warnings As Errors"

Category.Expanded = True
End Sub

 Make sure that a 2 is used as the property grid index since these categories and items
will be added to the second grid (index started at zero)

Set Category = wndPropertyGrid(2).AddCategory("Code Generation")

 In this property grid there are some Boolean items which will display True or False
as its value
Category.AddChildItemBinded PropertyItemBool, Me, "Optimize Code"

Only one of the three grids can be visible at the same time. A subroutine will be added to
determine and set which grid is visible.
23

 Add a subroutine called SwitchPropertyGrid


 It will take an Integer as the only parameter
 Code the subroutine in the diagram below.
Private Sub SwithPropertyGrid(nGrid As Integer)

If nGrid <> nCurrentGrid Then


wndPropertyGrid(nCurrentGrid).Visible = False
wndPropertyGrid(nGrid).Visible = True

nCurrentGrid = nGrid
End If

End Sub

 An integer called nGrid is passed, which is the index of the property grid that
needs to be displayed.
 The integer nGrid is compared to the current grid index called nCurrentGrid
 If the two values are not equal, then a new grid with index nGrid is to be
displayed.
 When a new grid is to be displayed, the current grid with an index of
nCurrentGrid is hidden and the grid with and index of nGrid is set to visible
 nCurrentGrid is then updated with the value in nGrid.

When a node is clicked in the wndTreeView control, the corresponding property grid is
displayed. To determine when a node has been clicked:
 Edit the wndTreeView_NodeClick event procedure
 This event procedure is passed the node that was clicked as the only
parameter.
 Code the wndTreeView_NodeClick event procedure as below:

Private Sub wndTreeView_NodeClick(ByVal Node As ComctlLib.Node)

SwithPropertyGrid (Node.Tag)
If (Not Node.Parent Is Nothing) Then Node.Parent.Tag = nCurrentGrid

For Each Node In wndTreeView.Nodes


If Node.Child Is Nothing Then Node.Image = IIf(Node.Tag = nCurrentGrid, 1, 0)
Next
End Sub

 The SwitchPropertyGrid subroutine is called, passing in the Node.Tag value.


This will switch which grid is visible.
SwithPropertyGrid (Node.Tag)
24

 Each node was previously assigned a Tag value in step that corresponded
with one of the three property grids.
 Whenever a child node is clicked the Tag value of the parent is updated to
the child’s Tag value.
If (Not Node.Parent Is Nothing) Then Node.Parent.Tag = nCurrentGrid

 This is done to keep the current grid displayed even when the user clicks on
the parent node (nodes with folder icons).
 The arrow icon must point to the current node.
1. Look at all of the child nodes, checking the Tag value to determine
which one is active.
2. The nodes image is updated to the index of the arrow image in the
imlTreeIcons ImageList if the node is active (corresponding grid is
displayed).
3. If not, then no image is displayed.
For Each Node In wndTreeView.Nodes
If Node.Child Is Nothing Then Node.Image = IIf(Node.Tag = nCurrentGrid, 1, 0)
Next

For debugging purposes, the values of all the variables are printed in the debug window
when the application calls its Unload event procedure.
 Add the following code to the Form_Unload event procedure

Private Sub Form_Unload(Cancel As Integer)

Me.SetFocus

Debug.Print "AssembleName = " & AssembleName


Debug.Print "OutputType = " & OutputType
Debug.Print "DefaultNamespace = " & Namespace
Debug.Print "StartupObject = " & StartupObject
Debug.Print "ApplicationIcon = " & ApplicationIcon
Debug.Print "ProjectFile = " & ProjectFile
Debug.Print "ProjectFolder = " & ProjectFolder
Debug.Print "OutputFile = " & OutputFile
Debug.Print "TargetSchema = " & TargetSchema
Debug.Print "PageLayout = " & PageLayout
Debug.Print "ClientScriptLanguage = " & ClientScriptLanguage

Debug.Print "ConditionalCompilationConstants = " & ConditionalCompilationConstants


Debug.Print "OptimizeCode = " & OptimizeCode
Debug.Print "CheckforArithmeticOverflow = " & CheckforArithmeticOverflow
Debug.Print "Alowunsafecodeblocks = " & Alowunsafecodeblocks
Debug.Print "WarningLevel = " & WarningLevel
Debug.Print "TreatWarningsAsErrors = " & TreatWarningsAsErrors

End Sub
25

Both the OK and Cancel command buttons will call the forms Unload event procedure.
 Add the following code to the OK and Cancel Click event procedures

Private Sub cmdCancel_Click()


Unload Me
End Sub

Private Sub cmdOk_Click()


Unload Me
End Sub

This will allow you to see how each variable was affected.

You have now completed this tutorial! If you are unclear on anything covered, you might
want to go back and complete this tutorial again. It might be a good idea to add some
additional functionality to this sample application to make sure you fully understand what is
going on.

You might also like