XML data to a label.text property

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.
User avatar
jvierra
Posts: 13725
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: XML data to a label.text property

Post by jvierra » Thu Feb 21, 2019 11:06 am

This is the variable you need to check: $BindingURL'

Code: Select all

$buttonSEARCH_Click= {
     [System.Windows.Forms.MessageBox]::Show($BindingURL')  # <==== get the value of the variable
     [xml]$file = (Get-Content 'c:\test\programdata\Server Configuration.xml')
     $detailsLBL.Text = $file.SelectSingleNode("//Instance[BindingHostName='$BindingURL']").Name
 } 

User avatar
jvierra
Posts: 13725
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: XML data to a label.text property

Post by jvierra » Thu Feb 21, 2019 11:09 am

Please post the code that sets that variable? This variable ->>> $detailsLBL

User avatar
miketartaglia
Posts: 91
Joined: Mon Feb 02, 2015 7:44 am

Re: XML data to a label.text property

Post by miketartaglia » Thu Feb 21, 2019 11:48 am

jvierra wrote:
Thu Feb 21, 2019 11:09 am
Please post the code that sets that variable? This variable ->>> $detailsLBL
$buttonSEARCH_Click= {
#TODO: Place custom script here
[xml]$file = (Get-Content 'c:\test\programdata\Server Configuration.xml')
$detailsLBL.Text = ($file.SelectSingleNode("//Instance[BindingHostName='$BindingURL']").Name)

}

User avatar
jvierra
Posts: 13725
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: XML data to a label.text property

Post by jvierra » Thu Feb 21, 2019 12:22 pm

Sorry I meant to ask for this variable $BindingURL.

User avatar
miketartaglia
Posts: 91
Joined: Mon Feb 02, 2015 7:44 am

Re: XML data to a label.text property

Post by miketartaglia » Thu Feb 21, 2019 12:35 pm

I don't know where that code is. What you are talking about is a text box Named BindingURL. I enter text in this box and I assumed that the variable is set then. Please correct me if I'm wrong.

User avatar
jvierra
Posts: 13725
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: XML data to a label.text property

Post by jvierra » Thu Feb 21, 2019 1:11 pm

How can you not know where the code is? You wrote it didn't you.

It sounds to me like the variable is not a simple text variable. If it is the text box then it is an object. I posted twice telling you how to determine what you have. Please go back and address the posts you ignored. They outline how to determine the issue and how to fix it.

User avatar
jvierra
Posts: 13725
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: XML data to a label.text property

Post by jvierra » Thu Feb 21, 2019 1:32 pm

Sorry for the short answer butI am in the middle of something.

A textbox has a property that gets the contents.

For instructions on how to use a textbox control see: https://info.sapien.com/index.php/guis/ ... ox-control

User avatar
jvierra
Posts: 13725
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: XML data to a label.text property

Post by jvierra » Fri Feb 22, 2019 2:29 am

I had a couple of minutes to kill so here is an example form showing how to use my XML code to query from a textbox and update a control. It is very simple.
Attachments
Test-XPathResults.psf
(35.97 KiB) Downloaded 19 times

User avatar
miketartaglia
Posts: 91
Joined: Mon Feb 02, 2015 7:44 am

Re: XML data to a label.text property

Post by miketartaglia » Fri Feb 22, 2019 9:09 am

That made me see the light. The problem was with me not assigning the $BindingURL.text to a variable after the user clicked the search button. Now I remember how to do it. thanks for the guidance.

Locked