Jump to content
Sign in to follow this  
GreenCan

Listview displaying Multiline text cells

Recommended Posts

GreenCan

A while ago, I saw a post from someone querying if it was possible to show multiline content in a listview, there were no replies to the post.

I had the same problem and I wrote following script.

I snooped the example from MrCreator who came with a ToolTip idea, modified the code abit and that's the result.

; example of tooltip for multiline text items
;   by GreenCan

#include <GUIConstants.au3>
#Include <GuiListView.au3>
#include <WindowsConstants.au3>
MsgBox(0,"Demo","Click on any cell, the cells containing multiple lines" & @CRLF & "will show a tooltip with the formatted text" & @CRLF & @CRLF & "Change '$NM_CLICK' to '$LVN_HOTTRACK'" & @CRLF & "for a fly-over effect", 10)

Global $iLastItem = -1, $iLastsubitemNR = -1

$GUI = GUICreate("Listview ToolTip for multiline cells")

$hListView = GuiCtrlCreateListView("Column 1", 10, 10, 380, 380,-1, BitOR($LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT ))

; fill with example data
    ; Add columns
    _GUICtrlListView_AddColumn ($hListView,  "Column 2", 100)
    _GUICtrlListView_AddColumn ($hListView,  "Column 3", 150)
    
    ; Add some rows
    _GUICtrlListView_AddItem($hListView, "A1", 0)
    _GUICtrlListView_AddSubItem($hListView, 0, "A2" & @CRLF & "Example of multiline text", 1)
    _GUICtrlListView_AddSubItem($hListView, 0, "A3" & @CRLF & "Example of multiline text" & @CRLF & "3rd line", 2)

    _GUICtrlListView_AddItem($hListView, "B1", 1)
    _GUICtrlListView_AddSubItem($hListView, 1, "B2" & @CRLF & "Line 2" & @CRLF & "Line 3" & @CRLF & "Line 4", 1)
    _GUICtrlListView_AddSubItem($hListView, 1, "B3", 2)
    
    _GUICtrlListView_AddItem($hListView, "C1")
    _GUICtrlListView_AddSubItem($hListView, 2, "C2" & @CRLF & "Another multiline text", 1)
    _GUICtrlListView_AddSubItem($hListView, 2, "C3" & @CRLF & "Another Example of multiline text", 2)
; done

GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    Switch GuiGetMsg()
    Case $GUI_EVENT_CLOSE
        ToolTip("") ; clean remaining ToolTip from WM_NOTIFY if necessary
        GUIDelete($GUI)
        Exit
    EndSwitch
WEnd
#FUNCTION# ==============================================================
Func WM_NOTIFY($hWnd, $MsgID, $wParam, $lParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
    
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
            Case $NM_CLICK ; when clicking on a cell that is multiline, a tooltip will display the content
            ;Case $LVN_HOTTRACK; Sent by a list-view control when the user moves the mouse over an item
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
                    Local $iItem = DllStructGetData($tInfo, "Item")
                    Local $subitemNR = DllStructGetData($tInfo, "SubItem")
                    
                    ; if no cell change return without doing anything
                    If $iLastItem = $iItem And $iLastsubitemNR = $subitemNR Then Return 0
                    $iLastItem = $iItem
                    $iLastsubitemNR = $subitemNR
                    
                    Local $sToolTipData = _GUICtrlListView_GetItemText($hListView, $iItem,$subitemNR)
                    $Mypos = StringInStr ( $sToolTipData, @CRLF )
                    If $Mypos > 0 Then 
                        ToolTip($sToolTipData, MouseGetPos(0) + 20, MouseGetPos(1) + 20) 
                    Else
                        ToolTip("")
                        ConsoleWrite("R" & $iItem & "C" & $iLastsubitemNR & " No tip" & @CR)
                    EndIf
            EndSwitch
    EndSwitch
        
    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
#FUNCTION# ==============================================================

To be honnest, I don't like it very much, I would prefer that the multiline data to display as integrated part of the standard ListView concept. I would very much like to see a dropdown (like a combo or a calendar selector) as part of the multiline cell.

I don't know if it would be hard to realize.

Did anyone work on this? I can't find any topic about this on the forum. Let me know.

GreenCan


Contributions

CheckUpdate - SelfUpdating script ------- Self updating script

Dynamic input validation ------------------- Use a Input masks can make your life easier and Validation can be as simple

MsgBox with CountDown ------------------- MsgBox with visual countdown

Display Multiline text cells in ListView ---- Example of pop-up or ToolTip for multiline text items in ListView

Presentation Manager ---------------------- Program to display and refresh different Border-less GUI's on a Display (large screen TV)

USB Drive Tools ------------------------------ Tool to help you with your USB drive management

Input Period udf ------------------------------ GUI for a period input

Excel ColorPicker ---------------------------- Color pickup tool will allow you to select a color from the standard Excel color palette

Excel Chart UDF ----------------------------- Collaboration project with water 

GetDateInString ------------------------------ Find date/time in a string using a date format notation like DD Mon YYYY hh:mm

TaskListAllDetailed --------------------------- List All Scheduled Tasks

Computer Info --------------------------------- A collection of information for helpdesk

Shared memory Demo ----------------------- Demo: Two applications communicate with each other through means of a memory share (using Nomad function, 32bit only)

Universal Date Format Conversion -------- Universal date converter from your PC local date format to any format

Disable Windows DetailsPane -------------- Disable Windows Explorer Details Pane

Oracle SQL Report Generator -------------  Oracle Report generator using SQL

SQLite Report Generator -------------------  SQLite Report generator using SQL

SQLite ListView and BLOB demo ---------- Demo: shows how binary (image) objects can be recognized natively in a database BLOB field

DSN-Less Database connection demo --- Demo: ActiveX Data Objects DSN-Less Database access

Animated animals ----------------------------- Fun: Moving animated objects

Perforated image in GUI --------------------- Fun: Perforate your image with image objects

UEZ's Perforator major update ------------- Fun: Pro version of Perforator by UEZ

Visual Crop Tool (GUI) ----------------------- Easy to use Visual Image Crop tool

Visual Image effect (GUI) -------------------- Visually apply effects on an image

 

 

 

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.