Jump to content
DigDeep

ListView with TEXT URL + Single cell highlighting on click

Recommended Posts

DigDeep

I am looking for 3 things here.

1. Only the Header, Row 1 & Row 2 texts should be bold and not the complete Listview.

2. The Text in _GUICtrlListView_AddItem +  _GUICtrlListView_AddSubItem showing as underlined, as a Hyperlink Text shows.

3. When a cell is clicked, only the specific cell should be highlighted and not the complete row, so that clicking on the single cell I can get the desired action. For sample, clicking on a cell will get a msgbox.

 

Can someone please help here.

Thanks.

 

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>

Example()

Func Example()
    Local $hImage, $idListview

    ; Create GUI
    GUICreate("ListView Add Column", 400, 300)
    $idListview = GUICtrlCreateListView("", 2, 2, 394, 268)

    ; Enable extended control styles
    _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
    GUISetState(@SW_SHOW)

    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "", 110)
    _GUICtrlListView_AddColumn($idListview, "Column 1", 110)
    _GUICtrlListView_AddColumn($idListview, "Column 2", 110)

    ; Add items
    _GUICtrlListView_AddItem($idListview, "Row 1", 0)
    _GUICtrlListView_AddSubItem($idListview, 0, "Row 1: Col 1", 1)
    _GUICtrlListView_AddSubItem($idListview, 0, "Row 1: Col 2", 2)

    _GUICtrlListView_AddItem($idListview, "Row 2", 1)
    _GUICtrlListView_AddSubItem($idListview, 1, "Row 2: Col 1", 1)
    _GUICtrlListView_AddSubItem($idListview, 1, "Row 2: Col 2", 2)



    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    WEnd
EndFunc   ;==>Example

 

Share this post


Link to post
Share on other sites
Melba23

DigDeep,

My GUIListViewEx UDF (look in my sig for the link) will let you do some of those things - take a look at Example 6 in the zip.

More than happy to work with you to get something as close as possible - but it will have to wait a few days as I am off for a few days from tomorrow (Xmas pressie was tickets to the Steven Wilson concert in London).

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Zedna
4 hours ago, DigDeep said:

I am looking for 3 things here.

3. When a cell is clicked, only the specific cell should be highlighted and not the complete row, so that clicking on the single cell I can get the desired action. For sample, clicking on a cell will get a msgbox.

 

About 3) look here for the solution by LarsJ

 

Share this post


Link to post
Share on other sites
DigDeep

Thanks @Zedna

I tried the same and it looks good now.

Share this post


Link to post
Share on other sites
DigDeep

@Zedna / @Melba23 So I worked a bit on the above case and was able to get so far. Clicking on the cells, I am able to get the display. 

The data in the cells are coming from different file locations. Is there a way, I can get the files or directory opened in place of getting the MsgBox?

eg: clicking on SubItem 1 it will open the @DesktopDir & "\Test1"

SubItem 2 will open the @DesktopDir & "\Test2"

SubItem 3 will open the @DesktopDir & "\Test3"

SubItem 4 will open the @DesktopDir & "\Test4"

 

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <GuiConstants.au3>;Inclusion file for the GUI interface controls
#include <WinAPI.au3>
#include <FontConstants.au3>

Global $GUI, $hListview, $aHit[2] = [-1, -1] ; $aHit contains row & col of marked cell
Global $iButton = 9999


Example()

Func Example()
    Local $hImage, $GUI

    ; Create GUI
    $GUI = GUICreate("ListView Add Column", 400, 300)
    $GUI = GUICtrlCreateListView("", 2, 2, 394, 240)
    $hListview = GUICtrlGetHandle($GUI)

    ; Enable extended control styles
    _GUICtrlListView_SetExtendedListViewStyle($GUI, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))

    Local $iButton = GUICtrlCreateButton("OK", 160, 250, 70, 20, $BS_DEFPUSHBUTTON)

    Local $R1C1 = FileRead(@DesktopDir & "\Test1\test1.txt")
    Local $R1C1_result = $R1C1

    Local $R1C2 = FileRead(@DesktopDir & "\Test2\test2.txt")
    Local $R1C2_result = $R1C2

    Local $R2C1 = FileRead(@DesktopDir & "\Test3\test3.txt")
    Local $R2C1_result = $R2C1

    Local $R2C2 = FileRead(@DesktopDir & "\Test4\test3.txt")
    Local $R2C2_result = $R2C2

    ; Add columns
    _GUICtrlListView_AddColumn($GUI, "", 110)
    _GUICtrlListView_AddColumn($GUI, "Column 1", 110)
    _GUICtrlListView_AddColumn($GUI, "Column 2", 110)

    ; Add items
    _GUICtrlListView_AddItem($GUI, "Row 1", 0)
    _GUICtrlListView_AddSubItem($GUI, 0, 12, 1) ; The data comes from $R1C1_result
    _GUICtrlListView_AddSubItem($GUI, 0, 48, 2) ; The data comes from $R1C2_result

    _GUICtrlListView_AddItem($GUI, "Row 2", 1)
    _GUICtrlListView_AddSubItem($GUI, 1, 85, 1) ; The data comes from $R2C1_result
    _GUICtrlListView_AddSubItem($GUI, 1, 120, 2) ; The data comes from $R2C2_result

    GUISetState(@SW_SHOW)

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit

            Case $iButton
                Local $GetResults = _GUICtrlListView_GetItemText($hListview, $aHit[0], $aHit[1])
                    MsgBox(0, "", $GetResults)
        EndSwitch
    WEnd
EndFunc   ;==>Example




Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $tNMHDR, $hWndFrom, $iCode
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hListview
            Switch $iCode
                Case $LVN_ITEMCHANGED
                    Local $tNMLISTVIEW, $iItem, $aInfo
                    $tNMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam)
                    $iItem = DllStructGetData($tNMLISTVIEW, "Item")
                    _GUICtrlListView_SetItemSelected($hListview, $iItem, False)
                    _GUICtrlListView_SetItemState($hListview, $iItem, 0, $LVIS_FOCUSED)
                    Local $aInfo = GUIGetCursorInfo($GUI)
                    If $aInfo[2] Then
                        $aInfo = _GUICtrlListView_SubItemHitTest($hListview, $aInfo[0] - 2, $aInfo[1] - 2) ; Upper left = ( 2, 2 )
                        If $aInfo[0] > -1 And $aInfo[1] > -1 And $aInfo[0] = $iItem Then
                            If $aHit[0] > -1 Then _GUICtrlListView_RedrawItems($hListview, $aHit[0], $aHit[0])
                            If $aHit[0] <> $aInfo[0] Or $aHit[1] <> $aInfo[1] Then
                                $aHit[0] = $aInfo[0] ; Row
                                $aHit[1] = $aInfo[1] ; Col
                            Else
                                $aHit[0] = -1 ; Row
                                $aHit[1] = -1 ; Col
                            EndIf
                            _GUICtrlListView_RedrawItems($hListview, $iItem, $iItem)
                        EndIf
                    EndIf

                Case $NM_CUSTOMDRAW
                    Local $tNMLVCUSTOMDRAW = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
                    Local $dwDrawStage = DllStructGetData($tNMLVCUSTOMDRAW, "dwDrawStage")
                    Switch $dwDrawStage ; Holds a value that specifies the drawing stage
                        Case $CDDS_PREPAINT ; Before the paint cycle begins
                            Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any ITEM-related drawing operations
                        Case $CDDS_ITEMPREPAINT ; Before painting an item
                            Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window of any SUBITEM-related drawing operations
                        Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM) ; Before painting a subitem
                            Local $dwItemSpec = DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec") ; Item index
                            Local $iSubItem = DllStructGetData($tNMLVCUSTOMDRAW, "iSubItem") ; Subitem index
                            Local $uItemState = DllStructGetData($tNMLVCUSTOMDRAW, "uItemState") ; Item state
                            If $dwItemSpec = $aHit[0] Then ; Marked row
                                Switch $iSubItem
                                    Case $aHit[1] ; Marked column
                                        DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", 0xFFFFFF) ; Forecolor white
                                        DllStructSetData($tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600) ; Backcolor dark blue, BGR

                                    Case Else ; Other columns
                                        DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", 0x000000) ; Forecolor black
                                        DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF) ; Backcolor white
                                EndSwitch
                            Else ; Other rows
                                DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", 0x000000)
                                DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF)
                            EndIf
                            Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

Share this post


Link to post
Share on other sites
Zedna

Here it is, also fixed some of yours errrors:

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <GuiStatusBar.au3>
#include <GuiConstants.au3>;Inclusion file for the GUI interface controls
#include <WinAPI.au3>
#include <FontConstants.au3>

Global Const $WM_LV_CLICK = $WM_USER + 1

Global $Form, $GUI, $hListview, $StatusBar1, $aHit[2] = [-1, -1] ; $aHit contains row & col of marked cell
Global $iButton
Global $files[3][3]

$files[1][1] = @DesktopDir & "\Test1\test1.txt"
$files[1][2] = @DesktopDir & "\Test2\test2.txt"
$files[2][1] = @DesktopDir & "\Test3\test3.txt"
$files[2][2] = @DesktopDir & "\Test4\test3.txt"

Example()

Func Example()

    ; Create GUI
    $Form = GUICreate("ListView Add Column", 400, 300)
    $GUI = GUICtrlCreateListView("", 2, 2, 394, 240)
    $hListview = GUICtrlGetHandle($GUI)

    ; Enable extended control styles
    _GUICtrlListView_SetExtendedListViewStyle($GUI, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))

    Local $iButton = GUICtrlCreateButton("OK", 160, 250, 70, 20, $BS_DEFPUSHBUTTON)

    Local $R1C1 = FileRead($files[1][1])
    Local $R1C1_result = $R1C1

    Local $R1C2 = FileRead($files[1][2])
    Local $R1C2_result = $R1C2

    Local $R2C1 = FileRead($files[2][1])
    Local $R2C1_result = $R2C1

    Local $R2C2 = FileRead($files[2][2])
    Local $R2C2_result = $R2C2

    ; Add columns
    _GUICtrlListView_AddColumn($GUI, "", 110)
    _GUICtrlListView_AddColumn($GUI, "Column 1", 110)
    _GUICtrlListView_AddColumn($GUI, "Column 2", 110)

    ; Add items
    _GUICtrlListView_AddItem($GUI, "Row 1", 0)
    _GUICtrlListView_AddSubItem($GUI, 0, 12, 1) ; The data comes from $R1C1_result
    _GUICtrlListView_AddSubItem($GUI, 0, 48, 2) ; The data comes from $R1C2_result

    _GUICtrlListView_AddItem($GUI, "Row 2", 1)
    _GUICtrlListView_AddSubItem($GUI, 1, 85, 1) ; The data comes from $R2C1_result
    _GUICtrlListView_AddSubItem($GUI, 1, 120, 2) ; The data comes from $R2C2_result

    $StatusBar1 = _GUICtrlStatusBar_Create($Form)
    GUISetState(@SW_SHOW)

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    GUIRegisterMsg($WM_LV_CLICK, "WM_LV_CLICK") ; WM_USER

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit

            Case $iButton
                Local $GetResults = _GUICtrlListView_GetItemText($hListview, $aHit[0], $aHit[1])
                    MsgBox(0, "", $GetResults)
        EndSwitch
    WEnd
EndFunc   ;==>Example


Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $tNMHDR, $hWndFrom, $iCode
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hListview
            Switch $iCode
                Case $LVN_ITEMCHANGED
                    Local $tNMLISTVIEW, $iItem, $aInfo
                    $tNMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam)
                    $iItem = DllStructGetData($tNMLISTVIEW, "Item")
                    _GUICtrlListView_SetItemSelected($hListview, $iItem, False)
                    _GUICtrlListView_SetItemState($hListview, $iItem, 0, $LVIS_FOCUSED)
                    Local $aInfo = GUIGetCursorInfo($Form)
                    If $aInfo[2] Then
                        $aInfo = _GUICtrlListView_SubItemHitTest($hListview, $aInfo[0] - 2, $aInfo[1] - 2) ; Upper left = ( 2, 2 )
                        If $aInfo[0] > -1 And $aInfo[1] > -1 And $aInfo[0] = $iItem Then
                            If $aHit[0] > -1 Then _GUICtrlListView_RedrawItems($hListview, $aHit[0], $aHit[0])
                            If $aHit[0] <> $aInfo[0] Or $aHit[1] <> $aInfo[1] Then
                                $aHit[0] = $aInfo[0] ; Row
                                $aHit[1] = $aInfo[1] ; Col
                            Else
                                $aHit[0] = -1 ; Row
                                $aHit[1] = -1 ; Col
                            EndIf
                            _GUICtrlListView_RedrawItems($hListview, $iItem, $iItem)
                        EndIf
                    EndIf

                Case $NM_CUSTOMDRAW
                    Local $tNMLVCUSTOMDRAW = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
                    Local $dwDrawStage = DllStructGetData($tNMLVCUSTOMDRAW, "dwDrawStage")
                    Switch $dwDrawStage ; Holds a value that specifies the drawing stage
                        Case $CDDS_PREPAINT ; Before the paint cycle begins
                            Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any ITEM-related drawing operations
                        Case $CDDS_ITEMPREPAINT ; Before painting an item
                            Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window of any SUBITEM-related drawing operations
                        Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM) ; Before painting a subitem
                            Local $dwItemSpec = DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec") ; Item index
                            Local $iSubItem = DllStructGetData($tNMLVCUSTOMDRAW, "iSubItem") ; Subitem index
                            Local $uItemState = DllStructGetData($tNMLVCUSTOMDRAW, "uItemState") ; Item state
                            If $dwItemSpec = $aHit[0] Then ; Marked row
                                Switch $iSubItem
                                    Case $aHit[1] ; Marked column
                                        DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", 0xFFFFFF) ; Forecolor white
                                        DllStructSetData($tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600) ; Backcolor dark blue, BGR

                                    Case Else ; Other columns
                                        DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", 0x000000) ; Forecolor black
                                        DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF) ; Backcolor white
                                EndSwitch
                            Else ; Other rows
                                DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", 0x000000)
                                DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF)
                            EndIf
                            Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors
                    EndSwitch

            EndSwitch
    EndSwitch

    If $hWnd = $Form Then
        If $wParam = $GUI And $iCode = $NM_CLICK Then
            $NMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam)
            $item = DllStructGetData($NMLISTVIEW, 'Item')
            $subitem = DllStructGetData($NMLISTVIEW, 'SubItem')
            _SendMessage($Form, $WM_LV_CLICK, $item, $subitem)
;~          _GUICtrlStatusBar_SetText($StatusBar1, 'Row:' & $item & ' Col:' & $subitem)
        EndIf
    EndIf

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func WM_LV_CLICK($hWnd, $MsgID, $wParam, $lParam)
    $item = Number($wParam)
    $subitem = Number($lParam)

    If $item = -1 Then Return _GUICtrlStatusBar_SetText($StatusBar1, '')

    $value = _GUICtrlListView_GetItemText($GUI, $item, $subitem)
    If $value == '' Then Return _GUICtrlStatusBar_SetText($StatusBar1, '')

    $item += 1 ; LV items are from 0, my array $files[] is from 1
    $file = $files[$item][$subitem]
    _GUICtrlStatusBar_SetText($StatusBar1, 'Row:' & $item & ' Col:' & $subitem & ' Value:' & $value & ' File:' & $file)
;~  If $file <> '' Then ShellExecute($file)
EndFunc

 

Share this post


Link to post
Share on other sites
DigDeep

Thanks @Zedna.

I also got it fixed by giving the file location as variables and then calling them in the while. But your solution is looking decent enough and I will see how to adjust this here.

I have observed another issue though. This part of code works perfectly fine when running outside as it is above. But When I am integrating this inside another GUI, which has way too many controls, I am not able to:

1. Click on any of the Cells. I found that the $hListview = GUICtrlGetHandle($GUI) is blocking the list view click. When I am removing this line, I can click but the complete row is highlighting. Because of which the $iButton does not do anything.

2. If I am using the Listview as it is coded above, I cannot Hide it when not needed. (Clicking on some other button should hide the complete listview.)

So, I had to re-arrange the complete List view instead of AddColumn, AddItem & AddSubItem to GUICtrlCreateListView and GUICtrlCreateListViewItem.

 

Can you please suggest if there's any other alternative to click on individual cells or fix to point 1?

As always, thanks for helping out.

Share this post


Link to post
Share on other sites
DigDeep

I don't want to have multiple GUIs' launching one after another.

Is there are way, I can get the 2nd GUI opening attached within the 1st GUI itself (like it is a lable) without the 2nd GUIs' Top toolbar?

Share this post


Link to post
Share on other sites
DigDeep

@Zedna, I am posting a sample script here which is doing the same behavior for me.

I have removed the status bar portion you had added above as I would not need that at this stage.

Could you please help in checking why are the individual cells not getting clicked and clicking on $iButton2 does not hide the Listview?

Just to add here, if you comment on the "$hListview = GUICtrlGetHandle($Child_GUI)", you will be able to click on the listview but not on individual cells. Though $iButton1 still does not do anything.

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <GuiStatusBar.au3>
#include <GuiConstants.au3>;Inclusion file for the GUI interface controls
#include <WinAPI.au3>
#include <FontConstants.au3>

Global Const $WM_LV_CLICK = $WM_USER + 1

Global $Child_GUI, $R1C1_result, $R1C2_result, $R2C1_result, $R2C2_result, $GUI, $hListview, $StatusBar1, $aHit[2] = [-1, -1] ; $aHit contains row & col of marked cell
Global $iButton1 = 9999
Global $iButton2 = 9999
Global $Get_Child_GUI2 = 9999
Global $files[3][3]

$files[1][1] = @DesktopDir & "\Test1\test1.txt"
$files[1][2] = @DesktopDir & "\Test2\test2.txt"
$files[2][1] = @DesktopDir & "\Test3\test3.txt"
$files[2][2] = @DesktopDir & "\Test4\test3.txt"


$Parent_GUI = GUICreate("Parent GUI", 640, 665, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU))
Local $Get_Default_Label_ForAll_Controls = GUICtrlCreateLabel("", 8, 16, 620, 400, $WS_BORDER)
GUICtrlSetState(-1, $GUI_DISABLE)
Local $Get_Child_GUI2 = GUICtrlCreateButton("Get GUI 2", 100, 608, 75, 25, $BS_DEFPUSHBUTTON)

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

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

        Case $Get_Child_GUI2 ; This will get the ListView visible with single cell click enable
            Example()

        Case $iButton1 ; This will allow the dir to open when single cells are clicked
                Local $GetResults = _GUICtrlListView_GetItemText($hListview, $aHit[0], $aHit[1])
                If $GetResults = $R1C1_result Then
                    ShellExecute(@DesktopDir & "\Test1\test1.txt")
                EndIf

                If $GetResults = $R1C2_result Then
                ShellExecute(@DesktopDir & "\Test1\test2.txt")
                EndIf

                If $GetResults = $R2C1_result Then
                ShellExecute(@DesktopDir & "\Test1\test3.txt")
                EndIf

                If $GetResults = $R2C2_result Then
                ShellExecute(@DesktopDir & "\Test1\test4.txt")
                EndIf

        Case $iButton2 ; This will hide the Child GUI
            GUICtrlSetState($Child_GUI, $GUI_HIDE)

    EndSwitch
WEnd



Func Example()

    ; Create GUI
;~     $Child_GUI = GUICreate("Child GUI", 400, 300)
;~     $Child_GUI = GUICtrlCreateListView("", 80, 56, 498, 350, $LVS_REPORT, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
    $Child_GUI = GUICtrlCreateListView("| Column 1| Column 2|", 80, 56, 498, 350, $LVS_REPORT, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) ; Compliance Incidents Header Label

    $hListview = GUICtrlGetHandle($Child_GUI)

    ; Enable extended control styles
;~     _GUICtrlListView_SetExtendedListViewStyle($Child_GUI, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))

    Local $iButton1 = GUICtrlCreateButton("Open Files", 376, 608, 75, 25, $BS_DEFPUSHBUTTON)

Local $iButton2 = GUICtrlCreateButton("Hide Child GUI", 472, 608, 75, 25, $BS_DEFPUSHBUTTON)

    Local $R1C1 = FileRead($files[1][1])
    Local $R1C1_result = $R1C1

    Local $R1C2 = FileRead($files[1][2])
    Local $R1C2_result = $R1C2

    Local $R2C1 = FileRead($files[2][1])
    Local $R2C1_result = $R2C1

    Local $R2C2 = FileRead($files[2][2])
    Local $R2C2_result = $R2C2

    ; Add columns
;~     _GUICtrlListView_AddColumn($Child_GUI, "", 110)
;~     _GUICtrlListView_AddColumn($Child_GUI, "Column 1", 110)
;~     _GUICtrlListView_AddColumn($Child_GUI, "Column 2", 110)

    ; Add items
    _GUICtrlListView_AddItem($Child_GUI, "Row 1", 0)
    _GUICtrlListView_AddSubItem($Child_GUI, 0, 12, 1) ; The data comes from $R1C1_result
    _GUICtrlListView_AddSubItem($Child_GUI, 0, 48, 2) ; The data comes from $R1C2_result

    _GUICtrlListView_AddItem($Child_GUI, "Row 2", 1)
    _GUICtrlListView_AddSubItem($Child_GUI, 1, 85, 1) ; The data comes from $R2C1_result
    _GUICtrlListView_AddSubItem($Child_GUI, 1, 120, 2) ; The data comes from $R2C2_result

;~     $StatusBar1 = _GUICtrlStatusBar_Create($Child_GUI)
;~     GUISetState(@SW_SHOW)

;~     GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
;~     GUIRegisterMsg($WM_LV_CLICK, "WM_LV_CLICK") ; WM_USER

;~     While 1
;~         Switch GUIGetMsg()
;~             Case $GUI_EVENT_CLOSE
;~                 Exit

;~             Case $iButton
;~                 Local $GetResults = _GUICtrlListView_GetItemText($hListview, $aHit[0], $aHit[1])
;~                     MsgBox(0, "", $GetResults)
;~         EndSwitch
;~     WEnd
EndFunc   ;==>Example


Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $tNMHDR, $hWndFrom, $iCode
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hListview
            Switch $iCode
                Case $LVN_ITEMCHANGED
                    Local $tNMLISTVIEW, $iItem, $aInfo
                    $tNMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam)
                    $iItem = DllStructGetData($tNMLISTVIEW, "Item")
                    _GUICtrlListView_SetItemSelected($hListview, $iItem, False)
                    _GUICtrlListView_SetItemState($hListview, $iItem, 0, $LVIS_FOCUSED)
                    Local $aInfo = GUIGetCursorInfo($Parent_GUI)
                    If $aInfo[2] Then
                        $aInfo = _GUICtrlListView_SubItemHitTest($hListview, $aInfo[0] - 2, $aInfo[1] - 2) ; Upper left = ( 2, 2 )
                        If $aInfo[0] > -1 And $aInfo[1] > -1 And $aInfo[0] = $iItem Then
                            If $aHit[0] > -1 Then _GUICtrlListView_RedrawItems($hListview, $aHit[0], $aHit[0])
                            If $aHit[0] <> $aInfo[0] Or $aHit[1] <> $aInfo[1] Then
                                $aHit[0] = $aInfo[0] ; Row
                                $aHit[1] = $aInfo[1] ; Col
                            Else
                                $aHit[0] = -1 ; Row
                                $aHit[1] = -1 ; Col
                            EndIf
                            _GUICtrlListView_RedrawItems($hListview, $iItem, $iItem)
                        EndIf
                    EndIf

                Case $NM_CUSTOMDRAW
                    Local $tNMLVCUSTOMDRAW = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
                    Local $dwDrawStage = DllStructGetData($tNMLVCUSTOMDRAW, "dwDrawStage")
                    Switch $dwDrawStage ; Holds a value that specifies the drawing stage
                        Case $CDDS_PREPAINT ; Before the paint cycle begins
                            Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any ITEM-related drawing operations
                        Case $CDDS_ITEMPREPAINT ; Before painting an item
                            Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window of any SUBITEM-related drawing operations
                        Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM) ; Before painting a subitem
                            Local $dwItemSpec = DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec") ; Item index
                            Local $iSubItem = DllStructGetData($tNMLVCUSTOMDRAW, "iSubItem") ; Subitem index
                            Local $uItemState = DllStructGetData($tNMLVCUSTOMDRAW, "uItemState") ; Item state
                            If $dwItemSpec = $aHit[0] Then ; Marked row
                                Switch $iSubItem
                                    Case $aHit[1] ; Marked column
                                        DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", 0xFFFFFF) ; Forecolor white
                                        DllStructSetData($tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600) ; Backcolor dark blue, BGR

                                    Case Else ; Other columns
                                        DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", 0x000000) ; Forecolor black
                                        DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF) ; Backcolor white
                                EndSwitch
                            Else ; Other rows
                                DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", 0x000000)
                                DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF)
                            EndIf
                            Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors
                    EndSwitch

            EndSwitch
    EndSwitch

;~     If $hWnd = $Child_GUI Then
;~         If $wParam = $Child_GUI And $iCode = $NM_CLICK Then
;~             $NMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam)
;~             $item = DllStructGetData($NMLISTVIEW, 'Item')
;~             $subitem = DllStructGetData($NMLISTVIEW, 'SubItem')
;~             _SendMessage($Child_GUI, $WM_LV_CLICK, $item, $subitem)
        ; _GUICtrlStatusBar_SetText($StatusBar1, 'Row:' & $item & ' Col:' & $subitem)
;~         EndIf
;~     EndIf

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

;~ Func WM_LV_CLICK($hWnd, $MsgID, $wParam, $lParam)
;~     $item = Number($wParam)
;~     $subitem = Number($lParam)

;~     If $item = -1 Then Return _GUICtrlStatusBar_SetText($StatusBar1, '')

;~     $value = _GUICtrlListView_GetItemText($GUI, $item, $subitem)
;~     If $value == '' Then Return _GUICtrlStatusBar_SetText($StatusBar1, '')

;~     $item += 1 ; LV items are from 0, my array $files[] is from 1
;~     $file = $files[$item][$subitem]
;~     _GUICtrlStatusBar_SetText($StatusBar1, 'Row:' & $item & ' Col:' & $subitem & ' Value:' & $value & ' File:' & $file)
 ; If $file <> '' Then ShellExecute($file)
;~ EndFunc

 

 

Edited by DigDeep

Share this post


Link to post
Share on other sites
DigDeep

Any luck? Adding @Melba23 too to get more helping hands.

As of now, I have fixed the ListView Hide. I had another control which was overlapping. But I am still not able to click on any of the cells individually nor able to get the $iButton1 to work.

Please help. 

Share this post


Link to post
Share on other sites
DigDeep

I figured out. it was an issue with Controller overlapping and WM_Notify not set correctly.

Thanks.

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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.