Jump to content

_GUIListViewEx_ContextPos() always fail


jimmy123j
 Share

Recommended Posts

I wan't to use the ListView to create a option table for right click, and get the item or subitem text for specific target

I use the _GUIListViewEx_ContextPos(), but can't get the row and col, always show the -1 and -1

image.png.d356fded6364ce90cf94e22a8b6c7173.png

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <File.au3>
#include <Misc.au3>
#include <String.au3>
#include <Array.au3>
#include "GUIListViewEx.au3"

$GUI = GUICreate("Test", 500, 400)
$LV = GUICtrlCreateListView("1|2|3", 1, 1, 468, 398)

For $i = 1 to 9
   GUICtrlCreateListViewItem ("1" & $i & "|2" & $i & "|3" & $i , $LV)
Next

$mContextmenu = GUICtrlCreateContextMenu($LV)
$GetPos = GUICtrlCreateMenuItem("Get Pos", $mContextmenu)
GUICtrlCreateMenuItem("", $mContextmenu)
$TestA= GUICtrlCreateMenuItem("A", $mContextmenu)
$TestB= GUICtrlCreateMenuItem("B", $mContextmenu)

GUISetState()

While 1


    Switch GUIGetMsg()
         Case $GUI_EVENT_CLOSE
            Exit

         Case $GetPos
            $Pos = _GUIListViewEx_ContextPos()
            _ArrayDisplay($Pos)

    EndSwitch

WEnd

 

 

Edited by jimmy123j
Link to comment
Share on other sites

  • Moderators

jimmy123j,

For the UDF to provide you with the correct information, you need to initialise the ListView so the UDF can access its details and register the UDF with Windows so it can detect the various events that the ListView generates. Then you will get the correct values:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <File.au3>
#include <Misc.au3>
#include <String.au3>
#include <Array.au3>
#include "GUIListViewEx.au3"

$GUI = GUICreate("Test", 500, 400)
$LV = GUICtrlCreateListView("1|2|3", 1, 1, 468, 398)

For $i = 1 to 9
   GUICtrlCreateListViewItem ("1" & $i & "|2" & $i & "|3" & $i , $LV)
Next

$aLVArray = _GUIListViewEx_ReadToArray($LV) ; Convert the ListView content into an array <<<<<<<<<<

$iLVIndex = _GUIListViewEx_Init($LV, $aLVArray) ; Initialise the UDF using that array <<<<<<<<<<<<<

$mContextmenu = GUICtrlCreateContextMenu($LV)
$GetPos = GUICtrlCreateMenuItem("Get Pos", $mContextmenu)
GUICtrlCreateMenuItem("", $mContextmenu)
$TestA= GUICtrlCreateMenuItem("A", $mContextmenu)
$TestB= GUICtrlCreateMenuItem("B", $mContextmenu)

GUISetState()

_GUIListViewEx_MsgRegister() ; Register the Windows messages used by the UDF <<<<<<<<<<<<<<<<<<<<<<

While 1


    Switch GUIGetMsg()
         Case $GUI_EVENT_CLOSE
            Exit

         Case $GetPos
            $Pos = _GUIListViewEx_ContextPos() ; Now this function will return the correct values <<<<
            _ArrayDisplay($Pos)

    EndSwitch

WEnd

Please ask if you have any questions.

M23

P.S. And if you have any further questions about any of my UDFs, please post in the relevant UDF thread (they are listed in my sig).

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

On 2018/12/22 at 11:56 PM, Melba23 said:

jimmy123j,

For the UDF to provide you with the correct information, you need to initialise the ListView so the UDF can access its details and register the UDF with Windows so it can detect the various events that the ListView generates. Then you will get the correct values:

Please ask if you have any questions.

M23

P.S. And if you have any further questions about any of my UDFs, please post in the relevant UDF thread (they are listed in my sig).

Thank you M23, it's work now

When my code not work, I try to edit the code from the Example 6, but still in-vain

Can I ask other stupid questions ?

If I want to disable move the row selected, how can I do

'cause user might move the row when they click the list, and I find all function of the UDF, but still can't find it

Sorry for stupid question and thanks again !

Link to comment
Share on other sites

  • Moderators

jimmy123j,

Glad your code works now.

To prevent drag, just tell the UDF not to allow it - like this:

$iLVIndex = _GUIListViewEx_Init($LV, $aLVArray, 0, 0, Default, 512)

Look in the _GUIListViewEx_Init function header to see what the various parameters do - and why 512 is what you need.

M23

P.S. And once again, if you have any further questions about any of my UDFs, please post in the relevant UDF thread (they are listed in my sig).

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

×
×
  • Create New...