Combobox example

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 8 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
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Combobox example

Post by localpct »

I am in the same boat, kinda.

Whenever I select one of the items in a combobox, it does the code twice.

So as you can see,
I want to select the VolumeLabel of the drive
Have it determine if it's FAT32, if not place a check in the box and update the Is NOT FAT32 Label
Then search the flash drive for certain directories and files

If pass, labels turn green and no check boxes
If fail, labels turn red and check boxes are added

Then I'd add to the createflashdrive_Click {

if $checkboxISNOTFAT32.Checked = $true
{ do this}
If $checkboxNETWORKDRIVERS.Checked = $true
{do this}

etc...

Yes I'm aware that my code is in the $comboboxFLASHDRIVELABEL_Click but it's 4am on the East Coast and I have to get up in 5 hours and I"ve been working on this all day.

I've tried get-wmiobject as well as System.IO.DriveInfo and they both appear to get the drive info I need, just need to change VolumeName and VolumeLabel. Any guidance is appreciated.
Attachments
FlashDriveCreator.psf
(232.99 KiB) Downloaded 172 times
Capture.PNG
Capture.PNG (13.43 KiB) Viewed 3261 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Combobox example

Post by jvierra »

When the index changes the code fires. THis happens at least twice before the combobox is displayed. You need to account for these extra events.

If you use the "SelectedIndexChanged" event which is the default for combobox the code will behave better.
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Combobox example

Post by localpct »

i was using the selectedindexchanged event but wasnt getting my results but I figured it out

Code: Select all

$comboboxFLASHDRIVELABEL.SelectedItem | ForEach-Object {
		if ((Test-Path -Path (Join-Path -Path ($_.Name) -ChildPath "Network Drivers") -PathType Container))
		{
			
			$labelALLMODELNETWORKDRIVEPRESENT.Text = 'Folder is present'
			$labelALLMODELNETWORKDRIVEPRESENT.ForeColor = 'Green'
			
		}
		
		else
		{
			$labelALLMODELNETWORKDRIVEPRESENT.Text = 'Folder does not exist'
			$labelALLMODELNETWORKDRIVEPRESENT.ForeColor = 'Red'
			$checkboxNETWORKDRIVERS.Checked = $true
		}
	}
This appears to be working so far.
User avatar
ianstraw
Posts: 29
Last visit: Wed Oct 28, 2015 8:22 am

Re: Combobox example

Post by ianstraw »

Thanks for the info so far.

Can you expand on it a little please? If i have a drop down list of domains, D1, d2, d3
The user selects d1 and hits the button. For this example the button will do a get-aduser * but i need to know to get the selected item to feed into get-aduser so it will run get-aduser * on d1?

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

Re: Combobox example

Post by jvierra »

Get-AdUser gets users not domains.

Not sure what you are trying to do.

Get-AdUser DOMAIN\userid

Try using help and work at a prompt until you understand how Get-AdUser works.
User avatar
ianstraw
Posts: 29
Last visit: Wed Oct 28, 2015 8:22 am

Re: Combobox example

Post by ianstraw »

I know how ad-user works. I dont think you understand what i am trying to do.

Let me try again....

- Combo box has 3 different domains to choose from
- for this example the button runs get-aduser *

If the person using the form selects d1 from the dropdown list, hits the button then the get-aduser runs on d1
If the person using the form selects d2 from the dropdown list, hits the button then the get-aduser runs on d2
If the person using the form selects d3 from the dropdown list, hits the button then the get-aduser runs on d3
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Combobox example

Post by jvierra »

The following will explain how to use Get-AdUser and how to option it. You cannot use Get-AdUser *. It will not work.

https://technet.microsoft.com/en-us/lib ... 17241.aspx

There are a number of options which you may need to adjust for your installation. The page explains all of the options and has examples. Try it at command prompt until you understand how to use the command. After that it will be easy to move into a form.
User avatar
ianstraw
Posts: 29
Last visit: Wed Oct 28, 2015 8:22 am

Re: Combobox example

Post by ianstraw »

Oh wow! Ok, i know how get-aduser works and yes get-aduser * does not work. I was simply trying to explain that the button would get all users off that domain that was selected in the form.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Combobox example

Post by jvierra »

ianstraw wrote:Oh wow! Ok, i know how get-aduser works and yes get-aduser * does not work. I was simply trying to explain that the button would get all users off that domain that was selected in the form.
Still not szure what you are asking.

To get the combobox just reference $combobox1.selecteditem. If itt has the domain name (FQDN, NB name, IP) it will work.
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Combobox example

Post by dan.potter »

Use the server parameter of get-aduser to query other domains.
This topic is 8 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