Jump to content

Help on GUICtrllistview


Syed23
 Share

Recommended Posts

hi All,

i am trying to create GUICtrlcreatelistview on that i need only 3 columns. but i am getting extra column with blank title and i want to remove it ay help? also the guictrllist item column size should get adjusted automatically. is it possible to do?

Any help is appreciated

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ListviewConstants.au3>
Opt('MustDeclareVars', 1)
Global $ListView, $GUI, $msg ,$Label1, $ComboList , $Show
$GUI = GUICreate("Bug Tracker",650,750,@DesktopHeight/4,@DesktopHeight/4) ; trying the make the GUI to appear on the center of the monitor
GUISetBkColor(0x00E0FFFF)
$Label1 = GUICtrlCreateLabel("Selet the Application",10,7,100,30)
$ComboList = GUICtrlCreateCombo("Internet Explorer",120,5,150,30)
GUICtrlSetData(-1,"Adobe Reader|Adobe Flash|Java|Office 2010|SAP GUI 7.20")
$Show = GUICtrlCreateButton("Show",320,5,50,30)
$ListView = GUICtrlCreateListView("S.NO|Reported Issue|Resolution", 10, 60, 630, 670)
GUICtrlDelete("")
GUISetState()
Do
 $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to comment
Share on other sites

  • Moderators

Syed23,

1. To centre your GUI, just use -1 for the position parameters. :)

2. To adjust the column width, use _GUICtrlListView_SetColumnWidth. This is one occasion when using a UDF function on a native control does work well. And note the special values you can use:

$LVSCW_AUTOSIZE - Automatically sizes the column.

$LVSCW_AUTOSIZE_USEHEADER - Automatically sizes the column to fit the header text.

If you use this value with the last column, its width is set to fill the remaining width of the list-view control

All clear? :mellow:

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Syed23,

What last empty column? :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>

Opt('MustDeclareVars', 1)

Global $ListView, $GUI, $msg, $Label1, $ComboList, $Show

$GUI = GUICreate("Bug Tracker", 650, 750, @DesktopHeight / 4, @DesktopHeight / 4) ; trying the make the GUI to appear on the center of the monitor
GUISetBkColor(0x00E0FFFF)
$Label1 = GUICtrlCreateLabel("Selet the Application", 10, 7, 100, 30)
$ComboList = GUICtrlCreateCombo("Internet Explorer", 120, 5, 150, 30)
GUICtrlSetData(-1, "Adobe Reader|Adobe Flash|Java|Office 2010|SAP GUI 7.20")
$Show = GUICtrlCreateButton("Show", 320, 5, 50, 30)
$ListView = GUICtrlCreateListView("S.NO|Reported Issue|Resolution", 10, 60, 630, 670)

 _GUICtrlListView_SetColumnWidth($ListView, 0, 100)
 _GUICtrlListView_SetColumnWidth($ListView, 1, 100)
 _GUICtrlListView_SetColumnWidth($ListView, 2, $LVSCW_AUTOSIZE_USEHEADER)

GUISetState()

Do
    $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE

I only see the 3 columns you require. :mellow:

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Syed23,

Like this: :graduated:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

; Set flag to indicate double click in ListView
Global $fDblClk = False

$Gui = GUICreate("Test", 400, 250)

; This works with either type of ListView

#cs
$hListView = GUICtrlCreateListView("Items", 2, 2, 220, 196)
_GUICtrlListView_SetColumnWidth($hListView, 0, $LVSCW_AUTOSIZE_USEHEADER)
GUICtrlCreateListViewItem("Item 1", $hListView)
GUICtrlCreateListViewItem("Item 2", $hListView)
GUICtrlCreateListViewItem("Hyperlink", $hListView)
GUICtrlCreateListViewItem("Item 4", $hListView)
#ce
;#cs
$hListView = _GUICtrlListView_Create($Gui, "Items", 2, 2, 220, 196, $LVS_REPORT)
_GUICtrlListView_SetColumnWidth($hListView, 0, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_AddItem($hListView, "Item 1",0)
_GUICtrlListView_AddItem($hListView, "Item 2",2)
_GUICtrlListView_AddItem($hListView, "Hyperlink",1)
_GUICtrlListView_AddItem($hListView, "Item 4",3)
;#ce

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch

    ; If an item was double clicked
    If $fDblClk Then
        $fDblClk = False
        If Not IsHWnd($hListView) Then $hListView = GUICtrlGetHandle($hListView)
        If _GUICtrlListView_GetSelectedIndices($hListView) = 2 Then
            ; Open the url
            ShellExecute("www.autoitscript.com")
        EndIf
    EndIf

WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)

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

    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_DBLCLK
                    $fDblClk = True
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

All clear? ;)

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I would have triggered the ShellExecute straight from the message handler, or used a dummy to trigger the message in the loop.... But then I don't like global flags :graduated:

But I didn't post just to provide "constructive criticism":

It is possible to custom draw a listview in order to draw the text as a hyperlink. For examples you should search the forum. It is also possible to keep track of which ones have been clicked and change the text colour. In fact, you could also change the cursor to be a clicky hand.

It all depends on what you mean by "hyperlink". Do you want something you can click and open a web page like Melba has already provided, or do you want the graphical effects of a hyperlink as well?

Custom drawing listviews

Link to comment
Share on other sites

This is cool :graduated:.

It is possible to custom draw a listview in order to draw the text as a hyperlink. For examples you should search the forum. It is also possible to keep track of which ones have been clicked and change the text colour. In fact, you could also change the cursor to be a clicky hand.

Matt,

is this possible to do?

Edited by Syed23

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to comment
Share on other sites

Matt,

is this possible to do?

Of course :graduated: Unfortunately for you I'm very busy with uni open days and school work at the moment (and another project which has a deadline coming up) so I don't really have time to do it myself (although it sounds like it will be useful, so I would usually).

Look at the link I posted above for custom drawing the text, and then try selecting a different GDI pen into the DC with the colour before drawing. SetCursor() is used to set the clicky hand, but you'll have to monitor WM_MOUSEMOVE messages, then find the subitem from the mouse position and then set it.

Link to comment
Share on other sites

  • Moderators

Syed23,

Yes, by replacing $NM_DBLCLK with $NM_CLICK.

But I would not recommend it. The ListView uses single clicks to select the item - if you also use it to action things, I have found that the script can get confused and the correct item is not returned when the selection is checked.

So use at your own risk. :graduated:

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Any suggestion why the below script is not working?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>
#include "_XMLDomWrapper.au3"
#include <_ListView_SysLink.au3>
#include"Array.au3"
Opt('MustDeclareVars', 1)
Global $fDblClk = False
Global $ListView, $GUI, $msg, $Label1, $ComboList, $Show,$Fopen,$Destination,$numberOfChannels,$i,$Issue,$Sol,$Exit,$HyperLink,$splitstring,$hSysLink1,$j = 0,$aInfo,$sInfo,$check,$show1
Global $hWnd, $iMsg, $iwParam, $ilParam, $ListView, $fDblClk, $array
$Destination = @TempDir
FileInstall(@ScriptDir&"\IE.xml",$Destination&"\IE.xml",1)
$GUI = GUICreate("Bug Tracker", 780, 780, -1, -1) ; trying the make the GUI to appear on the center of the monitor
GUISetBkColor(0x00E0FFFF)
$Label1 = GUICtrlCreateLabel("Selet the Application", 10, 7, 100, 30)
$ComboList = GUICtrlCreateCombo("Internet Explorer", 120, 5, 150, 30)
;GUICtrlSetData(-1, "Adobe Reader|Adobe Flash|Java|Office 2010|SAP GUI 7.20")
$Show = GUICtrlCreateButton("Show", 320, 5, 50, 30)
$Exit = GUICtrlCreateButton("Exit", 420, 5, 50, 30)
$show1 = GUICtrlCreateButton("Link",520,5,50,30)
$ListView = GUICtrlCreateListView("S.NO|Reported Issue|Fixed on|Link to CSS page", 10, 60, 750, 670)
 
_GUICtrlListView_SetColumnWidth($ListView, 0, 50)
_GUICtrlListView_SetColumnWidth($ListView, 1, 400)
_GUICtrlListView_SetColumnWidth($ListView, 2, 80)
_GUICtrlListView_SetColumnWidth($ListView, 3, 300)
GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
Do
    $msg = GUIGetMsg()
If $msg = $Show Then
  Select
   Case GUICtrlRead($ComboList) = "Internet Explorer"
    Call("explore")
  EndSelect
EndIf
If $fDblClk Then
        $fDblClk = False
        If Not IsHWnd($ListView) Then $ListView = GUICtrlGetHandle($ListView)
        If _GUICtrlListView_GetSelectedIndices($ListView) = 2 Then
            ; Open the url
            ShellExecute("[url="http://www.autoitscript.com"]www.autoitscript.com[/url]")
        EndIf
    EndIf
If $msg = $Exit Then
  Exit
EndIf
If $msg = $show1 Then
  $array = _GUICtrlListView_GetSelectedIndices($ListView)
  _ArrayDisplay($array)
EndIf
 
Until $msg = $GUI_EVENT_CLOSE
Edited by Syed23

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to comment
Share on other sites

  • Moderators

Syed23,

I do not have some of the include files so I cannot run it as it is. What error(s) do you get? :graduated:

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Melba23,

in above post #7 you have given me an example to create Hyperlink.. is it possible to help me to change it's color as hyperlink color and underlined text? so that i can complete this tool

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to comment
Share on other sites

  • Moderators

Syed23,

is it possible to help me to change it's color as hyperlink color and underlined text

No. As Mat has explained above, it requires a user-drawn ListView. There are examples on the forum if you search, but it not one of my areas of expertise (if indeed I have any at all!). ;)

And again...what errors do you get which stop you running the code you posted earlier? :graduated:

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

There were no errors... what i understand is if i click on the Hyperlink that did not understand that i have clicked it.... so nothing happens

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to comment
Share on other sites

If _GUICtrlListView_GetSelectedIndices($hListView) = 2 Then

what the above value "2" represents. My hyperlink will be in 4th column... do i need to do any modification on here?

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to comment
Share on other sites

  • Moderators

Syed23,

You need to modify a bit more than that. ;)

Here is a short example script to show you how to detect both the row and column of a ListView:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>

$hGui = GUICreate("Test", 250, 250)

$hListView = GUICtrlCreateListView("Column 1|Column 2|Column 3", 5, 10, 240, 160)
For $i = 1 To 6
    GUICtrlCreateListViewItem("Item " & $i & "1|Item " & $i & "2|Item " & $i & "3", $hListView)
Next

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

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


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

    #forceref $hWnd, $iMsg, $wParam

    Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam) ; Increase the struct size to get the column 
    If @error Then Return
    Switch DllStructGetData($tStruct, 3)
        Case $NM_DBLCLK 
            ConsoleWrite("Row: " & DllStructGetData($tStruct, 4) + 1 & " - Col: " &DllStructGetData($tStruct, 5) + 1 & @CRLF)
    EndSwitch

EndFunc   ;==>On_WM_NOTIFY

You will need to check both row and column values to see if the correct item has been double-clicked. :graduated:

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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