Jump to content

_guictrlistview_addsubitem() not working


Recommended Posts

#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <GuiConstantsEx.au3>
#Include <GuiComboBox.au3>
#include <Date.au3>


$inifile=@MyDocumentsDir&"\Backup.ini"

Global Const $HDN_FIRST = -300
Global Const $HDN_ITEMCHANGINGA = $HDN_FIRST - 0
Global Const $HDN_BEGINTRACKA = $HDN_FIRST - 6
global $save


Opt("GUIOnEventMode", 1)
$Gui = GUICreate("Test", 500, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, "quit")

$add_folder=GUICtrlCreateButton('',10,10,40,40,$BS_ICON)
GUICtrlSetImage (-1, "shell32.dll",46)
GUICtrlSetOnEvent(-1,"add_folder")

$add_file=GUICtrlCreateButton('',55,10,40,40,$BS_ICON)
GUICtrlSetImage (-1, "shell32.dll",134)
GUICtrlSetOnEvent(-1,"add_file")

$output_foler=GUICtrlCreateButton('',450,10,40,40,$BS_ICON)
gUICtrlSetImage (-1, "shell32.dll",146)
GUICtrlSetOnEvent(-1,"output_folder")

$combo1=GUICtrlCreateCombo('Please Select',100,10,100,25)
GUICtrlSetData(-1,'Daily|Weekly|Monthly')

$log=GUICtrlCreateLabel("Message Log",210,15,100,25)



$hListView = _GUICtrlListView_Create($GUI, "|Name|Location|ScD|Comments||", 10, 55, 480, 135,bitor($LVS_EX_GRIDLINES,$LVS_REPORT ), $WS_EX_CLIENTEDGE)
_GUICtrlListView_SetExtendedListViewStyle($hListView,bitor($LVS_EX_SUBITEMIMAGES,$LVS_EX_FULLROWSELECT))

_GUICtrlListView_SetColumnWidth($hListView, 0, 75)
_GUICtrlListView_SetColumnWidth($hListView, 1, 75)
_GUICtrlListView_SetColumnWidth($hListView, 2, 150)
_GUICtrlListView_SetColumnWidth($hListView, 3, 50)
_GUICtrlListView_SetColumnWidth($hListView, 4, 75)
_GUICtrlListView_SetColumnWidth($hListView, 5, 25)
_GUICtrlListView_SetColumnWidth($hListView, 6, 25)

$hImage = _GUIImageList_Create(16, 16, 5, 5)
_GUIImageList_AddIcon ($hImage, "shell32.dll", 4);folder
_GUIImageList_AddIcon ($hImage, "shell32.dll",54);file
_GUIImageList_AddIcon ($hImage, "shell32.dll",31);bin
_GUIImageList_AddIcon ($hImage, "shell32.dll",21);tick
_GUIImageList_AddIcon ($hImage, "shell32.dll",131);cross
_GUICtrlListView_SetImageList($hListView, $hImage, 1)


_GUICtrlListView_AddItem($hListView, 'Folder',0)

_GUICtrlListView_AddSubItem ($hListView, 0,'n',1,-1)
_GUICtrlListView_AddSubItem ($hListView, 0,'l',2, -1)
_GUICtrlListView_AddSubItem ($hListView, 0,'s',3, -1)
_GUICtrlListView_AddSubItem ($hListView, 0,'c',4, -1)
_GUICtrlListView_AddSubItem ($hListView,0,'',5,2)
_GUICtrlListView_AddSubItem ($hListView,0,'',6,3)
GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
   sleep(100)

WEnd
;------------------------------------------------------------------------------

Func _ListView_Click($hWnd, $iIndex)
 ConsoleWrite("handle clicked")
   If _GUICtrlListView_GetItemStateImage($hWnd, $iIndex) = 1 Then
        _GUICtrlListView_SetItemStateImage($hListView, $iIndex, 0)
    Else
        _GUICtrlListView_SetItemStateImage($hListView, $iIndex, 1)
    EndIf
EndFunc  ;==>_ListView_Click

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")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
             Case $NM_CLICK; Sent by a list-view control when the user clicks an item with the left mouse button
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                   
                        $sel= DllStructGetData($tInfo, "SubItem")  
                        $row=DllStructGetData($tInfo, "Item")
                        if $sel=5 Then
                            _GUICtrlListView_DeleteItem($hListView,$row)
                         EndIf 
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc  ;==>WM_NOTIFY

func add_folder()
if guictrlread($combo1) <> 'Please Select' Then
local $dir = FileSelectFolder("Choose a folder.", "",2)
if not @error Then
local $lv_count=_GUICtrlListView_GetItemCount($hListView)
_GUICtrlListView_AddItem($hListView, 'Folder',0)
_GUICtrlListView_AddSubItem ($hListView,$lv_count+1,'New Name',1,-1)
_GUICtrlListView_AddSubItem ($hListView, $lv_count+1,$dir,2, -1)
_GUICtrlListView_AddSubItem ($hListView, $lv_count+1,guictrlread($combo1),3, -1)
_GUICtrlListView_AddSubItem ($hListView, $lv_count+1,'c',4, -1)
_GUICtrlListView_AddSubItem ($hListView,$lv_count+1,'',5,2)
_GUICtrlListView_AddSubItem ($hListView,$lv_count+1,'',6,4)
EndIf
Else
GUICtrlSetData($log,"Please Choose a Backup Schedule")
EndIf
EndFunc


func add_file()
if guictrlread($combo1) <> 'Please Select' Then
local $dir = FileOpenDialog("Choose a file.",@MyDocumentsDir,'')
if not @error Then
_GUICtrlListView_AddItem($hListView, 'Folder',1)
EndIf
Else    
GUICtrlSetData($log,"Please Choose a Backup Schedule")
EndIf
EndFunc


func output_folder()
local $dir = FileSelectFolder("Choose a folder.",'',1+4)
if not @error Then
    $save=$dir
    DirCreate($dir)
    IniWrite($inifile,"config",0,$dir)
    EndIf
EndFunc
                
                
Func quit()
    Exit
    GUIDelete($GUI)
EndFunc  ;==>quit

Link to comment
Share on other sites

This works

func add_folder()
if guictrlread($combo1) <> 'Please Select' Then
local $dir = FileSelectFolder("Choose a folder.", "",2)
if not @error Then
local $lv_count=_GUICtrlListView_GetItemCount($hListView)
$i=_GUICtrlListView_AddItem($hListView, 'Folder',0)
_GUICtrlListView_AddSubItem ($hListView,$i,'New Name',1,-1)
_GUICtrlListView_AddSubItem ($hListView, $i,$dir,2, -1)
_GUICtrlListView_AddSubItem ($hListView, $i,guictrlread($combo1),3, -1)
_GUICtrlListView_AddSubItem ($hListView, $i,'c',4, -1)
_GUICtrlListView_AddSubItem ($hListView,$i,'',5,2)
_GUICtrlListView_AddSubItem ($hListView,$i,'',6,4)
EndIf
Else
GUICtrlSetData($log,"Please Choose a Backup Schedule")
EndIf
EndFunc
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...