One button for multiple boxes

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 7 years and 3 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
T4RH33L
Posts: 2
Last visit: Mon Apr 03, 2017 6:47 am

One button for multiple boxes

Post by T4RH33L »

Hello everyone!
I'm working on my first tool after purchasing PowerShell Studio today and I'm running into an issue. I have a button that I want to execute if a selection is made from a listbox or if text is entered into a textbox. I tried to use an if, elseif, else but PS won't accept $listbox.selecteditem -eq $true -and $textbox.text -eq $null. I was wondering if anyone else has done something like this? Thanks in advance.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: One button for multiple boxes

Post by jvierra »

Sorry. What does "PS won't accept..." mean? Is there an error message? You have to be more specific.
User avatar
T4RH33L
Posts: 2
Last visit: Mon Apr 03, 2017 6:47 am

Re: One button for multiple boxes

Post by T4RH33L »

PS = PowerShell (EDIT: I'm sorry, I just re-read your reply. I wasn't trying to be facetious here. I was assuming you were attempting to say that "PS" itself was too ambiguous.)

I was trying to use an "if" statement where if $listbox.SelectedItem was not $null and $textbox.Text was $null, then my button would execute my function. Then I would add an else for the reverse situation. But, what I am seeing is:

Load-DataGridView : Cannot validate argument on parameter 'Item'. The argument is null. Provide a valid value for the argument, and then try running the command again.

While I am still curious about whether or not this can be done, I have found a different way to accomplish what I want.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: One button for multiple boxes

Post by jvierra »

Your error is with the Load statement? Without any code it is not possible to understand what your issue is.
User avatar
AdamUK
Posts: 31
Last visit: Fri Jun 22, 2018 2:29 am

Re: One button for multiple boxes

Post by AdamUK »

I would just use the value assigned in the text box or drop down list as in when you run your function it would be like my-function $textbox.text
Then your running the function of the value in the textbox. Is this what you are after?
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: One button for multiple boxes

Post by dan.potter »

Is this what you're after?
Attachments
lbclick.psf
(41.82 KiB) Downloaded 120 times
This topic is 7 years and 3 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