Sign in to follow this  
Followers 0
NearValue

GUICtrlCreateListView() and _GUICtrlListView_Create() problem

5 posts in this topic

Having problems with GUICtrlCreateListView() and _GUICtrlListView_Create(). 

 

But if I use either of them, sorting (by clicking the header to arrange the list) using GUICtrlCreateListView() it works. But for _GUICtrlListView_Create() it won't. Same thing happens for editing the list using GUICtrlCreateListView().

 

;GUICtrlCreateListView() sorting works. Editing fails.

 

#include <GuiEdit.au3>
#include <GUIListViewEx_Mod.au3>
#include <GuiImageList.au3>
#include <String.au3>
#include <Misc.au3>
#include <File.au3>
#include <Timers.au3>
#include <WinAPI.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GUIListBox.au3>
#include <ListviewConstants.au3>
 
Global $hEdit, $hDC, $hBrush, $Item = -1, $SubItem = 0
 
Global $Style = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT)
Global $aIcons[3] = [0, 3, 6], $font = "Gill Sans"
 
Global $hGUI = GUICreate("TEST CLIENT", 1600, 900)
 
$hListView = GUICtrlCreateListView("TEST1|TEST2|TEST3", 5, 100, 938, 500)
 
;$hListView = _GUICtrlListView_Create($hGUI, "TEST1|TEST2|TEST3", 5, 100, 938, 500, $LVS_REPORT, $WS_EX_CLIENTEDGE)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_HEADERDRAGDROP, $LVS_EX_BORDERSELECT, $LVS_EX_ONECLICKACTIVATE, $LVS_EDITLABELS,$WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE))
 
$hNM_DBCLK = GUICtrlCreateDummy()
$hEN_KILLFOCUS = GUICtrlCreateDummy()
 
_AddRow($hListView, "1|A|NAME1", $aIcons, 1)
_AddRow($hListView, "2|B|NAME2", $aIcons, 2)
_AddRow($hListView, "3|C|NAME3", $aIcons, 3)
 
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
 
GUISetState(@SW_SHOW, $hGUI)
 
_GUICtrlListView_RegisterSortCallBack($hListView)
 
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        case $hNM_DBCLK
            Start_EditingLV()
        Case $hEN_KILLFOCUS
            End_EditingLV()
Case $hListView
_GUICtrlListView_SortItems($hListView, GUICtrlGetState($hListView))
    EndSwitch
WEnd
 
_GUICtrlListView_UnRegisterSortCallBack($hListView)
GUIDelete()
 
;===============================================================
 
Func _AddRow($hWnd, $sItem, $aIcons, $iPlus = 0)
Local $aItem = StringSplit($sItem, "|")
Local $iIndex = _GUICtrlListView_AddItem($hWnd, $aItem[1], $aIcons[0] + $iPlus, _GUICtrlListView_GetItemCount($hWnd) + 99999)
_GUICtrlListView_SetColumnWidth($hWnd, 0, $LVSCW_AUTOSIZE_USEHEADER)
 
For $x = 2 To $aItem[0]
_GUICtrlListView_AddSubItem($hWnd, $iIndex, $aItem[$x], $x - 1, $aIcons[$x - 1] + $iPlus)
_GUICtrlListView_SetColumnWidth($hWnd, $x - 1, $LVSCW_AUTOSIZE)
Next
EndFunc   ;==>_AddRow
 
 
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $tNMHDR, $hWndFrom, $iCode
 
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
 
Switch $hWndFrom
Case $hListView
Switch $iCode
Case $NM_DBLCLK
                    GUICtrlSendToDummy($hNM_DBCLK)
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
 
Func FrameRect($hDC, $nLeft, $nTop, $nRight, $nBottom, $hBrush)
 
 
Local $stRect = DllStructCreate("int;int;int;int")
 
DllStructSetData($stRect, 1, $nLeft)
DllStructSetData($stRect, 2, $nTop)
DllStructSetData($stRect, 3, $nRight)
DllStructSetData($stRect, 4, $nBottom)
 
DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush)
EndFunc
 
Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
Local $iCode = BitShift($wParam, 16)
 
Switch $lParam
Case $hEdit
Switch $iCode
Case $EN_KILLFOCUS
                    GUICtrlSendToDummy($hEN_KILLFOCUS)
EndSwitch
EndSwitch
 
Return $GUI_RUNDEFMSG
EndFunc
 
Func Start_EditingLV()
    ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))
 
    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView)
    Local $hRect = ControlGetPos($hGUI, "", $hListView)
 
    If ($aHit[0] <> -1) And ($aHit[1] = 0) Then
        $Item = $aHit[0]
        $SubItem = 0
        Local $aRect = _GUICtrlListView_GetItemRect($hListView, $Item)
    ElseIf ($aHit[0] <> -1) And ($aHit[1] > 0) Then
        $Item = $aHit[0]
        $SubItem = $aHit[1]
        Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $Item, $SubItem) ;dldl
    Else
        Return $GUI_RUNDEFMSG
    EndIf
 
    Local $iItemText = _GUICtrlListView_GetItemText($hListView, $Item, $SubItem)
    Local $iLen = _GUICtrlListView_GetStringWidth($hListView, $iItemText)
    $hEdit = _GUICtrlEdit_Create($hGUI, $iItemText, $aRect[0] + ($hRect[0] + 3), $aRect[1] + $hRect[1], $iLen + 10, 17, $Style)
 
    _GUICtrlEdit_SetSel($hEdit, 0, -1)
    _WinAPI_SetFocus($hEdit)
    $hDC = _WinAPI_GetWindowDC($hEdit)
    $hBrush = _WinAPI_CreateSolidBrush(0x0000FF)
    FrameRect($hDC, 0,0, $iLen + 10 , 17, $hBrush)
    HotKeySet("{ENTER}", "End_EditingLV")
 
EndFunc
 
Func End_EditingLV()
    Local $iText = _GUICtrlEdit_GetText($hEdit)
    _GUICtrlListView_SetItemText($hListView, $Item, $iText, $SubItem)
    _WinAPI_DeleteObject($hBrush)
    _WinAPI_ReleaseDC($hEdit, $hDC)
    _WinAPI_DestroyWindow($hEdit)
    ControlEnable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))
 
    $Item = -1
    $SubItem = 0
    HotKeySet("{ENTER}")
EndFunc
 

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

From this example: _GUICtrlListView_Create() was used and editing the list works, sorting the list fails.

#include <GuiEdit.au3>
#include <GUIListViewEx_Mod.au3>
#include <GuiImageList.au3>
#include <String.au3>
#include <Misc.au3>
#include <File.au3>
#include <Timers.au3>
#include <WinAPI.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GUIListBox.au3>
#include <ListviewConstants.au3>
 
Global $hEdit, $hDC, $hBrush, $Item = -1, $SubItem = 0
 
Global $Style = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT)
Global $aIcons[3] = [0, 3, 6], $font = "Gill Sans"
 
Global $hGUI = GUICreate("TEST CLIENT", 1600, 900)
 
;$hListView = GUICtrlCreateListView("TEST1|TEST2|TEST3", 5, 100, 938, 500)
 
$hListView = _GUICtrlListView_Create($hGUI, "TEST1|TEST2|TEST3", 5, 100, 938, 500, $LVS_REPORT, $WS_EX_CLIENTEDGE)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_HEADERDRAGDROP, $LVS_EX_BORDERSELECT, $LVS_EX_ONECLICKACTIVATE, $LVS_EDITLABELS,$WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE))
 
$hNM_DBCLK = GUICtrlCreateDummy()
$hEN_KILLFOCUS = GUICtrlCreateDummy()
 
_AddRow($hListView, "1|A|NAME1", $aIcons, 1)
_AddRow($hListView, "2|B|NAME2", $aIcons, 2)
_AddRow($hListView, "3|C|NAME3", $aIcons, 3)
 
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
 
GUISetState(@SW_SHOW, $hGUI)
 
_GUICtrlListView_RegisterSortCallBack($hListView)
 
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        case $hNM_DBCLK
            Start_EditingLV()
        Case $hEN_KILLFOCUS
            End_EditingLV()
Case $hListView
_GUICtrlListView_SortItems($hListView, GUICtrlGetState($hListView))
    EndSwitch
WEnd
 
_GUICtrlListView_UnRegisterSortCallBack($hListView)
GUIDelete()
 
;===============================================================
 
Func _AddRow($hWnd, $sItem, $aIcons, $iPlus = 0)
Local $aItem = StringSplit($sItem, "|")
Local $iIndex = _GUICtrlListView_AddItem($hWnd, $aItem[1], $aIcons[0] + $iPlus, _GUICtrlListView_GetItemCount($hWnd) + 99999)
_GUICtrlListView_SetColumnWidth($hWnd, 0, $LVSCW_AUTOSIZE_USEHEADER)
 
For $x = 2 To $aItem[0]
_GUICtrlListView_AddSubItem($hWnd, $iIndex, $aItem[$x], $x - 1, $aIcons[$x - 1] + $iPlus)
_GUICtrlListView_SetColumnWidth($hWnd, $x - 1, $LVSCW_AUTOSIZE)
Next
EndFunc   ;==>_AddRow
 
 
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $tNMHDR, $hWndFrom, $iCode
 
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
 
Switch $hWndFrom
Case $hListView
Switch $iCode
Case $NM_DBLCLK
                    GUICtrlSendToDummy($hNM_DBCLK)
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
 
Func FrameRect($hDC, $nLeft, $nTop, $nRight, $nBottom, $hBrush)
 
 
Local $stRect = DllStructCreate("int;int;int;int")
 
DllStructSetData($stRect, 1, $nLeft)
DllStructSetData($stRect, 2, $nTop)
DllStructSetData($stRect, 3, $nRight)
DllStructSetData($stRect, 4, $nBottom)
 
DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush)
EndFunc
 
Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
Local $iCode = BitShift($wParam, 16)
 
Switch $lParam
Case $hEdit
Switch $iCode
Case $EN_KILLFOCUS
                    GUICtrlSendToDummy($hEN_KILLFOCUS)
EndSwitch
EndSwitch
 
Return $GUI_RUNDEFMSG
EndFunc
 
Func Start_EditingLV()
    ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))
 
    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView)
    Local $hRect = ControlGetPos($hGUI, "", $hListView)
 
    If ($aHit[0] <> -1) And ($aHit[1] = 0) Then
        $Item = $aHit[0]
        $SubItem = 0
        Local $aRect = _GUICtrlListView_GetItemRect($hListView, $Item)
    ElseIf ($aHit[0] <> -1) And ($aHit[1] > 0) Then
        $Item = $aHit[0]
        $SubItem = $aHit[1]
        Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $Item, $SubItem) ;dldl
    Else
        Return $GUI_RUNDEFMSG
    EndIf
 
    Local $iItemText = _GUICtrlListView_GetItemText($hListView, $Item, $SubItem)
    Local $iLen = _GUICtrlListView_GetStringWidth($hListView, $iItemText)
    $hEdit = _GUICtrlEdit_Create($hGUI, $iItemText, $aRect[0] + ($hRect[0] + 3), $aRect[1] + $hRect[1], $iLen + 10, 17, $Style)
 
    _GUICtrlEdit_SetSel($hEdit, 0, -1)
    _WinAPI_SetFocus($hEdit)
    $hDC = _WinAPI_GetWindowDC($hEdit)
    $hBrush = _WinAPI_CreateSolidBrush(0x0000FF)
    FrameRect($hDC, 0,0, $iLen + 10 , 17, $hBrush)
    HotKeySet("{ENTER}", "End_EditingLV")
 
EndFunc
 
Func End_EditingLV()
    Local $iText = _GUICtrlEdit_GetText($hEdit)
    _GUICtrlListView_SetItemText($hListView, $Item, $iText, $SubItem)
    _WinAPI_DeleteObject($hBrush)
    _WinAPI_ReleaseDC($hEdit, $hDC)
    _WinAPI_DestroyWindow($hEdit)
    ControlEnable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))
 
    $Item = -1
    $SubItem = 0
    HotKeySet("{ENTER}")
EndFunc
 
Edited by NearValue

Share this post


Link to post
Share on other sites

Are you sure that you posted the right scripts? I can't edit either of them at all, but it sorts just fine on both.

 

BTW, unrelated to the problem. Your extended style settings will NOT work as you expect. $LVS_EX_GRIDLINES and $WS_EX_DLGMODALFRAME are the same value, and only the first one should be used as a ListView style setting, $WS_EX styles are windows style, $LVS_EX are listview styles.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Woops! My bad forgot to enable _GUICtrlListView_Create() part and disable the other. 2nd example should be ready

Share this post


Link to post
Share on other sites

GUIGetMsg works with control IDs returned by native functions, _GUICtrlListview_Create returns a handle and not a control ID so you can't use GUIGetMsg with a UDF created control, such as the LV you're using.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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

  • Similar Content

    • PINTO1927
      By PINTO1927
      Hello guys,
      I'm working with a simple script, complementing a GUICtrlCreateListView which has 5 columns. I would order the first column so that the numbers are decreasing.
      #include <GuiListView.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <GuiConstantsEx.au3> #include <StructureConstants.au3> Opt('MustDeclareVars', 1) Global $search_LV, $B_DESCENDING GUICreate("ListView Sort by Column Click", 400, 300) $search_LV = GUICtrlCreateListView("String|Number|String", 2, 2, 394, 268) GUICtrlSendMsg($search_LV, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) GUICtrlSendMsg($search_LV, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT) GUICtrlCreateListViewItem("line4|5|1A", $search_LV) GUICtrlCreateListViewItem("line5|4.50 |1B", $search_LV) GUICtrlCreateListViewItem("line10|4.0 |2C", $search_LV) GUICtrlCreateListViewItem("line3|23|01", $search_LV) GUICtrlCreateListViewItem("line2|0.34560 |09", $search_LV) GUICtrlCreateListViewItem("line1|1.0 |7A", $search_LV) GUICtrlCreateListViewItem("line1|0.1 |8C", $search_LV) GUICtrlCreateListViewItem("line1|97|5B", $search_LV) GUICtrlCreateListViewItem("line1|910|9B", $search_LV) GUICtrlCreateListViewItem("line1|99|11", $search_LV) GUICtrlCreateListViewItem("line1|990.99|06", $search_LV) _GUICtrlListView_SetColumnWidth($search_LV, 0, 75) _GUICtrlListView_SetColumnWidth($search_LV, 1, 75) _GUICtrlListView_SetColumnWidth($search_LV, 2, 75) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ;~ _GUICtrlListView_RegisterSortCallBack($search_LV, False) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $search_LV ; Kick off the sort callback ;~ _GUICtrlListView_SortItems($search_LV, GUICtrlGetState($search_LV)) ;~ _GUICtrlListView_UnRegisterSortCallBack($search_LV) EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $hWndListView = $search_LV ;~ If Not IsHWnd($search_LV) Then $hWndListView = GUICtrlGetHandle($search_LV) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom ;~ Case $search_LV Case GUICtrlGetHandle($search_LV) Switch $iCode Case $LVN_COLUMNCLICK ; A column was clicked ConsoleWrite("Header geklickt" & @CRLF) Local $tInfo = DllStructCreate($tagNMLISTVIEW, $iLparam) _GUICtrlListView_UnRegisterSortCallBack($search_LV) Local $ColumnSorted = DllStructGetData($tInfo, 'SubItem') If $ColumnSorted = 1 Then ConsoleWrite('Numeric: ' & _GUICtrlListView_RegisterSortCallBack($search_LV, True) & @CRLF) Else ConsoleWrite('Literal: ' & _GUICtrlListView_RegisterSortCallBack($search_LV, False) & @CRLF) EndIf _GUICtrlListView_SortItems($search_LV, DllStructGetData($tInfo, 'SubItem')) EndSwitch EndSwitch EndFunc ;==>WM_NOTIFY Ordering the "String" column, you notice that the line "line10" is not ordered last. And 'possible to order the "String" column in descending order?
      thank you very much
    • david1337
      By david1337
      Hey guys
      Quick question:
      In this GUI the listview is created from items in test.txt
      I would like my "Get Info" button to show the actual text of the item that is selected. So far I have been able to make it show the number of the item.
      What is the last missing puzzle here?
       
      #include <GUIConstantsEx.au3> #include <GUIListViewEx.au3> Global $MainGUI_ManageItemList Global $File = "test.txt" Global $FileToArray = FileReadToArray("test.txt") Call ("MainGUI_ManageItemList") Func MainGUI_ManageItemList() Local $Button1 $MainGUI_ManageItemList = GUICreate("Manage Item List", 800, 400, -1, -1) $cLV = GUICtrlCreateListView("[items]", 10, 10, 400, 775, $LVS_NOCOLUMNHEADER) GUICtrlSetFont(-1, 12, 800, 0, "@Arial Unicode MS") _GUICtrlListView_SetColumnWidth($cLV, 0, 378) $Button1 = GUICtrlCreateButton("Button 1", 425, 10, 80, 30) $RemoveItem = GUICtrlCreateButton("Remove Item", 425, 50, 80, 30) $GetInfo = GUICtrlCreateButton("GetInfo", 425, 120, 80, 30) GUISetState(@SW_SHOW, $MainGUI_ManageItemList) ; Intialise ListView Global $iLV_Index = _GUIListViewEx_Init($cLV) ; Insert lines _GUIListViewEx_Insert($FileToArray, True) ; Register required messages _GUIListViewEx_MsgRegister(True, False, False, False) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button1 MsgBox(0,"","Button 1 is pressed") Case $RemoveItem _GUIListViewEx_Delete() Case $GetInfo $iIndex = _GUICtrlListView_GetSelectedIndices($cLV) msgbox (0, "Selected item", $iIndex) EndSwitch WEnd EndFunc ;==>Main  
    • PINTO1927
      By PINTO1927
      Hi Guys,
      I'm working on this project:
      $Import = GUICtrlCreateButton("Import", 15, 175, 90, 40, $WS_GROUP) $List = GUICtrlCreateListView("Name|Address|E-mail", 15, 220, 400, 363, $LVS_SORTDESCENDING) $Item1 = GUICtrlCreateListViewItem("test|test|test", $List) GUISetState(@SW_SHOW, $GUI) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $Exit Exit Case $Import $Table_Import = FileOpenDialog("Import list '*.txt'", @DesktopDir & "\", "Text (*.txt)") If @error Then ContinueLoop GUICtrlSetData($Item1, $Table_Import) In the text file the fields are delimited with "|" and the values are not in the same row but one below the other.
      However in the txt file the sum of the values may change.
      Can you help me?
      Thank's
    • PINTO1927
      By PINTO1927
      Hello guys,
      I built a gui where a GUICtrlCreateListView with two columns is present.
      Through an "Import" button I would be able to import the contents of an .xls or .txt.
      Can you help me?
      Thank's
    • AutoBert
      By AutoBert
      I have a LV with different coloured Cols:
      ;https://autoit.de/index.php/Thread/84279-Unterschiedliche-Textfarben-innerhalb-einer-ListView/?postID=674195#post674195 #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <array.au3> #include <ListViewConstants.au3> #include <StructureConstants.au3> #include <WindowsConstants.au3> $aColBK = IniReadSection(@ScriptDir & "\lv_format.ini", "ColBKColor") _ArrayDelete($aColBK, 0) ;_ArrayDisplay($aColBK) $aRowBK = IniReadSection(@ScriptDir & "\lv_format.ini", "RowBKColor") _ArrayDelete($aRowBK, 0) ;_ArrayDisplay($aColBK) $aColText = IniReadSection(@ScriptDir & "\lv_format.ini", "ColTextColor") _ArrayDelete($aColText, 0) ;_ArrayDisplay($aColBK) $aRowText = IniReadSection(@ScriptDir & "\lv_format.ini", "RowTextColor") _ArrayDelete($aRowText, 0) ;_ArrayDisplay($aRowText) $GUI = GUICreate("Listview Farbig", 1024, 300, 0, 0) ;<==== Breite geändert $cListView = GUICtrlCreateListView("", 2, 2, 1020, 294, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) ;<==== Breite geändert $hListView = GUICtrlGetHandle($cListView) For $i = 1 To 31 _GUICtrlListView_InsertColumn($hListView, $i - 1, $i, 25) _GUICtrlListView_SetColumnWidth($hListView, $i - 1, 32) ;<==== eingefügt für Spaltenbreite Next For $i = 0 To 21 ; alle Item/SubItem erstellen _GUICtrlListView_AddItem($hListView, "Item: " &$i, $i) For $j = 1 To 30 _GUICtrlListView_AddSubItem($hListView, $i, "Sub: "&$j, $j) Next Next GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState() While True $msg = GUIGetMsg() Switch $msg Case -3 ExitLoop EndSwitch WEnd Func WM_NOTIFY($hWnd, $msg, $wParam, $lParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) Local $iDrawStage, $iItem, $iSubitem, $hDC, $tRect $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage') Switch $iDrawStage Case $CDDS_ITEMPREPAINT Return $CDRF_NOTIFYSUBITEMDRAW Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM) ; Item/SubItem das aktuell gezeichnet werden soll ermitteln $iItem = DllStructGetData($tCustDraw, 'dwItemSpec') $iSubitem = DllStructGetData($tCustDraw, 'iSubItem') Switch $iItem ; Zeilenwahl Case -1 ;kommt nicht vor ist aber notwendig, damit case else verwendet werden kann Case Else $iIndex = _ArraySearch($aRowBK, $iItem, 0, 0, 0, 0, 1, 0) If $iIndex = -1 Then ;nicht im Array für spezielle Zeilen also weiß DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR(0xFFFFFF)) Else DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR($aRowBK[$iIndex][1])) ;ConsoleWrite('Item '&$iItem&' BK: '&$aRowBK[$iIndex][1] & @CRLF) EndIf $iIndex = _ArraySearch($aRowText, $iItem, 0, 0, 0, 0, 1, 0) If $iIndex = -1 Then ;nicht im Array für spezielle Zeilen also schwarz DllStructSetData($tCustDraw, 'clrText', RGB2BGR(0x000000)) Else DllStructSetData($tCustDraw, 'clrText', RGB2BGR($aRowText[$iIndex][1])) ;ConsoleWrite('Item '&$iItem&' Text: '&$aRowText[$iIndex][1] & @CRLF) EndIf EndSwitch Switch $iSubitem Case -1 ;kommt nicht vor ist aber notwendig, damit case else verwendet werden kann Case Else $iIndex = _ArraySearch($aColBK, $iSubitem, 0, 0, 0, 0, 1, 0) If $iIndex <> -1 Then DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR($aColBK[$iIndex][1])) ;ConsoleWrite('SubItem '&$iSubitem&' BK: '&$aColBK[$iIndex][1] & @CRLF) EndIf $iIndex = _ArraySearch($aColText, $iSubitem, 0, 0, 0, 0, 1, 0) If $iIndex <> -1 Then DllStructSetData($tCustDraw, 'clrText', RGB2BGR($aColText[$iIndex][1])) ;ConsoleWrite('SubItem '&$iSubitem&' Text: '&$aColText[$iIndex][1] & @CRLF) EndIf EndSwitch Return $CDRF_NEWFONT EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func RGB2BGR($iColor) Local $sH = Hex($iColor, 6) Return '0x' & StringRight($sH, 2) & StringMid($sH, 3, 2) & StringLeft($sH, 2) EndFunc ;==>RGB2BGR i use lv_format.ini for defining the cols Background- and Textcolour. Now i want to colour the cols in the LV-Header also, but i can't figure it out.