Jump to content

Recommended Posts

Posted

Hello,

I have a gui consisting of two listviews.
I have attached both programmes as attachments

In the first programme "listview changing colours", I can change the colours of individual fields.
In the second programme ‘listview changing and doublclick’, I can move a line between the listviews and see via double-click which line I have clicked.

The idea is to make 1 programme out of it, where I can therefore both colour individual items, make the contents visible via double-click and transfer the line to another listview via ‘drag and drop’.
Because my main programme uses about 40 individual listviews, some speed is important.

After several days of searching and trying, I still get stuck every time.
Anyone have any idea how I can solve this?

Many thanks in advance for your reactions,

Albert

Listview changing colors.au3 Listview changing and doubleclick.au3

Posted (edited)

Here a working example of one listview with color and double click.  You can add as many listviews as you want.  I included a map to register all the colors of the different listviews.

#include <GUIConstants.au3>
#include <GuiListView.au3>

Opt("MustDeclareVars", True)

Global $idListView, $mColor[]

Example()

Func Example()
  Local $hGUI = GUICreate("Colored ListView", 350, 250)
  $idListView = GUICtrlCreateListView("Number|Number|Number", 5, 5, 300, 150)
  Local $hListView = GUICtrlGetHandle($idListView)
  Local $idButton = GUICtrlCreateButton("Change", 5, 180, 100, 20)

  GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY)
  GUISetState()

  For $i = 1 To 50
    GUICtrlCreateListViewItem($i & '|' & $i & '|' & $i, $idListView)
  Next
  ;init background colors for ListView 1 (could be many of these)
  Local $aColor[ControlListView($hGUI, "", $idListView, "GetItemCount")][ControlListView($hGUI, "", $idListView, "GetSubItemCount")]
  $aColor[0][1] = 0xFFAAFF
  $aColor[1][2] = 0x00AA00
  $aColor[2][0] = 0xCCCCCC
  $mColor[$idListView] = $aColor

  While True
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        Exit
      Case $idButton
        $aColor = $mColor[$idListView]
        $aColor[5][1] = 0xFF
        $mColor[$idListView] = $aColor
        _WinAPI_RedrawWindow($hListView)
    EndSwitch
  WEnd

EndFunc   ;==>Example

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
  Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)

  Switch $tNMHDR.IDFrom
    Case $idListView
      Switch $tNMHDR.Code
        Case $NM_CUSTOMDRAW
          Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
          Local $iDrawStage = $tCustDraw.dwDrawStage
          If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW
          If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW

          ; Paint item and subitem
          Local $iSubItem = $tCustDraw.iSubItem
          Local $iItem = $tCustDraw.dwItemSpec
          If ControlListView($hWnd, "", $tNMHDR.hWndFrom, "IsSelected", $iItem) Then Return $CDRF_DODEFAULT

          $tCustDraw.clrTextBk = ($mColor[$tCustDraw.IDFrom])[$iItem][$iSubItem] ? ($mColor[$tCustDraw.IDFrom])[$iItem][$iSubItem] : 0xFFFFFF
          Return $CDRF_NEWFONT

        Case $NM_DBLCLK
          Local $tItem = DllStructCreate($tagNMITEMACTIVATE, $lParam)
          ConsoleWrite("Double click for ListView : " & $tItem.IDFrom & " on item : " & $tItem.Index & " on subitem : " & $tItem.SubItem & @CRLF)
      EndSwitch
  EndSwitch
  Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

Edited by Nine
added change color
Posted

Thank you very much for the quick response.
I managed to create 2 listview side by side with different colours in the cells.
Also, the double-click works quite well

I still fail to move a row from listview[1] to listview[2].

 I tried: $idListView[1] = GUICtrlCreateListView("Number|Number|Number", 5, 5, 300, 150) to expand with:

  $idListView[1] = GUICtrlCreateListView("Number|Number|Number", 5, 5, 300, 150,BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT, $WS_BORDER))
  _GUICtrlListView_SetExtendedListViewStyle($idListView[1], $LVS_EX_FULLROWSELECT)

(As in the previous program), but that gives no result.
Should I add something in the WM_Notify ?

Posted
#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <GUIListViewEx.au3>
#include <GuiStatusBar.au3>



Opt("MustDeclareVars", True)

Global $idListView[28]
global $hListView[28]
global $mColor[28]
global $g_hStatus


Example()

Func Example()
  Local $hGUI = GUICreate("Colored ListView", 750, 250)
  $idListView[1] = GUICtrlCreateListView("Number|Number|Number", 5, 5, 300, 150,BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT, $WS_BORDER))
  _GUICtrlListView_SetExtendedListViewStyle($idListView[1], $LVS_EX_FULLROWSELECT)
   $hListView[1] = GUICtrlGetHandle($idListView[1])
  $idListView[2] = GUICtrlCreateListView("Number|Number|Number", 305, 5, 300, 150,BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT, $WS_BORDER))
  _GUICtrlListView_SetExtendedListViewStyle($idListView[2], $LVS_EX_FULLROWSELECT)
   $hListView[2] = GUICtrlGetHandle($idListView[2])

  GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY)

  GUISetState()

  For $i = 1 To 50
    GUICtrlCreateListViewItem($i & '|' & $i & '|' & $i, $idListView[1])
    GUICtrlCreateListViewItem($i & '|' & "OK" & '|' & $i, $idListView[2])
  Next

  ;init background colors for ListView 1 (could be many of these)
  Local $aColor[ControlListView($hGUI, "", $idListView[1], "GetItemCount")][ControlListView($hGUI, "", $idListView[1], "GetSubItemCount")]
  $aColor[0][1] = 0xFFAAFF
  $aColor[1][2] = 0x00AA00
  $aColor[2][0] = 0xCCCCCC
  $mColor[$idListView[1]] = $aColor

  ;init background colors for ListView 2 (could be many of these)
  Local $bColor[ControlListView($hGUI, "", $idListView[2], "GetItemCount")][ControlListView($hGUI, "", $idListView[2], "GetSubItemCount")]
  $bColor[0][1] = 0xCCCCCC
  $bColor[1][2] = 0x00AA00
  $bColor[2][0] = 0xFFAAFF
  $mColor[$idListView[2]] = $bColor

  While True
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        Exit
    EndSwitch
  WEnd

EndFunc   ;==>Example

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
  Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)

  Switch $tNMHDR.IDFrom
    Case $idListView[1]
      Switch $tNMHDR.Code
        Case $NM_CUSTOMDRAW
          Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
          Local $iDrawStage = $tCustDraw.dwDrawStage
          If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW
          If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW

          ; Paint item and subitem
          Local $iSubItem = $tCustDraw.iSubItem
          Local $iItem = $tCustDraw.dwItemSpec
          If ControlListView($hWnd, "", $tNMHDR.hWndFrom, "IsSelected", $iItem) Then Return $CDRF_DODEFAULT

          $tCustDraw.clrTextBk = ($mColor[$tCustDraw.IDFrom])[$iItem][$iSubItem] ? ($mColor[$tCustDraw.IDFrom])[$iItem][$iSubItem] : 0xFFFFFF
          Return $CDRF_NEWFONT

        Case $NM_DBLCLK
          Local $tItem = DllStructCreate($tagNMITEMACTIVATE, $lParam)
          ConsoleWrite("Double click for ListView : " & $tItem.IDFrom & " on item : " & $tItem.Index & " on subitem : " & $tItem.SubItem & @CRLF)
      EndSwitch

    Case $idListView[2]
      Switch $tNMHDR.Code
        Case $NM_CUSTOMDRAW
          Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
          Local $iDrawStage = $tCustDraw.dwDrawStage
          If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW
          If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW

          ; Paint item and subitem
          Local $iSubItem = $tCustDraw.iSubItem
          Local $iItem = $tCustDraw.dwItemSpec
          If ControlListView($hWnd, "", $tNMHDR.hWndFrom, "IsSelected", $iItem) Then Return $CDRF_DODEFAULT

          $tCustDraw.clrTextBk = ($mColor[$tCustDraw.IDFrom])[$iItem][$iSubItem] ? ($mColor[$tCustDraw.IDFrom])[$iItem][$iSubItem] : 0xFFFFFF
          Return $CDRF_NEWFONT

        Case $NM_DBLCLK
          Local $tItem = DllStructCreate($tagNMITEMACTIVATE, $lParam)
          ConsoleWrite("Double click for ListView : " & $tItem.IDFrom & " on item : " & $tItem.Index & " on subitem : " & $tItem.SubItem & @CRLF)

      EndSwitch

  EndSwitch
  Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...