Jump to content

Mixed-Rows Edit and Combo boxes in ListView


 Share

Recommended Posts

I'm trying to make some param-choising LisyView with mixed Edit and Combo boxes in different rows, but...

Combos appear blank and not get filled

cannot properly redraw ListView after deleting Edit and Combo Boxes

#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <StructureConstants.au3>
#include <FontConstants.au3>
#include <WinAPI.au3>
#include <GuiEdit.au3>
#include <EditConstants.au3>
#include <GuiComboBoxEx.au3>
#include <Array.au3>


Opt("GUIOnEventMode", 1)

Global Const $tagNMLVCACHEHINT = $tagNMHDR & ";int iFrom;int iTo"
Global $aHit[2] = [ -1, -1 ]
Global $Style_LWEditBox = BitOR($WS_CHILD, $WS_VISIBLE, $WS_BORDER, $ES_AUTOHSCROLL, $ES_LEFT)
Global $Style_LWComboBox = BitOR($CBS_DROPDOWN, $WS_VSCROLL, $WS_CHILD, $WS_TABSTOP, $WS_VISIBLE)
Global $hEdit, $hCombo, $Item = -1, $SubItem = 0
Global $aLWVariableChoises[8] = ["1|11|111","","3|33,|333","4|44|444","5|55|555","","",""]
Global $aLWActualChoises[8] = ["","","","","","","",""]

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 613, 220, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1_Close")
$ListView1 = GUICtrlCreateListView("Param Name|Param Value", 8, 8, 594, 198, BitOR($GUI_SS_DEFAULT_LISTVIEW,$LVS_EDITLABELS,$LVS_NOSORTHEADER,$LVS_ALIGNLEFT,$WS_BORDER), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE,$LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT,$LVS_EX_DOUBLEBUFFER))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 150)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 433)
$ListView1_0 = GUICtrlCreateListViewItem("Param 1|111", $ListView1)
$ListView1_1 = GUICtrlCreateListViewItem("Param 2|222", $ListView1)
$ListView1_2 = GUICtrlCreateListViewItem("Param 3|333", $ListView1)
$ListView1_3 = GUICtrlCreateListViewItem("Param 4|444", $ListView1)
$ListView1_4 = GUICtrlCreateListViewItem("Param 5|555", $ListView1)
$ListView1_5 = GUICtrlCreateListViewItem("Param 6|666", $ListView1)
$ListView1_6 = GUICtrlCreateListViewItem("Param 7|777", $ListView1)
$ListView1_7 = GUICtrlCreateListViewItem("Param 8|888", $ListView1)
$hListView = GUICtrlGetHandle($ListView1)
;------------------------------------------------------------------------------------------
Local $hDC = _WinAPI_GetDC($hListView)
Local $hFont = _SendMessage($hListView, $WM_GETFONT)
Local $hObject = _WinAPI_SelectObject($hDC, $hFont)
Local $lvLOGFONT = DllStructCreate($tagLOGFONT)
DllCall('gdi32.dll', 'int', 'GetObjectW', 'ptr', $hFont, 'int', DllStructGetSize($lvLOGFONT), 'ptr', DllStructGetPtr($lvLOGFONT))
_WinAPI_SelectObject($hDC, $hObject)
_WinAPI_ReleaseDC($hListView, $hDC)
Global $hListViewfont = _WinAPI_CreateFontIndirect( $lvLOGFONT )
Local $iWeight = BitOR( DllStructGetData( $lvLOGFONT, "Weight" ), $FW_BOLD )
DllStructSetData( $lvLOGFONT, "Weight", $iWeight )
Global $hListViewfontBold = _WinAPI_CreateFontIndirect( $lvLOGFONT )
;------------------------------------------------------------------------------------------
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
    Sleep(100)
WEnd
;--------------------------------------------------------------
Func Form1_Close()
    _ArrayDisplay($aLWActualChoises,"$aLWActualChoises")
    Exit
EndFunc
;--------------------------------------------------------------
Func WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam )

    Local $tNMHDR, $hWndFrom, $iCode
    $tNMHDR = DllStructCreate( $tagNMHDR, $lParam )
    $hWndFrom = HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) )
    $iCode = DllStructGetData( $tNMHDR, "Code" )

    Switch $hWndFrom
        Case $hListView

            Switch $iCode

                Case $LVN_ITEMCHANGED
                    Local $tNMLISTVIEW, $iItem, $aInfo
                    $tNMLISTVIEW = DllStructCreate( $tagNMLISTVIEW, $lParam )
                    $iItem = DllStructGetData( $tNMLISTVIEW, "Item" )




                Case $NM_CUSTOMDRAW
                    Local $tNMLVCUSTOMDRAW = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
                    Local $dwDrawStage = DllStructGetData($tNMLVCUSTOMDRAW, "dwDrawStage")
                    Local $dwItemSpec  = DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec")

                    Switch $dwDrawStage                ; Holds a value that specifies the drawing stage

                        Case $CDDS_PREPAINT
                            ; Before the paint cycle begins
                            Return $CDRF_NOTIFYITEMDRAW    ; Notify the parent window of any item-related drawing operations

                        Case $CDDS_ITEMPREPAINT;, $CDDS_SUBITEM
                            ; Before painting an item
                            Return $CDRF_NOTIFYITEMDRAW
                            ;Return $CDRF_NEWFONT           ; $CDRF_NEWFONT must be returned after changing font or colors

                        Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM)
                            ; Before painting a subitem
                            ;Local $dwItemSpec = DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec")              ; Item index
                            Local $iSubItem = DllStructGetData($tNMLVCUSTOMDRAW, "iSubItem")                  ; Subitem index
                            Local $hDC = DllStructGetData($tNMLVCUSTOMDRAW, "HDC")                            ; Handle to the item's device context

                            Switch $iSubItem
                                Case 0; parameter name
                                    _WinAPI_SelectObject($hDC, $hListViewfontBold)
                                    DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xE5E4E2 )
                                    DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText", 0x000000)  ; Forecolor of item text  AntiqueWhite

                                Case 1; parameter value
                                    _WinAPI_SelectObject($hDC, $hListViewfont)
                                    If Mod( $dwItemSpec, 2 ) = 0 Then
                                        DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xF2F3F4 )
                                    Else
                                        DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFCFCFC )
                                    EndIf
                                    DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText", 0x000000)  ; Forecolor of item text

                            EndSwitch
                            Return $CDRF_NEWFONT
                    EndSwitch

                Case $NM_CLICK
                    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView)
                    If ($aHit[0] <> -1) And ($aHit[1] > 0) Then
                        $Item = $aHit[0]
                        $SubItem = $aHit[1]
                        Local $iSubItemText = _GUICtrlListView_GetItemText($hListView, $Item, $SubItem)
                        Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $Item, $SubItem)

                        If $SubItem == 1 Then
                            Switch $Item
                                Case 1,5 To 7
                                    $hEdit = _GUICtrlEdit_Create($Form1, $iSubItemText, $aRect[0] + 10, $aRect[1] + 12, $aRect[2] - $aRect[0], 20, $Style_LWEditBox)
                                    _WinAPI_SetFocus($hEdit)
                                Case 0
                                    $hCombo = _GUICtrlComboBoxEx_Create($Form1,$aLWVariableChoises[$Item], $aRect[0] + 10, $aRect[1] + 12, $aRect[2] - $aRect[0], 20, $Style_LWComboBox)
                                    _WinAPI_SetFocus($hCombo)
                                Case 2
                                    $hCombo = _GUICtrlComboBoxEx_Create($Form1,$aLWVariableChoises[$Item], $aRect[0] + 10, $aRect[1] + 12, $aRect[2] - $aRect[0], 20, $Style_LWComboBox)
                                    _WinAPI_SetFocus($hCombo)
                                Case 3
                                    $hCombo = _GUICtrlComboBoxEx_Create($Form1,$aLWVariableChoises[$Item], $aRect[0] + 10, $aRect[1] + 12, $aRect[2] - $aRect[0], 20, $Style_LWComboBox)
                                    _WinAPI_SetFocus($hCombo)
                                Case 4
                                    $hCombo = _GUICtrlComboBoxEx_Create($Form1,$aLWVariableChoises[$Item], $aRect[0] + 10, $aRect[1] + 12, $aRect[2] - $aRect[0], 20, $Style_LWComboBox)
                                    _WinAPI_SetFocus($hCombo)
                            EndSwitch
                        EndIf
                    EndIf
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc


Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $iCode = BitShift($wParam, 16)
    Switch $lParam
        Case $hEdit
            Switch $iCode
                Case $EN_KILLFOCUS
                    Local $iText = _GUICtrlEdit_GetText($hEdit)
                    _GUICtrlListView_SetItemText($hListView, $Item, $iText, $SubItem)
                    _WinAPI_DestroyWindow($hEdit)
                    _WinAPI_RedrawWindow($hListView)
                    $aLWActualChoises[$Item] = $iText
                    $Item = -1
                    $SubItem = 0
            EndSwitch
        Case $hCombo
            Switch $iCode
                Case $EN_KILLFOCUS
                    Local $iText = _GUICtrlComboBoxEx_GetEditText($hCombo)
                    _GUICtrlListView_SetItemText($hListView, $Item, $iText, $SubItem)
                    _WinAPI_DestroyWindow($hCombo)
                    _WinAPI_RedrawWindow($hListView)
                    $aLWActualChoises[$Item] = $iText
                    $Item = -1
                    $SubItem = 0
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
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...