Checkboxes application routine of Pb tree

Source: Internet
Author: User

Original post location: http://www.hur.cn/bbs/dispbbs.asp? Boardid = 85 & id = 60818

Tree is widely used in programs, and many new users are always hard to create trees. Here is a tree application routine (this routine adds two function implementations based on a tree control I originally provided ). Of course, if you want to implement a three-state and four-state checkbox, You can implement it with a little bit of brains on the basis of my program.

[Upload = jpg] UploadFile/2007-7/200771521302926660. jpg [/upload]

Goals to be achieved:

1. When a node is selected or unselected (the checkboxes status changes), the tree can review all the subnodes under the node so that the subnode status is consistent with that of the current node.

2. You can easily obtain the selected status.
Difficulties:

1. Click the label (that is, the displayed text). The node status cannot be changed. Otherwise, a problem occurs when the tree is expanded.

2. pb does not provide events for tree node state change. Therefore, it can only be written in the clicked event. When a user clicks a label, the clicked event is triggered immediately, which is in conflict with the first one.

3. Combining the above two points: we must click checkboxes in the clicked event to trigger the program that changes the status.

4. Whether to select a node or how to select a node through a program has plagued me for a long time. Finally, we found that pb processes checkboxs by setting or determining statepictrue.

5. In the clicked event, the node status changes until all the code is executed.

Not much nonsense.

First, solve the following problems:

You need to use the api to determine whether checkboxes has been clicked.

Declare API: Function integer getiteminfo (long hWnd, long uMsg, long wParam, ref tvhittestinfo TV) library "user32.dll" Alias For "SendMessageA"

The structure required by this API has been created in the program. You can view it on your own.

Define an event mousemove (pbm_mousemove) and write the following code in the mousemove event:

// ================================================ ====================================
// Get the node status
// ================================================ ====================================
Tvhittestinfo ltvitem
Tvitem Item
Long ll_handle
RECT ItemRect, WindowRect
POINT point
Ll_handle = handle (this)
Ltvitem.pt. xx = UnitsToPixels (xpos, XUnitsToPixels! )
Ltvitem.pt. yy = UnitsToPixels (ypos, YUnitsToPixels! )
Getiteminfo (handle (this), 4 cores, 0, ltvitem)
IF ltvitem. hItem = 0 then return
Ib_ischeckboxes = (ltvitem. flags = 64)

// ================================================ ====================================
// Description: ib_ischeckboxes is the tree's instance variables. True: checkboxes under the cursor
// ================================================ ====================================

Then define two functions:

// ================================================ ====================================
// Function: vu_treeview: of_select ()
//--------------------------------------------------------------------
// Description: sets whether to select the status icon.
//--------------------------------------------------------------------
// Parameters:
// Value long al_handle node handle
// Value integer ai_picid status image no.
//--------------------------------------------------------------------
// Return: (none)
//--------------------------------------------------------------------
// Author: Cheng Ning Date: 2007.07.15
//--------------------------------------------------------------------
// Modification history:
//
// ================================================ ====================================
Treeviewitem ltvi_item
This. getitem (al_handle, ltvi_item)
Ltvi_item.statepictureindex = ai_picid
Setitem (al_handle, ltvi_item)

// ================================================ ====================================
// Function: vu_treeview: of_isselect ()
//--------------------------------------------------------------------
// Description: determines whether a node is selected (in the checkboxs status)
//--------------------------------------------------------------------
// Parameters:
// Value long al_handle node handle
// Value integer ai_selectpicid the selected Image number
//--------------------------------------------------------------------
// Return value: Boolean
//--------------------------------------------------------------------
// Author: Cheng Ning Date: 2007.07.15
//--------------------------------------------------------------------
// Modification history:
//
// ================================================ ====================================

Treeviewitem ltvi_item
This. getitem (al_handle, ltvi_item)
Return ltvi_item.statepictureindex = ai_selectpicid

Then, write a piece of code in the tree's clicked. Note that there is a long comment in the program, which mainly solves the fifth difficulty. you can comment out the corresponding code and run it to see the effect:

If this. ib_ischeckboxes then
// First, check whether the selection box is selected.
Ib_select = This. of_isselect (handle, 1)
This. of_scanallitem (handle, 'selectitem ')
/* Important:
The original status is not selected as an example:
Original Status 1
The previous sentence of_scanallitem sets the node status to 2.
After the clicked event is completed, the node status is reset to 1, which is inconsistent with the target.
Therefore, the following code sets the node status to the original status before of_scanallitem,
Ensure that the image is displayed in the correct status after the clicked event
I don't know if you can understand it like this */
If ib_select then
This. of_select (handle, 1)
Else
This. of_select (handle, 2)
End if
End if

The change of node status is mainly implemented through the of_scanallitem (handle, 'selectitem ') function and the ue_expfun of the tree. I have explained this in my previous post.

Ue_expfun Event code:

String ls_data, ls_label
Choose case as_evename
Case 'selectitem'
// Set whether the node is selected
If ib_select then
This. of_select (al_handle, 2)
Else
This. of_select (al_handle, 1)
End if
Case 'getselect'
// Obtain the selected node
If TV _2.of_isselect (al_handle, 2) then
TV _2.of_getdata (al_handle, ls_data, ls_label)
Is_selectitem + = "data:" + ls_data + "~ Tlabel: "+ ls_label + '~ R ~ N'
End if
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.