Jump to content

Combine List View and Tree View


Recommended Posts

I'm not exactly the greatest with GUI's but i started tinkering around with this idea, and I was wondering if there was a way to combine a tree view and and a list view so that I could have a tree view in the first column and data in 2 more columns.

It doesn't have to be done any certain way as long as it looks good, and when you scroll down through the data everything will still line up correctly by each row.

All ideas suggestions welcome!

Thanks

Lurch

Edit: Spelling

Edited by LurchMan

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

  • Moderators

LurchMan,

This is far from perfect, but it does synchronise the TreeView and ListView scrolling.

Elements that certainly need to improve: more rapid "following" by the other control (perhaps by using GUIRegisterMsg?); getting the line spacing/font size right so that the horizontal alignment is correct.

However, it gives you something to start your project - and it might just spur others into producing something better. ;-)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>
#include <GuiListView.au3>
#include <Misc.au3>

Global Const $iMax = 40

$hGUI = GUICreate("Synchro Pair", 195, 140, -1, -1)

$hTreeView = GUICtrlCreateTreeView(10, 5, 85, 120, -1, $WS_EX_CLIENTEDGE)
Global $aTV_Items[$iMax]
_GUICtrlTreeView_BeginUpdate($hTreeView)
For $i = 0 To $iMax - 1
    $aTV_Items[$i] = _GUICtrlTreeView_Add($hTreeView, 0, $i + 1)
Next
_GUICtrlTreeView_EndUpdate($hTreeView)

$hListView = GUICtrlCreateListView(" ", 100, 5, 85, 120, $LVS_NOCOLUMNHEADER)
For $i = 1 To $iMax
    GUICtrlCreateListViewItem($i, $hListView)
Next

GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $GUI_EVENT_PRIMARYDOWN
            While _IsPressed(01)
                Sleep(10)
            WEnd

            $aInfo = GUIGetCursorInfo($hGUI)

            $hTV_Top = _GUICtrlTreeView_GetFirstVisible($hTreeView)
            $iTV_TopIndex = _ArraySearch($aTV_Items, $hTV_Top)

            If _GUICtrlListView_GetTopIndex($hListView) > $iTV_TopIndex Then

                If $aInfo[4] = $hListView Then

                    $iTV_BotIndex = _GUICtrlListView_GetTopIndex($hListView) + 5
                    If $iTV_BotIndex > $iMax - 1 Then $iTV_BotIndex = $iMax - 1
                    _GUICtrlTreeView_EnsureVisible($hTreeView, $aTV_Items[$iTV_BotIndex])

                ElseIf $aInfo[4] = $hTreeView Then

                    _GUICtrlListView_EnsureVisible($hListView, $iTV_TopIndex)

                EndIf

            ElseIf $iTV_TopIndex > _GUICtrlListView_GetTopIndex($hListView) Then

                If $aInfo[4] = $hListView Then

                    _GUICtrlTreeView_EnsureVisible($hTreeView, $aTV_Items[_GUICtrlListView_GetTopIndex($hListView)])

                ElseIf $aInfo[4] = $hTreeView Then

                    $iLV_BotIndex = $iTV_TopIndex + 5
                    If $iLV_BotIndex > $iMax - 1 Then $iLV_BotIndex = $iMax - 1
                    _GUICtrlListView_EnsureVisible($hListView, $iLV_BotIndex)

                EndIf

            EndIf

        EndSwitch

WEnd

I look forward to seeing the finished article. Have fun. :-)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...