Sign in to follow this  
Followers 0
Ace08

Getting the value in a list view

5 posts in this topic

uhm guys i've used the following UDF code below to make my list view look like a spreadsheet(with cells)

for $i = 1 to UBound($_Records) - 1
_GUICtrlListView_AddItem($hListView, $ID, $i - 1)
_GUICtrlListView_AddSubItem($hListView, $i - 1, $LName, 1)
_GUICtrlListView_AddSubItem($hListView, $i - 1, $FName, 1)
next

question is how do i get the values in the cell i picked?

i've searched and found this

_GUICtrlListView_GetItem($hListView, 1)

but i can't seem to figure out how to use this to get the values of the cell i have selected


Work smarter not harder.My First Posted Script: DataBase

Share this post


Link to post
Share on other sites



Ace08,

Use a message handler to intercept the click and determine the item/subitem like this: ;)

#include <GuiMenu.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>

$hGUI = GUICreate('Read ListView Item', 400, 300)
$hListView = _GUICtrlListView_Create($hGUI, "", 2, 2, 394, 268)
_GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_GRIDLINES)
GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

; Add columns
_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)
_GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100)

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

GUISetState()

; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func ListView_Click()

    
EndFunc   ;==>ListView_Click


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    ;$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView) ; Get id of clicked item
                    If $aHit[0] <> -1 Then ; Check it was an item
                        Local $sText = _GUICtrlListView_GetItemText($hListView, $aHit[0], $aHit[1]); Read the item text
                        ConsoleWrite($sText & @CRLF) ; Display it
                    EndIf
                    Return 0
            EndSwitch
    EndSwitch
        
    Return $GUI_RUNDEFMSG
    
EndFunc   ;==>WM_NOTIFY

M23

P.S. I happened to have that script lying around, so it took almost no time to alter it. It greatly increases your chances of getting help if you provide a running script rather than just a few lines - having to write a whole script to show a solution is more than many here are prepared to do. :)


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

#3 ·  Posted (edited)

Just came back from a long holiday

Wow Thanks a lot Melba23 for the sample :(

and Sorry for not posting the whole script i thought that it was just a small code that i overlooked :graduated:

oh and one more question, when i used the code above i noticed that the entire line isn't highligted anymore exept only for the first column

Edited by Ace08

Work smarter not harder.My First Posted Script: DataBase

Share this post


Link to post
Share on other sites

Ace08,

the entire line isn't highligted anymore

Just add the relevant style: :graduated:

_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOr($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))

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

Thanks a lot Melba23 i'll try this one :D (so its just in the design part :graduated:)Thanks again :(


Work smarter not harder.My First Posted Script: DataBase

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  
Followers 0