Jump to content

[SOLVED] Default choice in list


Recommended Posts

Hello, im searching how make a default choice on TABLIST.

Dim $msg, $ret, $listbox, $button, $i

GUICreate("ListBox Selected Items Indices Demo", 400, 250, -1, -1)
$listbox = GUICtrlCreateList("", 125, 40, 180, 120, BitOR($LBS_SORT, $WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY, $LBS_MULTIPLESEL))
GUICtrlSetData($listbox, "test1|more testing|even more testing|demo|")
$button = GUICtrlCreateButton("Get Selected", 150, 160, 120, 40)
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $button
            $ret = _GUICtrlListGetSelItems ($listbox)
            If (Not IsArray($ret)) Then
                MsgBox(16, "Error", "Unknown error from _GUICtrlListGetSelItems")
            Else
                For $i = 1 To $ret[0]
                    MsgBox(0, "Selected", $ret[$i])
                Next
            EndIf
    EndSelect
WEnd

I have this code, i have found on forum.

 

Please help me

Edited by AutoDEV
Link to comment
Share on other sites

5 hours ago, AutoDEV said:

I have this code, i have found on forum. Please help me

As always, the code snippet you posted is not runnable :mad:.

Here is a revised version. What this has to do with TABLIST, however, is not clear to me.

#include <GUIConstantsEx.au3>
#include <ListBoxConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListBox.au3>

Global $msg, $ret, $listbox, $button, $i

GUICreate("ListBox Selected Items Indices Demo", 400, 250, -1, -1)
$listbox = GUICtrlCreateList("", 125, 40, 180, 120, BitOR($LBS_SORT, $WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY, $LBS_MULTIPLESEL))
GUICtrlSetData($listbox, "test1|more testing|even more testing|demo|")
$button = GUICtrlCreateButton("Get Selected", 150, 160, 120, 40)
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $button
;~             $ret = _GUICtrlListGetSelItems ($listbox)
            $ret = _GUICtrlListBox_GetSelItems ($listbox)

            If (Not IsArray($ret)) Then
                MsgBox(16, "Error", "Unknown error from _GUICtrlListGetSelItems")
            Else
                For $i = 1 To $ret[0]
                    MsgBox(0, "Selected", $ret[$i])
                Next
            EndIf
    EndSelect
WEnd

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

Posted (edited)

Hello.

I have one liste view.

If i take this code :

#include <GUIConstantsEx.au3>
#include <ListBoxConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListBox.au3>

Global $msg, $ret, $listbox, $button, $i

GUICreate("ListBox Selected Items Indices Demo", 400, 250, -1, -1)
$listbox = GUICtrlCreateList("", 125, 40, 180, 120, BitOR($LBS_SORT, $WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY, $LBS_MULTIPLESEL))
GUICtrlSetData($listbox, "test1|more testing|even more testing|demo|")
$button = GUICtrlCreateButton("Get Selected", 150, 160, 120, 40)
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $button
;~             $ret = _GUICtrlListGetSelItems ($listbox)
            $ret = _GUICtrlListBox_GetSelItems ($listbox)

            If (Not IsArray($ret)) Then
                MsgBox(16, "Error", "Unknown error from _GUICtrlListGetSelItems")
            Else
                For $i = 1 To $ret[0]
                    MsgBox(0, "Selected", $ret[$i])
                Next
            EndIf
    EndSelect
WEnd

i show a list item but for exmeple : How to select more testing by defaul without i must click on.

Is hard to understand i know and im sorry

Edited by AutoDEV
Link to comment
Share on other sites

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

Global $msg, $ret, $listbox, $button, $i

GUICreate("ListBox Selected Items Indices Demo", 400, 250, -1, -1)
$listbox = GUICtrlCreateList("", 125, 40, 180, 120, BitOR($LBS_SORT, $WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY))
GUICtrlSetData($listbox, "test1|more testing|even more testing|demo", 'more testing')
$button = GUICtrlCreateButton("Get Selected", 150, 160, 120, 40)
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $button
;~             $ret = _GUICtrlListGetSelItems ($listbox)
            $ret = _GUICtrlListBox_GetSelItems ($listbox)

            If (Not IsArray($ret)) Then
                MsgBox(16, "Error", "Unknown error from _GUICtrlListGetSelItems")
            Else
                For $i = 1 To $ret[0]
                    MsgBox(0, "Selected", $ret[$i])
                Next
            EndIf
    EndSelect
WEnd

Just read the documentation.

When the words fail... music speaks.

Link to comment
Share on other sites

Posted (edited)

Big thx.

Is 100% ok.

Problem solved

Just idk why but your work working if i edit by this else sorting data not working.

If u can say why im happy

$listMenu = GUICtrlCreateList("", 302, 67, 225, 126, BitXOR($GUI_SS_DEFAULT_LIST, $LBS_SORT, $WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY))
GUICtrlSetData(-1, "--------------|Open Note|--------------", "Open Note")

 

Edited by AutoDEV
Link to comment
Share on other sites

  • AutoDEV changed the title to [SOLVED] Default choice in list

If you don't use $LBS_MULTIPLESEL as style for your list it works to set default selection as 3rd parameter of GUICtrlSetData(), otherwise use _GUICtrlListBox_SetSel() to select the default value in the list.

When the words fail... music speaks.

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