Jump to content
Sign in to follow this  
Thetan

TreeView Question

Recommended Posts

Thetan

This is probably a simple fix, but here is my question. I would like to Create a treeview inside a tab and whenever you click on a different treeview item it will display something different. I'm not sure if this is even close to right, thanks for looking.

$TabSheet2 = GUICtrlCreateTabItem("List")
$TreeView2 = GUICtrlCreateTreeView(8, 48, 137, 217)
GUICtrlSetFont(-1, 9, 600, 0, "Arial")

$theitem = GUICtrlCreateTreeViewItem ("First",$TreeView2)
GUICtrlSetData( $thelabel, "Description of first")
$theitem = GUICtrlCreateTreeViewItem ("Second",$TreeView2)
GUICtrlSetData( $thelabel, "Description of second")

EDIT: code mistake.

Edited by Thetan

Share this post


Link to post
Share on other sites
BrettF

This is probably a simple fix, but here is my question. I would like to Create a treeview inside a tab and whenever you click on a different treeview item it will display something different. I'm not sure if this is even close to right, thanks for looking.

$TabSheet2 = GUICtrlCreateTabItem("List")
$TreeView2 = GUICtrlCreateTreeView(8, 48, 137, 217)
GUICtrlSetFont(-1, 9, 600, 0, "Arial")

$theitem = GUICtrlCreateTreeViewItem ("First",$TreeView2)
GUICtrlSetData( $thelabel, "Description of first")
$theitem = GUICtrlCreateTreeViewItem ("Second",$TreeView2)
GUICtrlSetData( $thelabel, "Description of second")

EDIT: code mistake.

Need more infomation on what you want to achieve....

Share this post


Link to post
Share on other sites
Thetan

Ok, basically I just want a simple treeview that displays names of things and when you click on any of the names it will display a description of that item. Maybe a treeview isn't the best way to go, but it seemed easy at first.

Posted Image

I think I may have found something like it in the examples, but I cant seem to figure it out.

Share this post


Link to post
Share on other sites
rasim

This?

#include <GuiConstants.au3>
#include <GuiTreeView.au3>
#include <WinAPI.au3>

$hGUI = GUICreate("Test", 300, 200)

$hTab = GUICtrlCreateTab(10, 10, 280, 180)

$TabItem1 = GUICtrlCreateTabItem("TabItem 1")

$hTreeView1 = GUICtrlCreateTreeView(25, 40, 100, 140, -1, $WS_EX_CLIENTEDGE)

For $i = 1 To 10
    GUICtrlCreateTreeViewItem("Item" & $i, $hTreeView1)
Next

$hEdit1 = GUICtrlCreateEdit("", 150, 80, 110, 60, $ES_WANTRETURN)

GUICtrlCreateTabItem("")

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $tNMHDR, $IdFrom, $iCode
    
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $IdFrom = DllStructGetData($tNMHDR, "IdFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    
    Switch $IdFrom
        Case $hTreeView1
            Switch $iCode
                Case $NM_CLICK
                    Local $tPoint = _WinAPI_GetMousePos(True, GUICtrlGetHandle($hTreeView1))
                    
                    Local $iX = DllStructGetData($tPoint, "X")
                    Local $iY = DllStructGetData($tPoint, "Y")
                    
                    Local $iItem = _GUICtrlTreeView_HitTestItem($hTreeView1, $iX, $iY)
                    
                    If $iItem <> 0 Then
                        Local $iText = _GUICtrlTreeView_GetText($hTreeView1, $iItem)
                        GUICtrlSetData($hEdit1, $iText)
                    EndIf
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc

Share this post


Link to post
Share on other sites
Thetan

No that's close but not it. I'm sorry I don't think I explained myself well enough.

I would need to manually create the name for each item, and manually write a description.

How can I link a description with a TreeView Item so that when the Item is clicked the Description is shown?

I will try to use your example and fix it to my needs. Thanks for the help.

GUICtrlCreateTreeViewItem("Car" & 1, $hTreeView1)
GUICtrlCreateTreeViewItem("SUV" & 2, $hTreeView1)
GUICtrlCreateTreeViewItem("Truck" & 2, $hTreeView1)
GUICtrlCreateTreeViewItem("Motorcycle" & 4, $hTreeView1)


GUICtrlSetData( $thelabel, "Description of Car")
GUICtrlSetData( $thelabel, "Description of SUV")
GUICtrlSetData( $thelabel, "Description of Truck")
GUICtrlSetData( $thelabel, "Description of Motorcycle")

Share this post


Link to post
Share on other sites
GaryFrost

#include <GuiConstants.au3>
#include <GuiTreeView.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

Global $aTreeItemDesc[4] = ["Description of Car", "Description of SUV", "Description of Truck", "Description of Motorcycle"]

$hGUI = GUICreate("Test", 300, 200)

$hTab = GUICtrlCreateTab(10, 10, 280, 180)

$TabItem1 = GUICtrlCreateTabItem("TabItem 1")

$hTreeView1 = GUICtrlCreateTreeView(25, 40, 100, 140, -1, $WS_EX_CLIENTEDGE)

GUICtrlCreateTreeViewItem("Car" & 1, $hTreeView1)
GUICtrlCreateTreeViewItem("SUV" & 2, $hTreeView1)
GUICtrlCreateTreeViewItem("Truck" & 2, $hTreeView1)
GUICtrlCreateTreeViewItem("Motorcycle" & 4, $hTreeView1)

$hEdit1 = GUICtrlCreateEdit("", 150, 80, 110, 60, $ES_WANTRETURN)

GUICtrlCreateTabItem("")

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $tNMHDR, $IdFrom, $iCode
   
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $IdFrom = DllStructGetData($tNMHDR, "IdFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
   
    Switch $IdFrom
        Case $hTreeView1
            Switch $iCode
                Case $NM_CLICK
                    Local $tPoint = _WinAPI_GetMousePos(True, GUICtrlGetHandle($hTreeView1))
                   
                    Local $iX = DllStructGetData($tPoint, "X")
                    Local $iY = DllStructGetData($tPoint, "Y")
                   
                    Local $iItem = _GUICtrlTreeView_HitTestItem($hTreeView1, $iX, $iY)
                   
                    If $iItem <> 0 Then
                        GUICtrlSetData($hEdit1, $aTreeItemDesc[_GUICtrlTreeView_Index($hTreeView1, $iItem)])
                    EndIf
            EndSwitch
    EndSwitch
   
    Return $GUI_RUNDEFMSG
EndFunc


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites
Thetan

Thanks for all of the help guys, that works perfect Gary.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×