Jump to content

can i disable listview select?


 Share

Recommended Posts

Hey guys,

I know with a listbox I can add the $LBS_NOSEL style and that makes it impossible to select items.

I was hoping there is something like this for a ListView also. Does anyone know?

Thanks!

Link to comment
Share on other sites

Hey guys,

I know with a listbox I can add the $LBS_NOSEL style and that makes it impossible to select items.

I was hoping there is something like this for a ListView also. Does anyone know?

Thanks!

I don't know but you can always use taq's method to stop anyone selecting anything. You create a blank label with the same dimensions as the listview

$cover = GUICtrlCreateLabel("",10,10,200,150); blocking the control!
GUICtrlSetState($cover,$GUI_ONTOP)

If you want the headers and scroll bars to be available you have to adjust the label size and position to leave them 'exposed'.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Just keep in mind that this clever method won't stop from selecting with keyboard. :)

True Siao, I hadn't thought about that.

Here's a clumsy way to stop the keyboard selecting an item. I couldn't see how to use a notification that an item is selected. If anyone knows I would be interested to learn.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <guilistview.au3>
#include <SendMessage.au3>
Opt('MustDeclareVars', 1)
Global $listview

Example()

Func Example()
    Local $Gui, $button, $item1, $item2, $item3, $input1, $msg, $cover, $hLV
    $Gui = 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
    $cover = GUICtrlCreateLabel("", 10, 20, 200, 130); blocking the edit box (from mouse)
    GUICtrlSetState($cover, $GUI_ONTOP);+$GUI_FOCUS)
    GUISetState()
    GUICtrlSetData($item2, "ITEM1")
    GUICtrlSetData($item3, "||COL33")
    GUICtrlDelete($item1)
    $hLV = GUICtrlGetHandle($listview)
    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)
        EndSelect
        
    ;stop keyboard selection of the ListView
        If ControlGetFocus($Gui) = "SysListView321" Then
            _GUICtrlListView_SetItemSelected($hLV, -1, False)
            _SendMessage($hLV, $WM_KILLFOCUS)
            GUICtrlSetState($cover, $GUI_FOCUS)
        EndIf
        
    Until $msg = $GUI_EVENT_CLOSE
EndFunc  ;==>Example
Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Return 1 from LVN_ITEMCHANGING to prevent item change. Might want to check for LVIF_STATE and stuff if only want prevent state selected change. Might want to implement this prevention as conditional via global flag, if you need to be able to change item's state yourself programatically at some point.

"be smart, drink your wine"

Link to comment
Share on other sites

LOL!

Now it just starts getting complicated with heavy code :)

Siao, why couldn't you just let me be happy with the blocking label? :(

I wish there was a style for the listview that works like the $LBS_NOSEL for the listbox.

Edited by lemony
Link to comment
Share on other sites

lemony

Now it just starts getting complicated with heavy code

It`s no heavy :)

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

$hGUI = GUICreate("Test GUI", 300, 200)

$hListView = GUICtrlCreateListView("Items|SubItems", 10, 10, 280, 180, $LVS_REPORT, $WS_EX_CLIENTEDGE)

For $i = 1 To 10
    _GUICtrlListView_AddItem($hListView, "Item " & $i)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 1)
Next

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $tNMHDR, $IdFrom, $iCode
    
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $IdFrom = DllStructGetData($tNMHDR, "IdFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    
    Switch $IdFrom
        Case $hListView
            Switch $iCode
                Case $LVN_ITEMCHANGING
                    Return 1
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Link to comment
Share on other sites

HAHA! That's working very nicely rasim! :)

Good job!

I want to understand that code a little better. Can you explain to me what is happening on this part:

Case $LVN_ITEMCHANGING
                    Return 1

So I figured out that up until this point, the function is finding out where you clicked on the GUI and if it is on the ListViewItem then it will "Return 1" right?

So what does it mean "Return 1". How does the script know that it should de-select the item.

It's working good, I just want to understand it a little you know.. so I can learn :)

Thanks!

Edited by lemony
Link to comment
Share on other sites

How does the script know that it should de-select the item.

When you clicking on a item, callback function processed notify messages. If notify message is LVN_ITEMCHANGING (item prepare to change) the callback function returned a 1 and item are not selected.

P.S.

Sorry, my english is not perfect. :)

Link to comment
Share on other sites

When you clicking on a item, callback function processed notify messages. If notify message is LVN_ITEMCHANGING (item prepare to change) the callback function returned a 1 and item are not selected.

P.S.

Sorry, my english is not perfect. :)

Yep I understand what you are saying :P

So the WM_NOTIFY function is intercepting the command to select an item and block it from going through with the Return 1. And this way the ListViewItem never even gets selected in the first place :)

Nice code rasim! Thanks for all that help :)

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