Jump to content

Odd ListView / ListViewItem behaviour OnEvent


Recommended Posts

Hi,

Thought I'd check here first before reporting this as a possible bug.

I had a problem where I was creating ListViewItems that could be clicked by the user to initiate a function.

I've done this many times in different programs, but for some reason for this particular script clicking on ListViewItems did nothing.

It has taken me almost 3 weeks to figure out the problem :)

Problem seems to be when there are more delimited items in the ListViewItem text than there are columns in the ListView itself.

Reproducer:

Opt("GUIOnEventMode", 1)

GUICreate("", 220, 150)

;----- NOT WORKING -----
$ListView1 = GUICtrlCreateListView("Col1|Col2|Col3", 10, 10, 190, 50)
GUICtrlCreateListViewItem("first|second|third|fourth",$ListView1)
GUICtrlSetOnEvent(-1,"_Selected")

;----- WORKING OK -----
$ListView2 = GUICtrlCreateListView("Col1|Col2|Col3|Col4", 10, 70, 190, 50)
GUICtrlCreateListViewItem("first|second|third|fourth",$ListView2)
GUICtrlSetOnEvent(-1,"_Selected")

GUISetState(@SW_SHOW)

While 1
    Sleep(100)
WEnd

Func _Selected()
    ConsoleWrite(@GUI_CtrlId & @CRLF)
EndFunc

The first ListView item does not respond to clicking. The second does.

Is this expected behaviour?

Edited by andybiochem
- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

Hi,

Thought I'd check here first before reporting this as a possible bug.

I had a problem where I was creating ListViewItems that could be clicked by the user to initiate a function.

I've done this many times in different programs, but for some reason for this particular script clicking on ListViewItems did nothing.

It has taken me almost 3 weeks to figure out the problem :party:

Problem seems to be when there are more delimited items in the ListViewItem text than there are columns in the ListView itself.

Reproducer:

Opt("GUIOnEventMode", 1)

GUICreate("", 220, 150)

;----- NOT WORKING -----
$ListView1 = GUICtrlCreateListView("Col1|Col2|Col3", 10, 10, 190, 50)
GUICtrlCreateListViewItem("first|second|third|fourth",$ListView1)
GUICtrlSetOnEvent(-1,"_Selected")

;----- WORKING OK -----
$ListView2 = GUICtrlCreateListView("Col1|Col2|Col3|Col4", 10, 70, 190, 50)
GUICtrlCreateListViewItem("first|second|third|fourth",$ListView2)
GUICtrlSetOnEvent(-1,"_Selected")

GUISetState(@SW_SHOW)

While 1
    Sleep(100)
WEnd

Func _Selected()
    ConsoleWrite(@GUI_CtrlId & @CRLF)
EndFunc

The first ListView item does not respond to clicking. The second does.

Is this expected behaviour?

I don't think using -1 for the control ID is working the way you think it does. That refers back to GuiCtrlCreateListViewItem(), not the list view itself. Because the Item creation gets an error for having too many columns, it gets 0 back for the ID. Try it this way:
Opt("GUIOnEventMode", 1)

GUICreate("", 220, 150)
GUISetOnEvent(-3, "_Quit")

$ListView1 = GUICtrlCreateListView("Col1|Col2|Col3", 10, 10, 190, 50)
ConsoleWrite("$ListView1 = " & $ListView1 & @LF)
$LVItem1 = GUICtrlCreateListViewItem("first|second|third|fourth", $ListView1)
ConsoleWrite("$LVItem1 = " & $LVItem1 & @LF)
GUICtrlSetOnEvent($ListView1, "_Selected")

$ListView2 = GUICtrlCreateListView("Col1|Col2|Col3|Col4", 10, 70, 190, 50)
ConsoleWrite("$ListView2 = " & $ListView2 & @LF)
$LVItem2 = GUICtrlCreateListViewItem("first|second|third|fourth", $ListView2)
ConsoleWrite("$LVItem2 = " & $LVItem2 & @LF)
GUICtrlSetOnEvent($ListView2, "_Selected")

GUISetState(@SW_SHOW)

While 1
    Sleep(100)
WEnd

Func _Selected()
    ConsoleWrite(@GUI_CtrlId & @CRLF)
EndFunc  ;==>_Selected

Func _Quit()
    Exit
EndFunc  ;==>_Quit

:)

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

Hi PsaltyDS!

I'm not interested in setting events to the ListView control itself.

I want to set events to the individual ListViewItems so that clicking on them invokes a function.

Perhaps this shows the idea better:

Opt("GUIOnEventMode", 1)

GUICreate("", 220, 150)

;----- NOT WORKING -----
$ListView1 = GUICtrlCreateListView("Col1|Col2|Col3", 10, 70, 190, 50)
GUICtrlCreateListViewItem("I|can't|be|clicked",$ListView1)
GUICtrlSetOnEvent(-1,"_Selected")

;----- WORKING OK -----
$ListView2 = GUICtrlCreateListView("Col1|Col2|Col3|Col4", 10, 10, 190, 50)
GUICtrlCreateListViewItem("I|can|be|clicked!",$ListView2)
GUICtrlSetOnEvent(-1,"_Selected")

GUISetState(@SW_SHOW)

While 1
    Sleep(100)
WEnd

Func _Selected()
    MsgBox(0,"","You selected ListViewItem with ID=" & @GUI_CtrlId & " ,and with text=" & GUICtrlRead(@GUI_CtrlId))
EndFunc

... but you're right, the control creation is saying that it fails and doesn't return a control ID, so why is the ListViewItem created anyway??

Edited by andybiochem
- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

  • 2 weeks later...

Hi PsaltyDS!

I'm not interested in setting events to the ListView control itself.

I want to set events to the individual ListViewItems so that clicking on them invokes a function.

Perhaps this shows the idea better:

Opt("GUIOnEventMode", 1)

GUICreate("", 220, 150)

;----- NOT WORKING -----
$ListView1 = GUICtrlCreateListView("Col1|Col2|Col3", 10, 70, 190, 50)
GUICtrlCreateListViewItem("I|can't|be|clicked",$ListView1)
GUICtrlSetOnEvent(-1,"_Selected")

;----- WORKING OK -----
$ListView2 = GUICtrlCreateListView("Col1|Col2|Col3|Col4", 10, 10, 190, 50)
GUICtrlCreateListViewItem("I|can|be|clicked!",$ListView2)
GUICtrlSetOnEvent(-1,"_Selected")

GUISetState(@SW_SHOW)

While 1
    Sleep(100)
WEnd

Func _Selected()
    MsgBox(0,"","You selected ListViewItem with ID=" & @GUI_CtrlId & " ,and with text=" & GUICtrlRead(@GUI_CtrlId))
EndFunc

... but you're right, the control creation is saying that it fails and doesn't return a control ID, so why is the ListViewItem created anyway??

DO IT LIKE THIS

GUICtrlCreateListViewItem("My List ITem Here", $listview)

GUICtrlSetOnEvent(-1,"Selected")

apparently you hve to set the event on the individual items, each one

If you fool around with a thing for very long you will screw it up
Link to comment
Share on other sites

  • 4 weeks later...

Lol, just because GUICtrlCreateListViewItem("I|can't|be|clicked",$ListView1) out of range. It should be GUICtrlCreateListViewItem("I|can't|be clicked",$ListView1).

To quote the sage philosopher, Homer: "Doh!" :D

This works fine for both:

Opt("GUIOnEventMode", 1)

GUICreate("", 220, 150)
GUISetOnEvent(-3, "_Quit")

$ListView1 = GUICtrlCreateListView("Col1|Col2|Col3", 10, 70, 190, 50)
GUICtrlCreateListViewItem("So|can|I!",$ListView1)
GUICtrlSetOnEvent(-1,"_Selected")

$ListView2 = GUICtrlCreateListView("Col1|Col2|Col3|Col4", 10, 10, 190, 50)
GUICtrlCreateListViewItem("I|can|be|clicked!",$ListView2)
GUICtrlSetOnEvent(-1,"_Selected")

GUISetState(@SW_SHOW)

While 1
    Sleep(100)
WEnd

Func _Selected()
    MsgBox(0,"","You selected ListViewItem with ID=" & @GUI_CtrlId & " ,and with text=" & GUICtrlRead(@GUI_CtrlId))
EndFunc

Func _Quit()
    Exit
EndFunc

:D

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