Sign in to follow this  
Followers 0
neverasunset

button in listview

3 posts in this topic

i just want to ask how i can put a button in listview

please share if you do know the solution

thanks!

Share this post


Link to post
Share on other sites



i just want to ask how i can put a button in listview

please share if you do know the solution

thanks!

You can add an icon. See the help for _GuiImageList_AddIcon.

Or you can use eltorro's udf.

Here is an example of using icons.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <guilistview.au3>
#include <GuiImageList.au3>
#include <StaticConstants.au3>


#Region ### START Koda GUI section ### Form=G:\MOE\MOE_OrderList.kxf
Global $MOEOrderListForm = GUICreate("List with buttons", 734, 497, 0, 0, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))

Global $ListView1 = GUICtrlCreateListView("Job No.|Customer Code|Cust Ref.|Last Modified|Due on|Transferred on", 1, 0, 630, 476, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS, $WS_VSCROLL), BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_FLATSB))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 70)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 90)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 120)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 4, 112)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 5, 128)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM)
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
Global $BtnSelectAll = GUICtrlCreateButton("Select All", 645, 9, 75, 25)
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
Global $BtnSelectNone = GUICtrlCreateButton("Select None", 645, 40, 75, 25)
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
Global $Icon1 = GUICtrlCreateIcon( @SystemDir & "\shell32.dll", -132, 639, 128, 16, 16, BitOR($SS_NOTIFY, $WS_GROUP))
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
Global $Icon2 = GUICtrlCreateIcon(@SystemDir & "\shell32.dll", -111, 639, 149, 16, 16, BitOR($SS_NOTIFY, $WS_GROUP))
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
Global $LblNoSelected = GUICtrlCreateLabel("0", 640, 78, 35, 24, $SS_RIGHT);BitOR($SS_RIGHT, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xF5CBC9)
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
Global $Label2 = GUICtrlCreateLabel("= Not selected", 659, 128, 73, 17)
GUICtrlSetBkColor(-1, 0xF5CBC9)
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
Global $Label3 = GUICtrlCreateLabel("= Selected", 659, 149, 55, 17)
GUICtrlSetBkColor(-1, 0xF5CBC9)
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
Global $Label4 = GUICtrlCreateLabel("", 630, 0, 103, 476, $WS_CLIPSIBLINGS)
GUICtrlSetBkColor(-1, 0xF5CBC9)
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH)
GUICtrlSetState(-1, $GUI_DISABLE)
Global $Label5 = GUICtrlCreateLabel("", 636, 75, 94, 1)
GUICtrlSetBkColor(-1, 0x808080)
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
Global $Label6 = GUICtrlCreateLabel("", 636, 121, 94, 1)
GUICtrlSetBkColor(-1, 0x808080)
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
Global $Label1 = GUICtrlCreateLabel("Job", 681, 78, 42, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xF5CBC9)
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)

#EndRegion ### END Koda GUI section ###




_GUICtrlListView_SetExtendedListViewStyle($ListView1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
Global $hListView1 = GUICtrlGetHandle($ListView1)
Global Const $FW_BOLD = 700
Global $Font = _WinAPI_CreateFont(14, 6, 0, 0, $FW_BOLD)

$hImage = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 110)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 131)
_GUICtrlListView_SetImageList($hListView1, $hImage, 2)

GUISetState(@SW_SHOW)
Global $LVItems[10][2], $LVLInes, $LVTotSelected = 0
Local $firstJob = 0

LoadOrderList()


GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    $nMsg = GUIGetMsg()
    ;If $nmsg <> 0 Then ConsoleWrite($nmsg & @CRLF)
    Switch $nMsg
    Case 0



    Case $GUI_EVENT_CLOSE
    Exit
    Case $BtnSelectAll
    $LVTotSelected = 0
    For $iIndex = 0 To _GUICtrlListView_GetItemCount($hListView1) - 1

    _GUICtrlListView_SetItemStateImage($hListView1, $iIndex, 1);set icon selected
    $LVTotSelected += 1

    Next
    SetJobsSelected($LVTotSelected)
    Case $BtnSelectNone
    $LVTotSelected = 0
    For $iIndex = 0 To _GUICtrlListView_GetItemCount($hListView1) - 1
    _GUICtrlListView_SetItemStateImage($hListView1, $iIndex, 2)
    Next
    SetJobsSelected($LVTotSelected)
    EndSwitch


WEnd




Func SetJobsSelected($iSel)
    GUICtrlSetData($LblNoSelected, $iSel)
    If $iSel < 2 Then
    GUICtrlSetData($Label1, "Job")
    Else
    GUICtrlSetData($Label1, "Jobs")
    EndIf



EndFunc ;==>SetJobsSelected


Func LoadOrderList($firstorder = 1, $batched = False)
    ;msgbox(262144,"batched","=" & $batched,3)

    Local $doshowNum, $doShowBatched
    _GUICtrlListView_BeginUpdate($ListView1)
    _GUICtrlListView_DeleteAllItems($hListView1)

    $LVLInes = 0;
    For $n = 1 To 10

    _GUICtrlListView_AddItem($hListView1,"ab" & $n,2)
    For $j = 1 To 5
    _GUICtrlListView_AddSubItem($hListView1, $n-1, "sub" & "/" & $n & $j, $j)
    Next
    $LVTotSelected += 1
    Next


    _GUICtrlListView_EndUpdate($ListView1)
    SetJobsSelected($LVTotSelected)

EndFunc ;==>LoadOrderList

Func _ListView_Click($hWnd, $iIndex)
    If _GUICtrlListView_GetItemStateImage($hWnd, $iIndex) = 1 Then
    _GUICtrlListView_SetItemStateImage($hWnd, $iIndex, 2)
    $LVTotSelected -= 1
    Else
    ; ConsoleWrite("C:" & _GUICtrlListView_GetItemText($hWnd, $iIndex, 5) & @CRLF)
    _GUICtrlListView_SetItemStateImage($hWnd, $iIndex, 1)
    $LVTotSelected += 1
    EndIf

    SetJobsSelected($LVTotSelected)
EndFunc ;==>_ListView_Click

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $hListView1
    If Not IsHWnd($hListView1) Then $hWndListView = GUICtrlGetHandle($hListView1)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
    Case $hWndListView
    Switch $iCode
    Case $LVN_KEYDOWN ; A key has been pressed
    Case $NM_CLICK, $NM_DBLCLK; Sent by a list-view control when the user clicks an item with the left mouse button
    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
    Local $iIndex = DllStructGetData($tInfo, "Index")

    If $iIndex <> -1 Then
    Local $iX = DllStructGetData($tInfo, "X")
    Local $iPart = 1
    If _GUICtrlListView_GetView($hListView1) = 1 Then $iPart = 2 ;for large icons view

    Local $aIconRect = _GUICtrlListView_GetItemRect($hListView1, $iIndex, $iPart)
    ConsoleWrite("353" & @CRLF)
    
    _ListView_Click($hWndListView, $iIndex)
    Return 1
    EndIf

    ; No return value
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY

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.

Share this post


Link to post
Share on other sites

thanks so much! ive been looking for an answer for eons!

Share this post


Link to post
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
Sign in to follow this  
Followers 0