Checked List Box Import from CSV

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms 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.
This topic is 6 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
A. Hohl
Posts: 18
Last visit: Thu Aug 01, 2019 3:13 am

Checked List Box Import from CSV

Post by A. Hohl »

Hello,

I am trying to design a CheckedListBox that will import a list of computer names from a CSV and allow me to later do a "foreach" command to "mass enable" computers that have been disabled in AD. any pointers on how to accomplish this?

Thanks,
Austin
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Checked List Box Import from CSV

Post by jvierra »

Have you looked in the info center for reference on how to use controls
https://info.sapien.com/index.php/guis/gui-controls
User avatar
A. Hohl
Posts: 18
Last visit: Thu Aug 01, 2019 3:13 am

Re: Checked List Box Import from CSV

Post by A. Hohl »

The site has a lot of helpful information, I am having a hard time specifically finding the command to import the CSV to the check list though...

Thanks,
Austin
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Checked List Box Import from CSV

Post by jvierra »

It works the same as a ListBox. The checks will not automatically be set. TO do that you need to use a DataTable.
A DataGridView works better.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Checked List Box Import from CSV

Post by jvierra »

I couldn't find any examples of how to use a CLB so here is a demo:

The code is simple:

Code: Select all

$csvtxt = @'
Name,Status
X0011,True
X0012,False
X0013,False
X0014,True
'@
$form1_Load={
    $csv = ConvertFrom-Csv $csvtxt
    $checkedlistbox1.DataSource = [System.Collections.ArrayList]$csv
    $checkedlistbox1.DisplayMember = 'Name'
    for($i=0;$i -lt $checkedlistbox1.Items.Count;$i++){
        $state = if($checkedlistbox1.Items[$i].Status -eq 'True'){$true}else{$false}
        $checkedlistbox1.SetItemChecked($i,$state)
    }
}
I used embedded CSV but it can be imported.
Attachments
Demo-CheckedListBoxLoad.psf
(26.18 KiB) Downloaded 180 times
User avatar
LtMandella
Posts: 61
Last visit: Mon May 07, 2018 4:03 pm

Re: Checked List Box Import from CSV

Post by LtMandella »

@JV
You ought to scrape this site for all your "how-to" answers, examples, and demos and compile into a book.
I bet you would sell a pile of books! I would buy it! (and in any event thanks for all your continuing help...)
Lt
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Checked List Box Import from CSV

Post by jvierra »

Thanks. Great idea. Now I need to find an editor and a publisher. Of course by the time I publish five other people will have published the same thing.

A book is a big and time consuming project. I used to write technical sales documents on a Saturday afternoon that went 60 or more pages. I think it was good I had a captive audience. Always an emergency. Always a sale that had to be done in days for a project that could take years.

I do like knocking off quick demos. They require limited effort.
User avatar
A. Hohl
Posts: 18
Last visit: Thu Aug 01, 2019 3:13 am

Re: Checked List Box Import from CSV

Post by A. Hohl »

Worked perfectly. Thank you!
This topic is 6 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked