Jump to content
Sign in to follow this  
lsakizada

How to make treeview item selected on selecting Tab item?

Recommended Posts

lsakizada

How to make treeview item selected on selecting Tab item?

for example: If clicking on tabitem TabSheet2 then $TreeView1_item2 will be selected in the enclose code bellow

#include <GUIConstants.au3>
#include <GuiTab.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AForm1", 524, 259, 193, 115)
$TreeView1 = GUICtrlCreateTreeView(16, 24, 121, 185)
$TreeView1_item1=GUICtrlCreateTreeViewItem("TabSheet1", $TreeView1)
$TreeView1_item2=GUICtrlCreateTreeViewItem("TabSheet2", $TreeView1)


$Tab1 = GUICtrlCreateTab(176, 16, 289, 193)
$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
$Button1 = GUICtrlCreateButton("Button 1", 200, 145, 75, 25, 0)

$TabSheet2 = GUICtrlCreateTabItem("TabSheet2")
$Button2 = GUICtrlCreateButton("Button 2", 300, 145, 75, 25, 0)

GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $TreeView1_item1
            GuiSwitch($Form1,$TabSheet1) 
            GUICtrlCreateTabItem("")

        case $TreeView1_item2
            GuiSwitch($Form1,$TabSheet2) 
            GUICtrlCreateTabItem("")

    EndSwitch
WEnd

Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites
martin

How to make treeview item selected on selecting Tab item?

for example: If clicking on tabitem TabSheet2 then $TreeView1_item2 will be selected in the enclose code bellow

#include <GUIConstants.au3>
#include <GuiTab.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AForm1", 524, 259, 193, 115)
$TreeView1 = GUICtrlCreateTreeView(16, 24, 121, 185)
$TreeView1_item1=GUICtrlCreateTreeViewItem("TabSheet1", $TreeView1)
$TreeView1_item2=GUICtrlCreateTreeViewItem("TabSheet2", $TreeView1)
$Tab1 = GUICtrlCreateTab(176, 16, 289, 193)
$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
$Button1 = GUICtrlCreateButton("Button 1", 200, 145, 75, 25, 0)

$TabSheet2 = GUICtrlCreateTabItem("TabSheet2")
$Button2 = GUICtrlCreateButton("Button 2", 300, 145, 75, 25, 0)

GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $TreeView1_item1
            GuiSwitch($Form1,$TabSheet1) 
            GUICtrlCreateTabItem("")

        case $TreeView1_item2
            GuiSwitch($Form1,$TabSheet2) 
            GUICtrlCreateTabItem("")

    EndSwitch
WEnd
Add this to the switch/endswitch loop

Case $Tab1

GUICtrlSetState($ItemYouWantToHaveSelected, $GUI_FOCUS)


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
lsakizada

Add this to the switch/endswitch loop

Case $Tab1

GUICtrlSetState($ItemYouWantToHaveSelected, $GUI_FOCUS)

This is not working as I have been asked.

I want the TABITEM to make specific TREEVIEW item selected. Not when clicking on Tab1!

What you posted is when clicking on any parts of the Tab1 the treeview item will be selected.


Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites
PsaltyDS

How about:

#include <GUIConstants.au3>
#include <GuiTab.au3>
#include <GuiTreeView.au3>

$Form1 = GUICreate("AForm1", 524, 259, 193, 115)
$TreeView1 = GUICtrlCreateTreeView(16, 24, 121, 185)
$TreeView1_item1 = GUICtrlCreateTreeViewItem("TabSheet1", $TreeView1)
$TreeView1_item2 = GUICtrlCreateTreeViewItem("TabSheet2", $TreeView1)


$Tab1 = GUICtrlCreateTab(176, 16, 289, 193)
$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
$Button1 = GUICtrlCreateButton("Button 1", 200, 145, 75, 25, 0)

$TabSheet2 = GUICtrlCreateTabItem("TabSheet2")
$Button2 = GUICtrlCreateButton("Button 2", 300, 145, 75, 25, 0)

GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $TreeView1_item1
            GUISwitch($Form1, $TabSheet1)
        Case $TreeView1_item2
            GUISwitch($Form1, $TabSheet2)
        Case $Tab1
            ; The TabItems are numbered from 0.
            If GUICtrlRead($Tab1) = 0 Then
                _GUICtrlTreeViewSetState($TreeView1, $TreeView1_item1, $TVIS_SELECTED + $TVIS_BOLD, 0)
                _GUICtrlTreeViewSetState($TreeView1, $TreeView1_item2, 0, $TVIS_SELECTED + $TVIS_BOLD)
            ElseIf GUICtrlRead($Tab1) = 1 Then
                _GUICtrlTreeViewSetState($TreeView1, $TreeView1_item1, 0, $TVIS_SELECTED + $TVIS_BOLD)
                _GUICtrlTreeViewSetState($TreeView1, $TreeView1_item2, $TVIS_SELECTED + $TVIS_BOLD, 0)
            EndIf
    EndSwitch
WEnd

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
lsakizada

How about:

#include <GUIConstants.au3>
#include <GuiTab.au3>
#include <GuiTreeView.au3>

$Form1 = GUICreate("AForm1", 524, 259, 193, 115)
$TreeView1 = GUICtrlCreateTreeView(16, 24, 121, 185)
$TreeView1_item1 = GUICtrlCreateTreeViewItem("TabSheet1", $TreeView1)
$TreeView1_item2 = GUICtrlCreateTreeViewItem("TabSheet2", $TreeView1)
$Tab1 = GUICtrlCreateTab(176, 16, 289, 193)
$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
$Button1 = GUICtrlCreateButton("Button 1", 200, 145, 75, 25, 0)

$TabSheet2 = GUICtrlCreateTabItem("TabSheet2")
$Button2 = GUICtrlCreateButton("Button 2", 300, 145, 75, 25, 0)

GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $TreeView1_item1
            GUISwitch($Form1, $TabSheet1)
        Case $TreeView1_item2
            GUISwitch($Form1, $TabSheet2)
        Case $Tab1
            ; The TabItems are numbered from 0.
            If GUICtrlRead($Tab1) = 0 Then
                _GUICtrlTreeViewSetState($TreeView1, $TreeView1_item1, $TVIS_SELECTED + $TVIS_BOLD, 0)
                _GUICtrlTreeViewSetState($TreeView1, $TreeView1_item2, 0, $TVIS_SELECTED + $TVIS_BOLD)
            ElseIf GUICtrlRead($Tab1) = 1 Then
                _GUICtrlTreeViewSetState($TreeView1, $TreeView1_item1, 0, $TVIS_SELECTED + $TVIS_BOLD)
                _GUICtrlTreeViewSetState($TreeView1, $TreeView1_item2, $TVIS_SELECTED + $TVIS_BOLD, 0)
            EndIf
    EndSwitch
WEnd

:)

Much better! :D

but still the slected rectangle can be displayed on both tree items.


Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites
martin

This is not working as I have been asked.

I want the TABITEM to make specific TREEVIEW item selected. Not when clicking on Tab1!

What you posted is when clicking on any parts of the Tab1 the treeview item will be selected.

Calm down a bit. Your response comes across in such a way that I have considered ignoring you.

I was just showing you what to do to highlight an item. If you are worried about clicking anywhere on TAB1 making th eitem get selected again then you just have to do something about it. Like this maybe

Case $Tab1

If _GUICtrlTabGetCurFocus($tab1) = 0 Then;if the first tab is selected

GUICtrlSetState($aboutitem, $GUI_FOCUS)

EndIf

I'd be interested to know if this is what you want.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
lsakizada

Calm down a bit. Your response comes across in such a way that I have considered ignoring you.

I was just showing you what to do to highlight an item. If you are worried about clicking anywhere on TAB1 making th eitem get selected again then you just have to do something about it. Like this maybe

Case $Tab1

If _GUICtrlTabGetCurFocus($tab1) = 0 Then;if the first tab is selected

GUICtrlSetState($aboutitem, $GUI_FOCUS)

EndIf

I'd be interested to know if this is what you want.

Yes, looks like yours code and the code that PsaltyDS posted is what I was looking for, just need a little touch to make it working.

Sorry if you understand me wrong.

I do not have good english as you.

In the place where I am living the people are speaking such directly way.


Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites
martin

Yes, looks like yours code and the code that PsaltyDS posted is what I was looking for, just need a little touch to make it working.

Sorry if you understand me wrong.

I do not have good english as you.

In the place where I am living the people are speaking such directly way.

That ok. I understand and I take back any critism I made! My English is far from perfect anyway. Gald I could help a bit.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
lsakizada

Fianly, it is done as I wanted. It might be usefull for other users (beginners :)) to handle Tabs and TreeView items.

#include <GUIConstants.au3>
#include <GuiTab.au3>
#include <GuiTreeview.au3>

$Form1 = GUICreate("AForm1", 524, 259, 193, 115)
$TreeView1 = GUICtrlCreateTreeView(16, 24, 121, 185)
$TreeView1_item1=GUICtrlCreateTreeViewItem("TabSheet1", $TreeView1)
$TreeView1_item2=GUICtrlCreateTreeViewItem("TabSheet2", $TreeView1)
$TreeView1_item3=GUICtrlCreateTreeViewItem("TabSheet3", $TreeView1)
$Tab1 = GUICtrlCreateTab(176, 16, 289, 193)
$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
$Button1 = GUICtrlCreateButton("Button 1", 200, 145, 75, 25, 0)
$TabSheet2 = GUICtrlCreateTabItem("TabSheet2")
$Button2 = GUICtrlCreateButton("Button 2", 300, 145, 75, 25, 0)
$TabSheet3 = GUICtrlCreateTabItem("TabSheet3")
$Button3 = GUICtrlCreateButton("Button 3", 350, 145, 75, 25, 0)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $TreeView1_item1
            GuiSwitch($Form1,$TabSheet1) 
                    _GUICtrlTreeViewSetState($TreeView1, $TreeView1_item1, $TVIS_SELECTED + $TVIS_BOLD, 0)
                    _GUICtrlTreeViewSetState($TreeView1, $TreeView1_item2, 0, $TVIS_SELECTED + $TVIS_BOLD)
                    _GUICtrlTreeViewSetState($TreeView1, $TreeView1_item3, 0, $TVIS_SELECTED + $TVIS_BOLD)
                GUICtrlCreateTabItem("")
            
        case $TreeView1_item2
                GuiSwitch($Form1,$TabSheet2)
                _GUICtrlTreeViewSetState($TreeView1, $TreeView1_item1, 0, $TVIS_SELECTED + $TVIS_BOLD)
                    _GUICtrlTreeViewSetState($TreeView1, $TreeView1_item2, $TVIS_SELECTED + $TVIS_BOLD, 0)
                    _GUICtrlTreeViewSetState($TreeView1, $TreeView1_item3, 0, $TVIS_SELECTED + $TVIS_BOLD)      
            GUICtrlCreateTabItem("")
        case $TreeView1_item3
                GuiSwitch($Form1,$TabSheet3)
                _GUICtrlTreeViewSetState($TreeView1, $TreeView1_item1, 0, $TVIS_SELECTED + $TVIS_BOLD)
                    _GUICtrlTreeViewSetState($TreeView1, $TreeView1_item2, 0, $TVIS_SELECTED + $TVIS_BOLD)
                    _GUICtrlTreeViewSetState($TreeView1, $TreeView1_item3, $TVIS_SELECTED + $TVIS_BOLD, 0)      
            GUICtrlCreateTabItem("")
        Case $Tab1
           ; The TabItems are numbered from 0.
            Local $TreeItemClicked = GUICtrlRead($Tab1)
            Switch $TreeItemClicked
                case 0
                
                    _GUICtrlTreeViewSetState($TreeView1, $TreeView1_item1, $TVIS_SELECTED + $TVIS_BOLD, 0)
                    _GUICtrlTreeViewSetState($TreeView1, $TreeView1_item2, 0, $TVIS_SELECTED + $TVIS_BOLD)
                    _GUICtrlTreeViewSetState($TreeView1, $TreeView1_item3, 0, $TVIS_SELECTED + $TVIS_BOLD)
                    
                Case 1
                    _GUICtrlTreeViewSetState($TreeView1, $TreeView1_item1, 0, $TVIS_SELECTED + $TVIS_BOLD)
                    _GUICtrlTreeViewSetState($TreeView1, $TreeView1_item2, $TVIS_SELECTED + $TVIS_BOLD, 0)
                    _GUICtrlTreeViewSetState($TreeView1, $TreeView1_item3, 0, $TVIS_SELECTED + $TVIS_BOLD)                  
                
                Case 2
                    _GUICtrlTreeViewSetState($TreeView1, $TreeView1_item1, 0, $TVIS_SELECTED + $TVIS_BOLD)
                    _GUICtrlTreeViewSetState($TreeView1, $TreeView1_item2, 0, $TVIS_SELECTED + $TVIS_BOLD)
                    _GUICtrlTreeViewSetState($TreeView1, $TreeView1_item3, $TVIS_SELECTED + $TVIS_BOLD, 0)  
                    
            EndSwitch
    EndSwitch
WEnd
Edited by lsakizada

Be Green Now or Never (BGNN)!

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  

×