I'm having trouble understanding how CheckedListBox controls work. So I create the collection of items within it, how does powershell studio use these items? Is each item its own variable? I am reading the Winforms control reference, the info center, etc but cannot seem to grasp how this works. I am creating a form so that a user can copy files to a directory on a number of servers. The user would check the check box and then when the remaining scripts are run, it would copy to the servers that were checked. Is there a way to view the checked items and see them in the console? I am assuming that the checked items are $Checkedboxlist.CheckedItems.
Is there a method for checking certain boxes when a particular check box is checked? (example - "All servers" check box would select all servers, or a check box for a group of servers in a certain geographic area).
Understanding CheckedListBox controls
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
-
- Posts: 7
- Last visit: Thu Mar 28, 2024 11:54 am
Re: Understanding CheckedListBox controls
Item in a ListBox of any time are stored as an array in the "Items" property of the ListBox.
See the following article for instructions on how to use this control:
https://info.sapien.com/index.php/guis/ ... ew-control
See the following article for instructions on how to use this control:
https://info.sapien.com/index.php/guis/ ... ew-control
-
- Posts: 7
- Last visit: Thu Mar 28, 2024 11:54 am
Re: Understanding CheckedListBox controls
So the items in the array, are verbatim? So if I have "Server1" it will be $Server1?
Re: Understanding CheckedListBox controls
No - the item in the array will be the value of $server1 and not the variable itself. If $server1 is an object then the object will have a reference in the list and be accessible through the list. Objects variables are always references to objects and not the object. Objects are structures stored in memory.
-
- Posts: 7
- Last visit: Thu Mar 28, 2024 11:54 am
Re: Understanding CheckedListBox controls
Ok so I need to be able to build a variable list and reference the items in the list to the variables?
Re: Understanding CheckedListBox controls
YOur question is far too vague.
I recomend starting with this as it will help you understand what variables and lists are in programming as your view of this is based on everyday usage.
Windows PowerShell™ 4: TFM
I recomend starting with this as it will help you understand what variables and lists are in programming as your view of this is based on everyday usage.
Windows PowerShell™ 4: TFM
Re: Understanding CheckedListBox controls
an example would be loading the checkedlistbox like so:
$checkedlistboxfiles.DisplayMember = "filename"
$checkedlistboxfiles.items.addrange(@($fileobject))
This assumes you have a $fileobject with a property called filename.
You might then have a button that wants to do something to all the files that you have 'checked'.
The button_click event would have code like this:
In the middle of the loops I retrieve the filename into $file which contains a filename that has been 'checked'.
Is that the sort of thing you were after?
$checkedlistboxfiles.DisplayMember = "filename"
$checkedlistboxfiles.items.addrange(@($fileobject))
This assumes you have a $fileobject with a property called filename.
You might then have a button that wants to do something to all the files that you have 'checked'.
The button_click event would have code like this:
- if ($checkedlistboxfiles.checkedIndices.count -gt 0)
- {
- for ($i = $checkedlistboxfiles.Items.Count - 1; $i -ge 0; $i--)
- {
- if ($checkedlistboxfiles.GetItemChecked($i))
- {
- $file = $checkedlistboxfiles.Items[$i].filename
- }
- }
- }
Is that the sort of thing you were after?
Re: Understanding CheckedListBox controls
To get a CheckedListBox item when it is checked just put your code into the event for the "ItemCheck" event. It will had you the item being checked.
https://docs.microsoft.com/en-us/dotnet ... mework-4.8
The item is "$_.CurrentItem",
https://docs.microsoft.com/en-us/dotnet ... mework-4.8
The item is "$_.CurrentItem",
Re: Understanding CheckedListBox controls
how can we skip the need to click an item twice to check it?
thank!
thank!
Re: Understanding CheckedListBox controls
Set the property to check on click. "CheckOnClick"
https://docs.microsoft.com/en-us/dotnet ... etcore-3.1
https://docs.microsoft.com/en-us/dotnet ... etcore-3.1