Tips for using the Treeview control in Pb

Source: Internet
Author: User

The Treeview control in PowerBuilder is a tree-like tour, similar to the Windows resource manager. It features a tree-like hierarchy of information items, which can clearly show the relationship between the master and the details, making operations very convenient. It can be used in combination with datawindow in an application. It is a classification system that provides information, and a specific information to achieve the wonderful effect of Zhu Lian BIHE. It is particularly suitable for multi-level information classification retrieval, Which is incomparable to multi-level menus. Its forms of expression are favored by program designers and users, she can be seen in many applications.

In PowerBuilder, the application of the Treeview control is much more complex than other controls, and it is often overwhelmed when it comes to it. However, it is not difficult to grasp the mechanism clearly. Next, I will discuss the use of the Treeview controller with examples of long white company's classified search of books.

1. General steps for applying the Treeview Control

1. Establishing an application and setting up interfaces with databases is the prerequisite for database operations.

2. Create an application window W_1 in the application, and add two datawindow control objects named dw_3 and dw_4 to it and a Treeview object named TV _1.

3. Modify dw_3 attributes

General: Fill in the datawindow object name in an existing datawindow named dw_date (Note: it is different from the datawindow control object) for generating Tree View items, set its visible item to invisible.

4. Modify the dw_4 attribute

General: Enter the datawindow object name as an existing datawindow object named dw_ts to display the specific content queried.

5. Edit TV _1 attributes

The Treeview tree view item cannot be edited directly. You must write a program in the script.

Picture: adds four different icons to the picture name to represent two levels (level 1 and level 2) and two States (unselected and selected) in the Tree View ).

GENERAL: You can set whether to select a specific application, where:

Delete items: whether to allow the deletion of table items during running.

Disable pragdrog: whether to allow drag and drop table items during running.

Edit labels: whether to allow you to click a table item to change the table item title during running.

Show buttons: whether to display the +-button in the table item, which shows relative scaling.

Hide Selection: determines whether the selected item is displayed in high brightness when the control loses focus.

Show line: whether to add a vertical line between table items.

Lines at root: Specifies whether all table entries at the root layer are connected by a vertical bar.

Indentation: scale down the child table item to the right of the parent table item.

6. Compile TV _1 script

This is the key and difficulty of the Treeview control.

II. Information Structure and creation of the Treeview Control

Treeviewitem is the basic information unit of the Treeview control. There are two methods to generate Tree View items. One is to generate a root-layer view item, then, the lower-level view items are dynamically generated in the application. The other is to take all Tree View items once and complete. The two methods have their own advantages. Please select them based on your actual situation. The latter method is used in this example.

1. main attributes of treeviewitem in the Tree View

Data: any type, the internal value of the tree view item.

Level: Integer type. The tree view items are in the Tree View.

Children: boolean type, which determines whether the item has a next layer (middle name ).

Pictureindex: Integer type. The number of the icons used when this item is not selected in the icon queue.

Selectedpictureindex: Integer type. The number of the icon used when this item is selected in the icon queue.

2. functions used to generate the treeviewitem

Insertitemfirst (): takes the Add item as the first item.

Insertitemlast (): adds an item as the last item.

Insertitem (): insert the added item to the end of the specified item

Insertitemsort (): ordered.

3. Common Treeview events

Constructor: this event is triggered when the control is created. You can construct a treeviewitem here.

Click: When you click the treeviewitem item, run the query program.

Double click: double-click the treeviewitem to run the query program.

Itempopulate event: this event is triggered when a treeviewitem item is expanded for the first time. When this event is triggered, the system passes the handle of the treeviewitem through the handle parameter. It is mainly used to generate lower-level information items of corresponding items. It is mainly used in the first method.

Iii. Event code

1. constructor Event code of the Tree View control TV _1 wanqi

Integer li_rowcount, li_row
String li_current_dn, li_last_dn, li_current_ei, li_last_ei
// Declare the instance variables of the two tree views
Treeviewitem itvi_level_one, itvi_level_two
// Long ii_h_l_one
// Long ii_h_l_two
Dw_3.settransobject (sqlca) // dw_3
Is an implicit data window with data from the Spanning Tree
Li_rowcount = dw_3.retrieve () // number of rows
Dw_3.setsort ("LB, PM ")
Dw_3.sort ()
// Generate Tree View items at all levels
For li_row = 1 to li_rowcount
Li_current_dn = dw_3.object.lb [li_row]
// "LB category" in the dw_3 object"
Li_current_ei = dw_3.object.pm [li_row]
// "PM name" in the dw_3 object"
If isnull (li_current_ei) then
Li_current_ei = ""
End if

If li_current_dn <> li_last_dn then
// If lb is not the same as the first-level view item
// Set the level-1 Tree View Item
Itvi_level_one.label = dw_3.object.lb [li_row]
// Display information of view items
Itvi_level_one.level = 1 // level
Itvi_level_one.data = li_current_dn
// View item internal information
Itvi_level_one.pictureindex = 1
// The icon serial number used when no selection is made
Itvi_level_one.selectedpictureindex = 3
// Icon serial number used for selection
Itvi_level_one.children = (li_current_ei <> '')
// Whether the tree view has a lower level
Ii_h_l_one = This. insertitemlast (0, itvi_level_one)
// Add the item to the last entry of the level-1 tree
End if
// Set the level-2 Tree View Item
If li_current_dn <> li_last_ei then
If li_current_ei <> ''then
Itvi_level_two.label = dw_3.object.pm [li_row]
Itvi_level_two.level = 2
Itvi_level_two.data = li_current_dn
Itvi_level_two.pictureindex = 2
Itvi_level_two.selectedpictureindex = 4
Itvi_level_two.data = li_current_ei
Itvi_level_two.children = false
Ii_h_l_two = This. insertitemlast
(Ii_h_l_one, itvi_level_two)
// Add the item to the last entry of the second-level tree
End if
End if
Li_last_dn = li_current_dn // set the comparison item
Li_last_ei = li_current_ei
Next

2. clicked Event code of the TV _1 Control

String S1
Treeviewitem II
This. getitem (handle, ii)
S1 = string (II. Label)

Choose case II. Level
Case 1
// Filter category
Dw_4.setfilter ("lB = '" + S1 + "'")
Dw_4.filter ()
Case 2
Dw_4.setfilter ("PM = '" + S1 + "'")
Dw_4.filter ()
// Filter the title
End choose

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.