Sign in to follow this  
Followers 0
Lemures

Change ListView font?

18 posts in this topic

I have a program where I need to show a list of players on a server. The user will have selected several players, and I need their names to stand out somehow. I was hoping To have a list view where people could double click names to toggle bold on that particular name, but it appears I cannot change the text of individual entries. Any ideas as to a workaround or something that would appear similiar to the end user?

Share this post


Link to post
Share on other sites



GUICtrlSetColor () on the listviewitem should work.

Share this post


Link to post
Share on other sites

GUICtrlSetColor () on the listviewitem should work.

I'm trying to edit the color or font of individual entries, not the entire thing.

Share this post


Link to post
Share on other sites

#include <GuiConstants.au3>
GuiCreate("MyGUI", 392, 323,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
opt("GUIONEVENTMODE",1)
$List_1 = GuiCtrlCreateListView("List1", 40, 90, 230, 84)
$1=GUICtrlCreateListViewItem ( "text", $List_1 )
$2=GUICtrlCreateListViewItem ( "text2", $List_1 )
$3=GUICtrlCreateListViewItem ( "text3", $List_1 )
GUICtrlSetColor($2,"0xAAFFAA")
GUISetState(@SW_SHOW)
while 1
WEnd

changes the font of item #2... where's the problem?

Share this post


Link to post
Share on other sites

#include <GuiConstants.au3>
GuiCreate("MyGUI", 392, 323,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
opt("GUIONEVENTMODE",1)
$List_1 = GuiCtrlCreateListView("List1", 40, 90, 230, 84)
$1=GUICtrlCreateListViewItem ( "text", $List_1 )
$2=GUICtrlCreateListViewItem ( "text2", $List_1 )
$3=GUICtrlCreateListViewItem ( "text3", $List_1 )
GUICtrlSetColor($2,"0xAAFFAA")
GUISetState(@SW_SHOW)
while 1
WEnd

changes the font of item #2... where's the problem?

Oh. Whoa. That does work. I didnt realize I could set the color of the individual thing. Thank you!!

Share this post


Link to post
Share on other sites

Hmm..

How do I modify the color of a particular item when all I have is the items text? Right now I am grabbing a list of players on a server, so it's not like I've defined each individual thing.. individually.

Share this post


Link to post
Share on other sites

Study this for a while... it should keep you busy. :)

#include <GUIConstants.au3>
#include <GUIListView.au3>

Global Const $WM_NOTIFY = 0x004E
Global Const $NM_DBLCLK = -3

GUICreate('ListView Test', 220, 120)

$lv = GUICtrlCreateListView('Column', 10, 10, 60, 100)
Dim $lvarray[5]
$lvarray[0] = GUICtrlCreateListViewItem('Apple', $lv)
$lvarray[1] = GUICtrlCreateListViewItem('Orange', $lv)
$lvarray[2] = GUICtrlCreateListViewItem('Banana', $lv)
$lvarray[3] = GUICtrlCreateListViewItem('Pear', $lv)
$lvarray[4] = GUICtrlCreateListViewItem('Mango', $lv)

$input = GUICtrlCreateInput('', 80, 10, 60, 20)
$btn = GUICtrlCreateButton('Colorize', 150, 10, 60, 20)
GUICtrlCreateLabel('Enter the name of an item from the listview and press Colorize.  Or, double click an item.', 80, 40, 130, 70)

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $btn
            colorit(1)
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func colorit($opt)
    If $opt = 1 Then
        $lvtxt = GUICtrlRead($input)
    Else
        $lvtxt = _GUICtrlListViewGetItemText($lv, _GUICtrlListViewGetSelectedIndices($lv))
    EndIf
    Local $found = False
    For $i = 0 To 4
        If GUICtrlRead($lvarray[$i]) = $lvtxt Then
            For $x = 0 To 4
                GUICtrlSetColor($lvarray[$x], 0x000000)
            Next
            $found = True
            ExitLoop
        EndIf
    Next
    If $found = True Then GUICtrlSetColor($lvarray[$i], 0xFF0000)
EndFunc

Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
    Local $tagNMHDR = DllStructCreate("int;int;int", $lParam), $event
    If @error Then Return
    $event = DllStructGetData($tagNMHDR, 3)
    If $wParam = $lv And $event = $NM_DBLCLK Then colorit(2)
    $tagNMHDR = 0
EndFunc

Share this post


Link to post
Share on other sites

I love you. Awesome.

Tomorrow I'll figure out how to change the font (hopefully) and then easily sort by the 'colorized' ones. Thanks!

Share this post


Link to post
Share on other sites

Hmm.. any easy way to do this with just a list?

This function

Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
    Local $tagNMHDR = DllStructCreate("int;int;int", $lParam), $event
    If @error Then Return
    $event = DllStructGetData($tagNMHDR, 3)
    If $wParam = $lv And $event = $NM_DBLCLK Then colorit(2)
    $tagNMHDR = 0
EndFunc

Isnt working for me for just a list view. I'll admit though, I have no understanding of how that function works.

Share this post


Link to post
Share on other sites

#10 ·  Posted

In your script, you'll need...

Global Const $WM_NOTIFY = 0x004E

Global Const $NM_DBLCLK = -3

...at the top of the script, and...

GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")

...after GuiSetState().

That is the part of the script that detects the double click on the listview. Your functions for double clicks goes here...

If $wParam = $lv And $event = $NM_DBLCLK Then YOURFUNCTIONS()

If you do not plan on using double clicks in your listview, you can just leave out that function and the above mentioned.

Share this post


Link to post
Share on other sites

#11 ·  Posted

Err, I mistyped. I meant for just a list. I dont need it to be a listview. I've modified everything that needs to be, but its not giving me a unique $event with that coding when I double click anything (ive got a traytip telling me the current $event, and nothing changes when I double click in a list, but it does when i double click in a listview)

Share this post


Link to post
Share on other sites

#12 ·  Posted

For example, making these changes:

$lv = GUICtrlCreateList('Column', 10, 10, 60, 100)
Dim $lvarray[5]
$lvarray[0] = _GUICtrlListAddItem($lv, 'Apple')
$lvarray[1] = _GUICtrlListAddItem($lv, 'Orange')
$lvarray[2] = _GUICtrlListAddItem($lv, 'Banana')
$lvarray[3] = _GUICtrlListAddItem($lv, 'Pear')
$lvarray[4] = _GUICtrlListAddItem($lv, 'Mango')

-----------------------

Func colorit($opt)
   MsgBox(0,"","ColorIt")
EndFunc

I can only get that message box if i click Colorize. Double clicking does not do it.

Share this post


Link to post
Share on other sites

#13 ·  Posted

Well, you can just check $msg in the loop returning $lv, and then MsgBox, for example...

Case $lv

MsgBox(0, '', GUICtrlRead($lv))

But, if you're wanting to change a single line a different color, that I don't know how to do in a regular List control.

Share this post


Link to post
Share on other sites

#14 ·  Posted

Ahh, yes, after a bit more experimentation, youre right, I cant even change the color of things in a list, but I can in a list view.

Then my final question is how do I get a listview to look just like a list? without the columns, or atleast have them locked at larger than the width, or something.

bah. I really should have gone to sleep last night ><

Share this post


Link to post
Share on other sites

#15 ·  Posted

Check out the listview styles and extended styles listed in the help file. I seem to recall ones that will do what you want.

Share this post


Link to post
Share on other sites

#16 ·  Posted

Check out the listview styles and extended styles listed in the help file. I seem to recall ones that will do what you want.

Roger that. Thank you for all of your help!

Share this post


Link to post
Share on other sites

#17 ·  Posted

Alright, one last question hopefully!

I now have the programming properly 'highlighting' several entries in a 60 entry list. Is there any way to then have it sort by the highlighted ones, so that the ones that are 'highlighted' are up top?

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

I've actually been working on trying to solve this myself. I don't think there is a sort by color option (hope I'm wrong). The closest I get is this...

#include <GUIConstants.au3>
#include <GUIListView.au3>

Opt('GUIOnEventMode', 1)

Global Const $WM_NOTIFY = 0x004E
Global Const $NM_DBLCLK = -3

$gui = GUICreate('ListView Test', 80, 120)
GUISetOnEvent($GUI_EVENT_CLOSE, 'quit')

$lv = GUICtrlCreateListView('Column', 10, 10, 60, 100)
GUICtrlCreateListViewItem('Apple', $lv)
GUICtrlCreateListViewItem('Orange', $lv)
GUICtrlCreateListViewItem('Banana', $lv)
GUICtrlCreateListViewItem('Pear', $lv)
GUICtrlCreateListViewItem('Mango', $lv)

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")

While 1
    Sleep(100)
WEnd

Func colorit()
    Local $lvind = _GUICtrlListViewGetCurSel($lv)
    Local $lvtxt = _GUICtrlListViewGetItemText($lv, $lvind)
    If $lvtxt <> '' Then
        _GUICtrlListViewDeleteItem($lv, $lvind)
        _GUICtrlListViewInsertItem($lv, 0, $lvtxt)
        _GUICtrlListViewSetItemSelState($lv, 0, 1)  ; <<< And here's the problem!
        GUICtrlSetColor(GUICtrlRead($lv), 0xFF0000)  ; <<< And here's the problem!
    EndIf
EndFunc   ;==>colorit

Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
    Local $tagNMHDR = DllStructCreate("int;int;int", $lParam), $event
    If @error Then Return
    $event = DllStructGetData($tagNMHDR, 3)
    If $wParam = $lv And $event = $NM_DBLCLK Then colorit()
    $tagNMHDR = 0
EndFunc

Func quit()
    Exit
EndFunc

Double clicking an item moves(*) it to the top of the list, but I can't get it to color. Obviously it's easy enough to color it when not a freshly inserted item.

* Ok, it's not really moving it. I'm deleting the item and re-inserting it at index 0. The problem I'm having is I can't figure out how to get the 'new' item's identifier (ctrl id) so I can color it. Normally you could just use _GUICtrlListViewSetItemSelState() to focus the item, and then use GUICtrlSetColor() with GUICtrlRead() (as shown above), but the newly inserted items don't seem to show their IDs with GuiCtrlRead().

Edited by xcal

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