Jump to content

How to get ListView Cell


Recommended Posts

Is there a better way to select and get the value from a row in listview? I added the red text part to the Help example? It gives me the whole row separated by "|". I can work with that, but I would like to learn the best technique to do this. I did a lot of searching, but didn't seem to find the answers.

1. How could I retrieve just the value from one cell in the selected row - say I only wanted the column 2 cell value. Is there an index, column values I could retrieve and then directely get the cell value?

2. Is looking for any msg value > 0 the best way to flag when a row in the list view is selected?

I want to become more effective in this.

Thanks.

#include <GUIConstants.au3>

GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
GUISetBkColor(0x00E0FFFF) ; will change background color

$listview = GUICtrlCreateListView("col1  |col2|col3  ", 10, 10, 200, 150);,$LVS_SORTDESCENDING)
$button = GUICtrlCreateButton("Value?", 75, 170, 70, 20)
$item1 = GUICtrlCreateListViewItem("item2|col22|col23", $listview)
$item2 = GUICtrlCreateListViewItem("item1|col12|col13", $listview)
$item3 = GUICtrlCreateListViewItem("item3|col32|col33", $listview)
$input1 = GUICtrlCreateInput("", 20, 200, 150)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)  ; to allow drag and dropping
GUISetState()
GUICtrlSetData($item2, "ITEM1")
GUICtrlSetData($item3, "||COL33")
GUICtrlDelete($item1)

Do
    $msg = GUIGetMsg()
    
    Select
        Case $msg = $button
            MsgBox(0, "listview item", GUICtrlRead(GUICtrlRead($listview)), 2)
        Case $msg = $listview
            MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2)
    [color="#FF0000"]   Case $msg > 0
            ConsoleWrite(GUICtrlRead(GUICtrlRead($ListView)) & @CRLF)[/color]
    EndSelect
Until $msg = $GUI_EVENT_CLOSE
Link to comment
Share on other sites

I looked further in the Help file and found an answer to my #1 question. I can do the following to get column 1 item selected:

$a = _GUICtrlListView_GetItemTextArray($listview,-1)
         ConsoleWrite("Column 1 selected = " & $a[1] & @CRLF)

But, is there a better way to get a selection clicked then just looking for anything >0? Is there any way to specifically get the listview event for any rows? I would like to do something more specific than

Case $msg > 0.

Do
    $msg = GUIGetMsg()
    
    Select
        Case $msg = $button
            MsgBox(0, "listview item", GUICtrlRead(GUICtrlRead($listview)), 2)
        Case $msg = $listview
            MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2)
        Case $msg > 0
            $a = _GUICtrlListView_GetItemTextArray($listview,-1)
            $b = $a[1]
            ConsoleWrite("$b=" & $b & @CRLF)
    EndSelect
Until $msg = $GUI_EVENT_CLOSE
Link to comment
Share on other sites

I looked further in the Help file and found an answer to my #1 question. I can do the following to get column 1 item selected:

$a = _GUICtrlListView_GetItemTextArray($listview,-1)
         ConsoleWrite("Column 1 selected = " & $a[1] & @CRLF)

But, is there a better way to get a selection clicked then just looking for anything >0? Is there any way to specifically get the listview event for any rows? I would like to do something more specific than

Case $msg > 0.

Do
    $msg = GUIGetMsg()
    
    Select
        Case $msg = $button
            MsgBox(0, "listview item", GUICtrlRead(GUICtrlRead($listview)), 2)
        Case $msg = $listview
            MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2)
        Case $msg > 0
            $a = _GUICtrlListView_GetItemTextArray($listview,-1)
            $b = $a[1]
            ConsoleWrite("$b=" & $b & @CRLF)
    EndSelect
Until $msg = $GUI_EVENT_CLOSE
Read the UDF section in the help file of the latest beta regards ListView.

There are many examples how to get the anything from list view.

Edited by lsakizada

Be Green Now or Never (BGNN)!

Link to comment
Share on other sites

Read the UDF section in the help file of the latest beta regards ListView.

There are many examples how to get the anything from list view.

Thanks, I see that.

But how can I track events when I click on a row in a list view? I know using case msg >0 works, but is there somethine more specific to get the event for a listview row?

Thanks again.

Link to comment
Share on other sites

Thanks, I see that.

But how can I track events when I click on a row in a list view? I know using case msg >0 works, but is there somethine more specific to get the event for a listview row?

Thanks again.

Search forum for:

GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")

There are lots of examples

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...