Jump to content

List of checkboxes?


Overkill
 Share

Recommended Posts

BEAUTIFUL!

Now I have to go work back through my code, remember what it all does, and make it work :)

Also, next problem is resizing/repositioning:

http://www.autoitscript.com/forum/index.ph...=89332&st=0

I lied...once I got back to the file and reworked the code, etc. It started telling me that everything is checkmarked.

I've edited the code a bit so that it'll work on any PC, and the main code is still the same. If I need to go through and comment it, I can.

Thanks again for being awesome :)

FileList2.au3

Edited by Overkill
Link to comment
Share on other sites

  • Moderators

Overkill,

Awesome? Surely some mistake! But I can solve this one easily - read what I posted last time - "I also had to change your ListBox creation code to get it to work properly".

Why? Because your code as written uses _GUICtrlListView_AddItem - and this returns an index number for the item (from the Help file: "Return Value Success: The index of the new item").

If we want to use GUICtrlRead to get the state of the checkbox, we need to use the ControlID of the item, which is returned by GUICtrlCreateListViewItem (from the Help file: "Return Value Success: Returns the identifier (controlID) of the new control".

If you use GUICtrlCreateListViewItem (like I suggested in the last post) your $STORE array will hold the ControlIds (use _ArrayDisplay to see the difference) and GUICtrlRead will work correctly:

#include<GUIConstantsEx.au3>
;~ #include<OvKFuncs.au3>
#include<WindowsConstants.au3>
#include<TabConstants.au3>
#include<Array.au3>
#Include<GuiListView.au3>
Opt("GUIResizeMode",$GUI_DOCKBORDERS)
Global $MUSICDIR="M:\Music"
Global $EXT="mp3"

If FileExists($MUSICDIR)=0 Then
    $PSUEDODIR=@TEMPDIR&"\Overkill\Music"
    DirCreate($PSUEDODIR)
    DirCreate($PSUEDODIR&"\Artist 1")
    DirCreate($PSUEDODIR&"\Artist 2")
    For $I=1 to 5
        RunWait(@ComSpec & " /c " & 'DIR "' & @ScriptDir & '" /S /B > "' & $PSUEDODIR & '\Artist 1\song' & $I & '.mp3"', "", @SW_HIDE)
    Next
    For $I=1 to 3
        RunWait(@ComSpec & " /c " & 'DIR "' & @ScriptDir & '" /S /B > "' & $PSUEDODIR & '\Artist 2\song' & $I & '.mp3"', "", @SW_HIDE)
    Next
    $MUSICDIR=$PSUEDODIR
EndIf

$ARTISTLIST=DirList($MUSICDIR)

GUICreate("Directory List",622,482,Default,Default,BitOr($GUI_SS_DEFAULT_GUI,$WS_MAXIMIZEBOX,$WS_SIZEBOX))
    $TAB = GUICtrlCreateTab(1,1,620,480,BitOr($GUI_SS_DEFAULT_TAB,$TCS_MULTILINE,$TCS_RIGHTJUSTIFY))

;~ Dim $LISTVIEW[2]
Dim $STORE[$ARTISTLIST[0]+1][1]
    For $I=1 to $ARTISTLIST[0]
        
        GUICtrlCreateTabItem($ARTISTLIST[$I])
        $SONGLIST=FileList($MUSICDIR&"\"&$ARTISTLIST[$I],1,$EXT)
    ;$LISTVIEW=GUICtrlCreateListView("",2,140,615,280)
        ;_GUICtrlListView_SetExtendedListViewStyle($LISTVIEW, BitOR($LVS_EX_BORDERSELECT , $LVS_EX_CHECKBOXES ))
        $LISTVIEW=GUICtrlCreateListView("Filelist",2,140,615,280, -1, $LVS_EX_CHECKBOXES )
        ;_GUICtrlListView_InsertColumn($LISTVIEW, 0, "Filelist")
        ;_GUICtrlListView_SetColumnWidth($LISTVIEW, 0, $LVSCW_AUTOSIZE_USEHEADER)
            _GUICtrlListView_SetColumnWidth($LISTVIEW, 0, $LVSCW_AUTOSIZE_USEHEADER)

            
            For $n = 1 to $SONGLIST[0]
            If $SongList[0]+1 > UBound($STORE,2) Then ReDim $STORE[$ARTISTLIST[0]+1][$SONGLIST[0]+1]
            $STORE[$I][0] = $SONGLIST[0]
        ;$STORE[$I][$N] = _GUICtrlListView_AddItem($LISTVIEW, $SONGLIST[$N], $N - 1)
            $STORE[$I][$N] = GUICtrlCreateListViewItem($SONGLIST[$N], $LISTVIEW)
            
        ;_ArrayDisplay($STORE, "", -1, 1)
            
        Next
        
        GUICtrlSetResizing($LISTVIEW,BitOr($GUI_DOCKBORDERS,$GUI_DOCKTOP))
;~      ReDim $LISTVIEW[$I+2]
    Next

GUICtrlCreateTabItem("")
$BUTTON = GUICtrlCreateButton("Button",1,440,120,30)
GUISetState(@SW_SHOW)

While 1
    $m = GUIGetMsg()
    If $m = $GUI_EVENT_CLOSE THEN
        FileDelete($PSUEDODIR)
        Exit
    EndIf
    If $m = $BUTTON Then
        For $I=1 to $ARTISTLIST[0]
            For $N=1 to $STORE[$I][0]
                If BitOR(GUICtrlRead($STORE[$I][$N], 1), $GUI_CHECKED) = $GUI_CHECKED Then ConsoleWrite("$I="&$I&"$N="&$N&@CRLF)
            Next
        Next
    EndIf
WEnd

Func FileList($dir, $subdirs = 0, $filetype = "*")

Local $F = @TempDir & '\FileListFile.TMP'

$DLERROR1 = FileExists($dir)
If $DLERROR1 = 0 Then
    SetError(1, Default, "")
    MsgBox(16, "ERROR", "Directory " & $dir & " does not exist.")
    Exit
EndIf

Note that I also had to play around with the style settings for your ListBox (as shown in the last script I posted) - if I left the $LVS_EX_BORDERSELECT style in place, it did not work. There is also no real reason to use _GUICtrlListView_InsertColumn - you can set your columns in GUICtrlCreateListView as shown.

Moral of all this (other than read the posted solutions more carefully ;-))? Be careful mixing the builtin AutoIt commands (without the leading underscore) and the UDF commands (with underscore). They often use different parameters or give different return values. No doubt there is a UDF function to check if the checkboxes are in fact checked, but I do not know which.

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

Well, I appreciate the help :) I'm usually doing 3 things at once while reading these posts and i miss something glaringly obvious :)

This is a major hump I'm climbing over too...my coding experience is very very limited =) Been learning and teaching myself a lot, and having fun doing it ^_^

We'll see how this goes...and now all I need to do is find a way to resize the listview to be right below the tabs even if i maximize it and I'm good :huh2: That's what the thread i linked earlier is ^^

Link to comment
Share on other sites

  • Moderators

Overkill,

Your enthusiasm comes over loud and clear - that, with your willingness to try to do something yourself first (shown by your self-generated coding examples), is why you get help so quickly. The "write it for me" brigade get very tiring after a while.

As for "usually doing 3 things at once while reading these posts and i miss something glaringly obvious" - that is emphatically NOT the way to go about coding. It is always the little detail that trips you up. You need to concentrate hard - attention to detail is essential. A good example: you did not capitalise the "i" in the quote above - as a human I can understand it perfectly, but the lump of fused sand which is your microprocessor might find it harder in some circumstances. How easy to code"$lO" and not "$10" - and how hard to spot afterwards.

But never forget (unless it becomes your job, and even then...) that it is FUN, as you have found. I have been enjoying coding for some 40-odd years, I hope you make it long-term pleasure as well.

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

Overkill,

Your enthusiasm comes over loud and clear - that, with your willingness to try to do something yourself first (shown by your self-generated coding examples), is why you get help so quickly. The "write it for me" brigade get very tiring after a while.

As for "usually doing 3 things at once while reading these posts and i miss something glaringly obvious" - that is emphatically NOT the way to go about coding. It is always the little detail that trips you up. You need to concentrate hard - attention to detail is essential. A good example: you did not capitalise the "i" in the quote above - as a human I can understand it perfectly, but the lump of fused sand which is your microprocessor might find it harder in some circumstances. How easy to code"$lO" and not "$10" - and how hard to spot afterwards.

But never forget (unless it becomes your job, and even then...) that it is FUN, as you have found. I have been enjoying coding for some 40-odd years, I hope you make it long-term pleasure as well.

M23

Yeesh...you've got 38 years of coding on me. I'll start catching up in the next 30-40 years though, no worries :)

I also need to figure out how I'm going to build the array that reads which item is checkmarked and associates it with the filename since $songlist gets pushed out each step of the for loop. I wonder if a 56x302 arrray would use up too much memory...

Nope, guess not....Yay! Now it'll tell me which MP3s are selected

TODO:

Make application actually do something

Link to comment
Share on other sites

  • Moderators

Overkill,

TODO:

Make application actually do something

Always helps!!!!

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

Overkill,

Always helps!!!!

M23

I'll try and keep that in mind :)

Any insight you may have on the other thread would be appreciated...program works like this but it'd work better if I could make the listview take up more space...some of the artists i have on here are 200-400 songs ><

Link to comment
Share on other sites

  • 2 years later...

Sorry for the thread necro, but at least it shows I have been doing my research! :mellow:

For some reason I just cannot get the text in the listview to be visible.

If you run the following code you will see that the listview must be populating as the side scroll bar becomes visible. Unfortunately though, the text in the listview, nor the checkboxes is visible.

I just can't seem to spot what is wrong!

#include <ButtonConstants.au3>
#include <DateTimeConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <_sql.au3>
#include <_MySQLConnect.au3>
#include <array.au3>
Dim $ArrayUsers[100], $avArray[100] ; 100 users for now
Global $iRows, $iColumns  
#Region ### START Koda GUI section ### Form=C:\my_autoit_scripts\Reporting Tool\Form1.kxf
$Form1 = GUICreate("Reporting Tool", 623, 442, 247, 266)
$File = GUICtrlCreateMenu("&File")
$MenuItem3 = GUICtrlCreateMenuItem("Exit", $File)
$MenuItem1 = GUICtrlCreateMenu("&Settings")
$MenuItem4 = GUICtrlCreateMenuItem("Connections", $MenuItem1)
$MenuItem2 = GUICtrlCreateMenu("&Help")
$MenuItem5 = GUICtrlCreateMenuItem("About", $MenuItem2)
$gfVertLine = GUICtrlCreateGraphic(128, 0, 1, 417)
GUICtrlSetColor(-1, 0x000000)
$tbFilters = GUICtrlCreateTab(136, 16, 473, 401)
$tbFilter = GUICtrlCreateTabItem("Filters")
$lstReporter = GUICtrlCreateListView("", 152, 176, 241, 97, -1, $LVS_EX_CHECKBOXES)
        _GUICtrlListView_SetColumnWidth($lstReporter, 0, 300)
    For $j = 1 To 25
        GUICtrlCreateListViewItem("Item " & $j , $lstReporter)
    Next
$tbSortBy = GUICtrlCreateTabItem("Sort by")
$tbOutputs = GUICtrlCreateTabItem("Outputs")
GUICtrlCreateTabItem("")
$btnExit = GUICtrlCreateButton("Exit", 8, 376, 113, 25)
$btnGenReport = GUICtrlCreateButton("Generate Report", 8, 336, 113, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE  ; User closes window
   _SQL_Close()   ; Disconnect
   Exit     ; Exit
  Case $btnExit    ; User pressed the Exit button
   _SQL_CLose()   ; Disconnect from database.
   Exit
  Case $btnGenReport      ; User pressed the Generate Report button
  
EndSwitch
WEnd

Hoping someone can help here. :)

Clark

Link to comment
Share on other sites

Use column header text in the GUICtrlCreateListview line and the items will show up.

$lstReporter = GUICtrlCreateListView("1", 152, 176, 241, 97, -1, $LVS_EX_CHECKBOXES)

I used "1" as an example.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I'm not sure if it's a bug or just that the documentation fails to mention it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Hmm. There still seems to be a problem with having checkboxes in ListViews.

If I assign a handle to each ListViewItem and then later try to check whether the ListBoxItem has been checked (as it is a Checkbox), it always returns 0.

So, I am assigning a handle in the above code by:

$ArrayUsers[$j]=GUICtrlCreateListViewItem("Item " & $j , $lstReporter)

And then I later check whether it is checked by:

$avArray[$j] = BitAnd(GUICtrlRead($ArrayUsers[$j]),$GUI_CHECKED)

No matter if the checkbox is checked or not, $avArray[x] always contains a 0

Is this something that I am getting wrong somewhere?

Edited by Clark
Link to comment
Share on other sites

Try it with _GUICtrlListView_GetItemChecked, here's something I threw together from your code above. The code I added is at the bottom in a function called _ReadCheckbox().

#include <ButtonConstants.au3>
#include <DateTimeConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <_sql.au3>
#include <_MySQLConnect.au3>
#include <array.au3>
Dim $ArrayUsers[100], $avArray[100] ; 100 users for now
Global $iRows, $iColumns
#region ### START Koda GUI section ### Form=C:\my_autoit_scripts\Reporting Tool\Form1.kxf
$Form1 = GUICreate("Reporting Tool", 623, 442, 247, 266)
$File = GUICtrlCreateMenu("&File")
$MenuItem3 = GUICtrlCreateMenuItem("Exit", $File)
$MenuItem1 = GUICtrlCreateMenu("&Settings")
$MenuItem4 = GUICtrlCreateMenuItem("Connections", $MenuItem1)
$MenuItem2 = GUICtrlCreateMenu("&Help")
$MenuItem5 = GUICtrlCreateMenuItem("About", $MenuItem2)
$gfVertLine = GUICtrlCreateGraphic(128, 0, 1, 417)
GUICtrlSetColor(-1, 0x000000)
$tbFilters = GUICtrlCreateTab(136, 16, 473, 401)
$tbFilter = GUICtrlCreateTabItem("Filters")
$lstReporter = GUICtrlCreateListView("1", 152, 176, 241, 97, -1, $LVS_EX_CHECKBOXES)
_GUICtrlListView_SetColumnWidth($lstReporter, 0, 300)
For $j = 1 To 25
 GUICtrlCreateListViewItem("Item " & $j, $lstReporter)
Next
$tbSortBy = GUICtrlCreateTabItem("Sort by")
$tbOutputs = GUICtrlCreateTabItem("Outputs")
GUICtrlCreateTabItem("")
$btnExit = GUICtrlCreateButton("Exit", 8, 376, 113, 25)
$btnGenReport = GUICtrlCreateButton("Generate Report", 8, 336, 113, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
 $nMsg = GUIGetMsg()
 Switch $nMsg
  Case $GUI_EVENT_CLOSE ; User closes window
    _SQL_Close()   ; Disconnect
   Exit ; Exit
  Case $btnExit ; User pressed the Exit button
    _SQL_CLose()   ; Disconnect from database.
   Exit
  Case $btnGenReport ; User pressed the Generate Report button
   _ReadCheckbox()
 EndSwitch
WEnd
Func _ReadCheckbox()
 For $I = 0 To _GUICtrlListView_GetItemCount($lstReporter)
  If _GUICtrlListView_GetItemChecked($lstReporter, $I) Then
   MsgBox(0, "", "Item " & $I + 1 & " is Checked")
  EndIf
 Next
EndFunc   ;==>_ReadCheckbox

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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