Jump to content

how to make that listview (items)editable


E1M1
 Share

Recommended Posts

How to change that listview so I can edit item's text if I click on item?

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 629, 461, 460, 262)
$ListView1 = GUICtrlCreateListView("list|List1", 0, 0, 626, 454, BitOR($LVS_REPORT,$LVS_EDITLABELS,$LVS_SHOWSELALWAYS),$LVS_EX_GRIDLINES)
GUICtrlCreateListViewItem("item11|item12",$ListView1)
GUICtrlCreateListViewItem("item21|item22",$ListView1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd
Edited by E1M1

edited

Link to comment
Share on other sites

How to change that listview so I can edit item's text if I click on item?

Mmmh,

if I remeber right there is a UDF exactly for that - under GUIListview-managment.

So if you don't want to search here start scite and press F1. (or Help->Help)

HTH, Reinhard

Link to comment
Share on other sites

all I found was :

#Include <GuiListView.au3>

_GUICtrlListView_EditLabel($hWnd, $iIndex)

But it don't let me edit any item, when I finished item editing on that example, I didn't had any other chance to edit it.I need ability to edit item I click on.I also searched from this froum for GUIListview-managment ... didn't find that udf.

*****************

can anyone help me understand that example from help

there is many DllStructGetData() commands in that example, I know only that I gets DLL data, what what dll it uses? what data it get's and how this thing work?

how I know what Struct must be? and how i know which Element I need to use? where it all came from?

edited

Link to comment
Share on other sites

all I found was :

#Include <GuiListView.au3>

_GUICtrlListView_EditLabel($hWnd, $iIndex)

But it don't let me edit any item, when I finished item editing on that example, I didn't had any other chance to edit it.I need ability to edit item I click on.I also searched from this froum for GUIListview-managment ... didn't find that udf.

*****************

can anyone help me understand that example from help

there is many DllStructGetData() commands in that example, I know only that I gets DLL data, what what dll it uses? what data it get's and how this thing work?

how I know what Struct must be? and how i know which Element I need to use? where it all came from?

I think what you need is eltorro's _EIPLISTVIEW. He hasn't updated it recently and I posted an update here.

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

all I found was :

#Include <GuiListView.au3>

_GUICtrlListView_EditLabel($hWnd, $iIndex)

But it don't let me edit any item, when I finished item editing on that example, I didn't had any other chance to edit it.I need ability to edit item I click on.I also searched from this froum for GUIListview-managment ... didn't find that udf.

*****************

can anyone help me understand that example from help

there is many DllStructGetData() commands in that example, I know only that I gets DLL data, what what dll it uses? what data it get's and how this thing work?

how I know what Struct must be? and how i know which Element I need to use? where it all came from?

The example for _GUICtrlListView_GetEditControl() in the help file is a working example of how it is done. The example will need modifying slightly to work with sub items as well as items.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

The example for _GUICtrlListView_GetEditControl() in the help file is a working example of how it is done. The example will need modifying slightly to work with sub items as well as items.

you re right but I don't know how I have to modify it, and do I need to work with all these DllStructGetData() commands?

edited

Link to comment
Share on other sites

you re right but I don't know how I have to modify it, and do I need to work with all these DllStructGetData() commands?

rasim has posted a much better example here.

Posted by rasim

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

thanks.

I have few more questions.

how to change script if I want to use single click instead of double click to edit item?

How I enable left,right arrows for moving inside Listview?

I want that I can move with arrow keys inside listview and I want automatically enable item editing on item select.

I also want get rid of that red border, And I want to add option fot automatically select text it should be variablethat will be checked every time item selected.

for example

if $SelecAll = 0 then dont select text when item is selected

if $SelecAll = 1 then select all text when Item is selected so if I press any text symbol, item's text will be automatically replaced.

edited

Link to comment
Share on other sites

But how i connect all these nice examples to 1 big script?

they all use WM_NOTIFY(), But don't understand how it works.And it's not easy to operate with function that i cant understand.

I Dont know where All these variables come from, and how DllStruct* commands work? how these commands know what they have to do?

all autoit funcs with DllStruct are black area for me,I simply cant understand how It works.

edited

Link to comment
Share on other sites

In this case don't try to do complicated projects/tasks and do only simple ones (for the start of your scripting).

Well I know some autoit commands and I have some autoit programming experience.

Here I would mention some of things Ive done in autoit:

notepad (it has more functions that windows original notepad)

apt - looks and acts like Adept under linux but my program is for windows and coded in autoit

MainMenu - alternative for windows start menu

If sentence interpretator

Program to to limit usage of programs, that program can use server to get blacklist, whitelist and main conf, this program can also use plugins.

ECP Edit Control Poisoner - turn random edit control into powerful command line.

I found ~400 self made scripts from my computer.

now I am trying to make simple excel, but problem is: I dont have any editable ListView control.

But if u can recommend me something easier to do then let me know.

edited

Link to comment
Share on other sites

For that kind of burden, I fear the only way to go is like Zedna pointed out already above by using WM_Notify type of editing.

Check out the examples, there's really not magic involved, you don't have to mess around with dlls but just copy and adjust the examples.

Edited by KaFu
Link to comment
Share on other sites

Thats exactly what Windows is nice enough to track and notify you via WM_Notify, it's a message broadcast in the background. Take this example

#include <GuiListView.au3>
#include<GUIConstants.au3>
#include<Constants.au3>
#include<WindowsConstants.au3>


$Gui = GUICreate("Test", 400, 250)

$hListView = GUICtrlCreateListView("Items", 2, 2, 220, 196, BitOR($LVS_EDITLABELS, $LVS_REPORT))
;$hListView = _GUICtrlListView_Create($Gui, "Items", 2, 2, 220, 196, BitOR($LVS_EDITLABELS, $LVS_REPORT))

If Not IsHWnd($hListView) Then $hListView = GUICtrlGetHandle($hListView)

$ListItem1 = _GUICtrlListView_AddItem($hListView, "Item 1",0)
$ListItem2 = _GUICtrlListView_AddItem($hListView, "Item 2",2)
$ListItem3 = _GUICtrlListView_AddItem($hListView, "Item 3",1)
$ListItem4 = _GUICtrlListView_AddItem($hListView, "Item 4",3)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

$Edit_Button = GUICtrlCreateButton("Edit Item", 10, 200)

GUISetState()


While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Edit_Button
            $iSelected = _GUICtrlListView_GetSelectedIndices($hListView)
            If $iSelected <> "" Then _GUICtrlListView_EditLabel($hListView, $iSelected)
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
    $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")
consolewrite($iCode & @crlf)

    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_BEGINLABELEDIT
                    Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)
                    Return False
                Case $LVN_ENDLABELEDIT
                    Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)
                    Local $tBuffer = DllStructCreate("char Text[" & DllStructGetData($tInfo, "TextMax") & "]", _
                        DllStructGetData($tInfo, "Text"))
                    Local $sNewText = DllStructGetData($tBuffer, "Text")
                    If StringLen($sNewText) Then Return True
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

copied from here:

#467479

and changed

$iCode = DllStructGetData($tNMHDR, "Code")

to

$iCode = DllStructGetData($tNMHDR, "Code")

consolewrite($iCode & @crlf)

open the GUI, move your mouse over the listview, use cursors and you'll see the $iCode notify codes in the console. Each code is unique and represents a certain action. Look up the examples or the AU constant includes for listview to learn what they mean (focus set, focus lost, clicked, doubleclicked...).

Edited by KaFu
Link to comment
Share on other sites

Thanks, now I can start making my modifications (I already did) but now I cant use up/down arrow to jump from row to another (anymore). How I enable it again?

Edit: I cant create another column! GUI doesn't display that!

Here's modification:

#include <GuiListView.au3>
#include<GUIConstants.au3>
#include<Constants.au3>
#include<WindowsConstants.au3>


$Gui = GUICreate("Test", 400, 250)

$hListView = GUICtrlCreateListView("Items|Items2", 2, 2, 220, 196, BitOR($LVS_EDITLABELS, $LVS_REPORT))
;$hListView = _GUICtrlListView_Create($Gui, "Items", 2, 2, 220, 196, BitOR($LVS_EDITLABELS, $LVS_REPORT))

If Not IsHWnd($hListView) Then $hListView = GUICtrlGetHandle($hListView)

$ListItem1 = _GUICtrlListView_AddItem($hListView, "Item 1|Item 21",0)
$ListItem2 = _GUICtrlListView_AddItem($hListView, "Item 2|Item 22",2)
$ListItem3 = _GUICtrlListView_AddItem($hListView, "Item 3|Item 23",1)
$ListItem4 = _GUICtrlListView_AddItem($hListView, "Item 4|Item 24",3)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

$Edit_Button = GUICtrlCreateButton("Edit Item", 10, 200)

GUISetState()


While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Edit_Button
            $iSelected = _GUICtrlListView_GetSelectedIndices($hListView)
            If $iSelected <> "" Then _GUICtrlListView_EditLabel($hListView, $iSelected)
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
    $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")
consolewrite($iCode & @crlf)
If $iCode = -2 Then
                $iSelected = _GUICtrlListView_GetSelectedIndices($hListView)
            If $iSelected <> "" Then _GUICtrlListView_EditLabel($hListView, $iSelected)
EndIf   

    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_BEGINLABELEDIT
                    Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)
                    Return False
                Case $LVN_ENDLABELEDIT
                    Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)
                    Local $tBuffer = DllStructCreate("char Text[" & DllStructGetData($tInfo, "TextMax") & "]", _
                        DllStructGetData($tInfo, "Text"))
                    Local $sNewText = DllStructGetData($tBuffer, "Text")
                    If StringLen($sNewText) Then Return True
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc
Edited by E1M1

edited

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