assing a multiline value to a textbox

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
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.
Locked
User avatar
sunlister
Posts: 1
Meble kuchenne na zamówienie - na wymiar - Wrocław
Joined: Fri Dec 15, 2017 7:02 am

assing a multiline value to a textbox

Post by sunlister »

Hi,
I'm trying to assing a multiline value to a textbox but it put everything on the same line.

The multiline property of the textbox is at True.
When I do a write-host of my variable it show on differents lines.
$example = "Hi
Car
Today"

$I_INFO_SUPP.text = $example

The result is "HiCarToday"

Thanks

User avatar
mxtrinidad
Site Admin
Posts: 399
Joined: Sun Mar 03, 2013 12:42 pm

Re: assing a multiline value to a textbox

Post by mxtrinidad »

Simple fix!

You need to use the Here-String text format the following way:

$example = @"Hi
Car
Today
"@

For more information look at the following link: https://technet.microsoft.com/en-us/lib ... 92792.aspx

Otherwise the previous format will be understood as a one line string no matter how you'll break it within the double (or single) quotes.

:)

jvierra
Posts: 14355
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: assing a multiline value to a textbox

Post by jvierra »

I do not see that at all. Using sunlister's example and assigning to a multiline textbox produces individual lines.

See attached example.
Attachments
Test-TextBoxFormats.psf
(22.87 KiB) Downloaded 50 times

cody m

Re: assing a multiline value to a textbox

Post by cody m »

I also can not reproduce the error that Sunlister is getting.

User avatar
mxtrinidad
Site Admin
Posts: 399
Joined: Sun Mar 03, 2013 12:42 pm

Re: assing a multiline value to a textbox

Post by mxtrinidad »

The only way I can replicate the issue would be by leaving the text box multiline property as "False". Otherwise setting it to "True" and resizing the textbox then it will work with either single, double quotes, and here-string format.
Multiline_2017-12-15_18-19-35.png
Multiline_2017-12-15_18-19-35.png (11.63 KiB) Viewed 1824 times

jvierra
Posts: 14355
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: assing a multiline value to a textbox

Post by jvierra »

I suspect t that this could indicate that the OP is setting the multiline property at the wrong time although, if the box is expanded then it must be set to $true.

There is also a possible problem using Net 1.0 or 2.0. All updates to Net 2.0 seem to have fixed some of the odd behaviors of the initial versions. I have no way of testing so this is just from memory.

Locked