Jump to content

Can't read listview !!


AlienStar
 Share

Recommended Posts

hello everybody

tell me why I can't read listview items please

here is my code

#include <GUIConstants.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <GDIPlus.au3>
#include <File.au3>
Opt("MustDeclareVars", 1)
Global $hListView
Local $edtpst_db = "C:\Users\User\AppData\Local\PTMW\edtpst_db.ini"
Local $hGUI5 = GUICreate("", 650, 550)
Local $idListView = GUICtrlCreateListView("", 5, 5, 640, 500, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
Local $hCMenu_edtpst = GUICtrlCreateContextMenu($idListView) 
Local $edtpst_edt = GUICtrlCreateMenuItem("edit post", $hCMenu_edtpst, 1)
;=============================================================================
_GUICtrlListView_SetExtendedListViewStyle($idListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
_GUICtrlListView_AddColumn($idListView, "image", 130)       ; Must not be too small
_GUICtrlListView_AddColumn($idListView, "title", 265)
_GUICtrlListView_AddColumn($idListView, "category", 120)
_GUICtrlListView_AddColumn($idListView, "date", 100)
Local $hListView = GUICtrlGetHandle($idListView)
Local $hImage = _GUIImageList_Create(128, 85, 5, 3)

_GUICtrlListView_SetImageList($hListView, $hImage, 1)
_GDIPlus_Startup()

Local $aArray = _FileListToArrayRec(@ScriptDir&"\imgtest", "*.jpg", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_FULLPATH)
Local $iArray = UBound($aArray) - 1, $GDIpBmpLarge, $GDIpBmpResized, $GDIbmp, $img
;_ArrayDisplay($aArray)

For $i = 1 To UBound($aArray)-1
    $GDIpBmpLarge = _GDIPlus_BitmapCreateFromMemory(Binary(FileRead($aArray[$i]))) ;GDI+ image!
    $GDIpBmpResized = _GDIPlus_ImageResize($GDIpBmpLarge, 128, 128) ;GDI+ image
    $GDIbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($GDIpBmpResized) ;GDI image!
    $img = _GUIImageList_Add($hImage, $GDIbmp)
    _GUICtrlListView_AddItem($idListView, "", $img)
    ;----------------------------------------------------------------
    _GDIPlus_BitmapDispose($GDIpBmpLarge)
    _GDIPlus_BitmapDispose($GDIpBmpResized)
    _WinAPI_DeleteObject($GDIbmp)
    ;----------------------------------------------------------------
    _GUICtrlListView_AddSubItem($idListView, $i - 1, "Title", 1)
    ;GUICtrlSetFont(-1, 9, 0, 0, $font)
    ;----------------------------------------------------------------
    _GUICtrlListView_AddSubItem($idListView, $i - 1, "Category", 2)
    ;GUICtrlSetFont(-1, 9, 0, 0, $font)
    ;----------------------------------------------------------------
    _GUICtrlListView_AddSubItem($idListView, $i - 1, "Date", 3)
    ;GUICtrlSetFont(-1, 9, 0, 0, $font)
    ;----------------------------------------------------------------
Next
_GDIPlus_Shutdown()

GUISetState(@SW_SHOW)

; Message loop
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

        Case $edtpst_edt
            Local $idListView_rd = GUICtrlRead(GUICtrlRead($idListView))
            MsgBox(0,"",$idListView_rd)
    EndSwitch
WEnd

; Cleanup
GUIDelete()

 

Edited by AlienStar
Link to comment
Share on other sites

  • Moderators

AlienStar,

I imagine it is because you have added items using the _GUICtrlListView UDF functions and not the native GUICtrlCreateListViewItem function. Thus there is no ControlID for GUICtrlRead to use. Try using the native function to add the elements to your ListView and you should be able to read them.

M23

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

25 minutes ago, Melba23 said:

AlienStar,

I imagine it is because you have added items using the _GUICtrlListView UDF functions and not the native GUICtrlCreateListViewItem function. Thus there is no ControlID for GUICtrlRead to use. Try using the native function to add the elements to your ListView and you should be able to read them.

M23

I am compelled to do so, because I need to add images in listview.

would you tell me how to solve please ?

Edited by AlienStar
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...