Sign in to follow this  
Followers 0
LeThanh201

Help about GUICtrlCreateListView, Please

8 posts in this topic

Hi, all

I want to create a ListViewItem that I can choose the SubItem. I tried all ways but they are false.

Help me, please!!!!

Thanks, all !

Share this post


Link to post
Share on other sites



Hi, all

I want to create a ListViewItem that I can choose the SubItem. I tried all ways but they are false.

Help me, please!!!!

Thanks, all !

Show us what you have tried, a small script that reproduces the problem(s).


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi, all

I want to create a ListViewItem that I can choose the SubItem. I tried all ways but they are false.

Help me, please!!!!

Thanks, all !

If you mean that you want to know what sub item has been clicked then here is a modified version of a post by gafrost so that the sub item is detected.

; Events - ListView
#include <GuiConstants.au3>;Inclusion file for the GUI interface controls
#include <GuiListView.au3>

Global $ListView
;Global Const $WM_NOTIFY = 0x004E
Global Const $DebugIt = 1

;ListView Events
;Global Const $NM_FIRST = 0
Global Const $NM_LAST = (-99)
;Global Const $NM_OUTOFMEMORY = ($NM_FIRST - 1)
;Global Const $NM_CLICK = ($NM_FIRST - 2)
;Global Const $NM_DBLCLK = ($NM_FIRST - 3)
;Global Const $LVN_FIRST = -100;
;Global Const $LVN_ITEMCHANGED = ($LVN_FIRST-1);

#endregion End Global variables

Opt("WinTitleMatchMode", 2)

$main_GUI = GUICreate("GuiRegisterMsg Test", 225, 400, 300, 10, BitOR($WS_THICKFRAME, $WS_SIZEBOX))

$ListView = GUICtrlCreateListView("Entry Name|Category", 5, 75, 195, 280, BitOR($LVS_SORTASCENDING, $LVS_SINGLESEL))
_GUICtrlListView_SetColumnWidth ($ListView, 0, 100)
_GUICtrlListView_SetColumnWidth ($ListView, 1, 100)
GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
GUICtrlCreateListViewItem("Name 1|Category 1", $ListView)
GUICtrlCreateListViewItem("Name 2|Category 2", $ListView)
GUISetState()

;Register WM_NOTIFY  events
GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")

While 1
   
   $msg = GUIGetMsg()
   
   Switch $msg
     
  ;-----------------------------------------------------------------------------------------
  ;This case statement exits and updates code if needed
      Case $GUI_EVENT_CLOSE
         Exit
         
         
     ;-----------------------------------------------------------------------------------------
     ;put all the misc. stuff here
        Case Else
          ;;;
   EndSwitch
WEnd

Func ListView_Click($it,$sit)
  ;----------------------------------------------------------------------------------------------
    If $DebugIt Then    _DebugPrint ("$NM_CLICK on item " & $it & ", subitem " & $sit)
  ;----------------------------------------------------------------------------------------------
EndFunc ;==>ListView_Click

Func ListView_DoubleClick()
  ;----------------------------------------------------------------------------------------------
    If $DebugIt Then    _DebugPrint ("$NM_DBLCLK")
  ;----------------------------------------------------------------------------------------------
    MsgBox(0,"Double Clicked", _GUICtrlListView_GetItemText ($ListView, _GUICtrlListView_GetSelectedIndices($ListView)))
EndFunc ;==>ListView_DoubleClick

Func ListView_ItemChanged()
  ;----------------------------------------------------------------------------------------------
    If $DebugIt Then    _DebugPrint ("$LVN_ITEMCHANGED: " & _GUICtrlListView_GetItemText ($ListView, _GUICtrlListView_GetSelectedIndices($ListView)))
  ;----------------------------------------------------------------------------------------------
EndFunc

;
; WM_NOTIFY event handler
Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tagNMHDR, $event, $hwndFrom, $code
    $tagNMHDR = DllStructCreate("int;int;int;int;int", $lParam);NMHDR (hwndFrom, idFrom, code)
    If @error Then Return
    $event = DllStructGetData($tagNMHDR, 3)
    Select
    Case $wParam = $ListView
        Select
            Case $event = $NM_CLICK
                ListView_Click (DllStructGetData($tagNMHDR, 4), DllStructGetData($tagNMHDR, 5))
                
            Case $event = $NM_DBLCLK
                ListView_DoubleClick ()
            Case $event = $LVN_ITEMCHANGED
                ListView_ItemChanged()
            EndSelect
    EndSelect
    $tagNMHDR = 0
    $event = 0
    $lParam = 0
EndFunc ;==>WM_Notify_Events

Func _DebugPrint($s_text)
    $s_text = StringReplace($s_text, @LF, @LF & "-->")
    ConsoleWrite("!===========================================================" & @LF & _
            "+===========================================================" & @LF & _
            "-->" & $s_text & @LF & _
            "+===========================================================" & @LF)
EndFunc ;==>_DebugPrint

EDIT: It obviously took me a long time to do that, I didn't see you there Garry.

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.

Share this post


Link to post
Share on other sites

#include <GUIConstants.au3>
#include<buttonconstants.au3>
#include <ListviewConstants.au3>

opt('mustdeclarevars', 1)

Global $ok, $item1, $dulieu, $docten, $msg, $ten, $chinh, $dulieu

GUICreate('My Country', 500, 300)
$ok = GUICtrlCreateButton("OK", 100, 200, 50, 30, $BS_DEFPUSHBUTTON)
$chinh = GUICtrlCreateListView("FULLNAME                |BIRTHDAY        |  ADDRESS", 30, 30, 450, 150, $LVS_EDITLABELS, $LVS_EX_GRIDLINES)
$item1 = GUICtrlCreateListViewItem("Le Van Thanh        |20/01/1991|VietNam", $chinh)
GUICtrlRead(GUICtrlRead($chinh))

GUISetState()
while 1
    GUICtrlRead(GUICtrlRead($chinh))
    $msg = GUIGetMsg()
    Select
    case $msg = $gui_event_close
        Exit
    Case $msg = $ok
        $dulieu = GUICtrlRead(GUICtrlRead($chinh))
        
        GUICtrlSetData($item1, $dulieu)
    EndSelect
    WEnd

I want to choose SubItem in BIRTDAY column and ADDRESS column. And What can I do to when I click OK button, I update my new data???

Thanks.

Share this post


Link to post
Share on other sites

#include <GUIConstants.au3>
#include<buttonconstants.au3>
#include <ListviewConstants.au3>

opt('mustdeclarevars', 1)

Global $ok, $item1, $dulieu, $docten, $msg, $ten, $chinh, $dulieu

GUICreate('My Country', 500, 300)
$ok = GUICtrlCreateButton("OK", 100, 200, 50, 30, $BS_DEFPUSHBUTTON)
$chinh = GUICtrlCreateListView("FULLNAME                |BIRTHDAY        |  ADDRESS", 30, 30, 450, 150, $LVS_EDITLABELS, $LVS_EX_GRIDLINES)
$item1 = GUICtrlCreateListViewItem("Le Van Thanh        |20/01/1991|VietNam", $chinh)
GUICtrlRead(GUICtrlRead($chinh))

GUISetState()
while 1
    GUICtrlRead(GUICtrlRead($chinh))
    $msg = GUIGetMsg()
    Select
    case $msg = $gui_event_close
        Exit
    Case $msg = $ok
        $dulieu = GUICtrlRead(GUICtrlRead($chinh))
        
        GUICtrlSetData($item1, $dulieu)
    EndSelect
    WEnd

I want to choose SubItem in BIRTDAY column and ADDRESS column. And What can I do to when I click OK button, I update my new data???

Thanks.

if you haven't got enough information already then have a look at eltorro's editable listview.

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

LeThanh201

Quick example:

#include <GUIConstants.au3>
#include <GUIListView.au3>

GUICreate('My Country', 500, 240)

$ok = GUICtrlCreateButton("OK", 30, 200, 72, 27, $BS_DEFPUSHBUTTON)

$hListView = GUICtrlCreateListView("FULLNAME|BIRTHDAY|ADDRESS", 30, 30, 440, 150, _
BitOR($LVS_REPORT, $LVS_SINGLESEL), BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $WS_EX_CLIENTEDGE))

_GUICtrlListView_SetColumnWidth($hListView, 0, 235)
_GUICtrlListView_SetColumnWidth($hListView, 1, 100)
_GUICtrlListView_SetColumnWidth($hListView, 2, 100)

_GUICtrlListView_AddItem($hListView, "Le Van Thanh")
_GUICtrlListView_AddSubItem($hListView, 0, "20/01/1991", 1)
_GUICtrlListView_AddSubItem($hListView, 0, "VietNam", 2)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $gui_event_close
            ExitLoop
        Case $msg = $ok
            $aIndex = _GUICtrlListView_GetSelectedIndices($hListView, True)
            If $aIndex[0] > 0 Then
                MsgBox(0, "", _GUICtrlListView_GetItemText($hListView, $aIndex[1]) & @LF & _
                       _GUICtrlListView_GetItemText($hListView, $aIndex[1], 1) & @LF & _
                       _GUICtrlListView_GetItemText($hListView, $aIndex[1], 2))
            EndIf
    EndSelect
WEnd

Share this post


Link to post
Share on other sites

LeThanh201

Quick example:

#include <GUIConstants.au3>
#include <GUIListView.au3>

GUICreate('My Country', 500, 240)

$ok = GUICtrlCreateButton("OK", 30, 200, 72, 27, $BS_DEFPUSHBUTTON)

$hListView = GUICtrlCreateListView("FULLNAME|BIRTHDAY|ADDRESS", 30, 30, 440, 150, _
BitOR($LVS_REPORT, $LVS_SINGLESEL), BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $WS_EX_CLIENTEDGE))

_GUICtrlListView_SetColumnWidth($hListView, 0, 235)
_GUICtrlListView_SetColumnWidth($hListView, 1, 100)
_GUICtrlListView_SetColumnWidth($hListView, 2, 100)

_GUICtrlListView_AddItem($hListView, "Le Van Thanh")
_GUICtrlListView_AddSubItem($hListView, 0, "20/01/1991", 1)
_GUICtrlListView_AddSubItem($hListView, 0, "VietNam", 2)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $gui_event_close
            ExitLoop
        Case $msg = $ok
            $aIndex = _GUICtrlListView_GetSelectedIndices($hListView, True)
            If $aIndex[0] > 0 Then
                MsgBox(0, "", _GUICtrlListView_GetItemText($hListView, $aIndex[1]) & @LF & _
                       _GUICtrlListView_GetItemText($hListView, $aIndex[1], 1) & @LF & _
                       _GUICtrlListView_GetItemText($hListView, $aIndex[1], 2))
            EndIf
    EndSelect
WEnd

It is mean that I can't choose my subitem and I can't edit my listview. Oh, it is seem so boring

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