Jump to content

Recommended Posts

  • Moderators
Posted

error471,

The UDF can save/load an array to/from a file with ease, but there is no UDF provision for styling or formatting the ListView content.  However, your question makes it sound as if you want separate styling/colours for different subitems within the ListView - doing so requires a considerable amount of code but would also need separate arrays to hold the required colour data, which could themselves be saved/loaded along with the text content. So the answer is "Perhaps"!

Can you give me a more detailed explanation of what you are looking to achieve? The image in this post gives you an idea of what might be possible - does that look as if it could be something worth pursuing? If so, then we might break out into a new thread as the UDF will only be a small part of the overall script.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

@Melba23:

Thanks for the very quick answer, yes the linked image is a good example of what my intention is. I made a mockup of what I am trying to achieve. See attachment. If you could carry on the UDF to be able to save and load the colours it would be pure awesomeness.

mockup.png

  • Moderators
Posted

error471,

As I explained above, I will not be adding such functionality to the UDF itself (it is already complex enough) but I believe it will be possible to use it along with some custom code to let you produce something along the lines of the above. I will start looking into how it might be done tomorrow.

And as mentioned I will split off these posts into a separate thread as they will not be concerned with the UDF proper, so do not be surprised if this thread suddenly appears a little empty!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

  • Moderators
Posted (edited)

error471,

A little proof of concept script - you can edit (doubleclick) and colour (rightclick) columns 1-5:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>
#include <File.au3>

#include"GUIListViewEx.au3"

Global $aColArray, $iLVRtRow, $iLVRtCol

$hGUI = GUICreate("Test", 500, 500)

$cLV = GUICtrlCreateListView("Fixed Title|Column 1|Column 2|Column 3|Column 4|Column 5", 10, 10, 480, 300, $LVS_SINGLESEL)
_GUICtrlListView_SetColumnWidth($cLV, 0, 100)
_GUICtrlListView_SetColumnWidth($cLV, 1, 70)
_GUICtrlListView_SetColumnWidth($cLV, 2, 70)
_GUICtrlListView_SetColumnWidth($cLV, 3, 70)
_GUICtrlListView_SetColumnWidth($cLV, 4, 70)

; Create array and fill listview
Global $aLVArray[5]
For $i = 0 To 4
    $aLVArray[$i] = StringUpper(StringRegExpReplace(_TempFile("", "", "", 7), "(?U)^.*\\(\w*)\.$", "$1"))
    GUICtrlCreateListViewItem($aLVArray[$i], $cLV)
Next

; Initiate ListView - edit on click in columns 1-5
$iLVIndex = _GUIListViewEx_Init($cLV, $aLVArray, 0, 0, True, 2 + 16, "1-5")

$mColMenu = GUICtrlCreateContextMenu($cLV)

$mColYel = GUICtrlCreateMenuItem("Yellow Text", $mColMenu)
$mColOra = GUICtrlCreateMenuItem("Orange Text", $mColMenu)
$mColGry = GUICtrlCreateMenuItem("Grey Text", $mColMenu)
$mColBlk = GUICtrlCreateMenuItem("Black Field", $mColMenu)
$mColRed = GUICtrlCreateMenuItem("Red Field", $mColMenu)
$mColGrn = GUICtrlCreateMenuItem("Green Field", $mColMenu)

GUISetState()

_InitColor($cLV)

_GUIListViewEx_MsgRegister(False)
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1

    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $mColYel To $mColGrn
            _SetColour($iMsg)
    EndSwitch

    $aRet = _GUIListViewEx_EditOnClick()

WEnd

Func _InitColor($cLV)

    ; Read content into an array
    $aColArray = _GUIListViewEx_ReadToArray($cLV)
    ; Clear all elements except col 0
    For $i = 0 To  UBound($aColArray, $UBOUND_ROWS) - 1
        For $j = 1 To  UBound($aColArray, $UBOUND_COLUMNS) - 1
            ; No entry = default colours
            $aColArray[$i][$j] = "|"
        Next
    Next

EndFunc

Func _SetColour($iSel)

    If $iLVRtRow <> -1 And $iLVRtCol > 0 Then
        $sColSet = ""
        Switch $iSel
            Case $mColYel
                $sColSet = "0x80FFFF|" ; Note BGR not RGB
            Case $mColOra
                $sColSet = "0x0080FF|"
            Case $mColGry
                $sColSet = "0xC0C0C0|"
            Case $mColBlk
                $sColSet = "|0x000000"
            Case $mColRed
                $sColSet = "|0x0000FF"
            Case $mColGrn
                $sColSet = "|0x00FF00"
        EndSwitch
    EndIf

    ; Current colour
    $aCurrSplit = StringSplit($aColArray[$iLVRtRow][$iLVRtCol], "|")
    $aNewSplit = StringSplit($sColSet, "|")
    For $i = 1 To 2
        If $aNewSplit[$i] Then
            $aCurrSplit[$i] = $aNewSplit[$i]
        EndIf
    Next
    $aColArray[$iLVRtRow][$iLVRtCol] = $aCurrSplit[1] & "|" & $aCurrSplit[2]

EndFunc

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $iMsg, $wParam, $lParam)

    ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW
    Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam)

    Local $iCode = BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF)
    Switch $iCode

        Case $NM_RCLICK
            ; Get position of right click
            $iLVRtRow = DllStructGetData($tStruct, 4)
            $iLVRtCol = DllStructGetData($tStruct, 5)

        Case $NM_CUSTOMDRAW
            Local $tNMLVCUSTOMDRAW = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
            Local $dwDrawStage = DllStructGetData($tNMLVCUSTOMDRAW, "dwDrawStage")
            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
                    ; Before painting an item
                    Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window of any subitem-related drawing operations
                Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM)
                    ; Before painting a subitem
                    Local $iItem = DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec") ; Item index
                    Local $iSubItem = DllStructGetData($tNMLVCUSTOMDRAW, "iSubItem") ; Subitem index
                    If $iSubItem > 0 Then
                        ; Set default colours
                        $iTextColour = 0x000000
                        $iBackColour = 0xFEFEFE
                        ; Get required colours
                        $aSplitColour = StringSplit($aColArray[$iItem][$iSubItem], "|")
                        If $aSplitColour[1] Then $iTextColour = $aSplitColour[1]
                        If $aSplitColour[2] Then $iBackColour = $aSplitColour[2]
                        ; Set required colours
                        DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", $iTextColour)
                        DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", $iBackColour)
                    EndIf
                    Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors
            EndSwitch

    EndSwitch

EndFunc

Now to get it all working when the ListView content changes!

M23

Edited by Melba23
Typo

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

  • Moderators
Posted (edited)

error471,

And now I have one that does work when adding/deleting rows - you will need to use the amended UDF this time:

<snip>

There is some ghosting when dragging items, but other than that it seems pretty stable. How does it look to you?

As it was so easy to do, I am now off to see if I can integrate all that into the UDF itself without causing a major rewrite - but no promises.

M23

Edited by Melba23
Beta code removed

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

  • Moderators
Posted (edited)

error471,

Way ahead of you.  A rainy afternoon has seen lots of progress:

<snip>

I am working on the colour loading now. I think I might even be able to integrate the "user colour" option completely into the UDF - just be patient for a while and see what happens.

M23

Edited by Melba23
Beta code removed

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

  • Moderators
Posted (edited)

error471,

And here is the  script with colour loading incorporated:

<snip>

You can get the colour array returned (press the "Colour" button) so that you can save it and reload when required.

I think that is all for today - time for dinner and then the grand final of Only Connect. I will get back to the code after my round of golf tomorrow morning.

M23

 

Edited by Melba23
Beta code removed

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted (edited)

@Melba23

Nice.
I notice one issue

When I try to drag coloured item (moving item with mouse usage), then the colors is not moved together with this selected item. 

 

@error471

How did you made this "bending header" ?

As I trying understand "mockup of what I am trying to achieve" means an example made with "MSPaint" ? Or you know a way to made it in AutoIt ?

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Moderators
Posted

mLipok,

As I mentioned above

  On 1/18/2016 at 10:54 AM, Melba23 said:

There is some ghosting when dragging items

Expand  

However, it seems to correct itself once the dragging stops. A similar problem exists when dragging multiple items.  I have always attributed the effect to the limitations of coding something that complex in AutoIt - which sounds better than saying that I have no idea why it happens!

M23

As

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted
  On 1/18/2016 at 9:07 PM, Melba23 said:

As I mentioned above

There is some ghosting when dragging items

Expand  

So I did not understand you well.
Sorry for my lack of language knowledge.

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Moderators
Posted

mLipok.

No problem - and your English is fine, much better then my Polish!

Dobranoc,

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

Thank you for the compliment.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Moderators
Posted (edited)

error471,

I have managed (I think!) to integrate the user colour management into the main UDF - and without causing it to crash too often. Here are the test files I have been using:

<snip>

Please test the script as much as possible to see if you can crash it - please note what operations you carried out if it does fail. The only problem I have discovered so far is a reluctance of the ListViews to recolour immediately - I am still working on that.

Anyone else reading, please also try the script and post comments - the more testers the merrier.

M23

 

Edited by Melba23
Removed Beta code

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

@Melba23

 

Thanks for your efforts dude. I can't start Colour ListView Min.au3 because of this error:

 

"C:\Program Files (x86)\AutoIt3\Include\GUIListViewEx_Colour_Max.au3" (2036) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
If StringInStr(($aGLVEx_Data[0][13])[$iItem + 1][$iSubItem], ";") Then
If StringInStr(($aGLVEx_Data[0][13]^ ERROR
->20:43:03 AutoIt3.exe ended.rc:1

 

  • Moderators
Posted

error471,

I have re-uploaded the files - please try again as they work for me.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

Works fine in general, no crashes. But I found a weird behaviour: Whenever I select+drag a line from the left ListView and drop it to the right one all coloured row's of the original ListView are move too. Dragging and dropping within the same ListView works fine. What I also discovered is, that after clicking around for a while, some fields get a colour without my intervention.

  • Moderators
Posted

error471,

In fact the colours are being transferred correctly - the problem appears to be getting the ListViews to redraw correctly after the operation so that the new colours show. That is today's task!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

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...