TextBox "Lines" array not assigned when defined in proeprties browser.

Support for all customers who have purchased a SAPIEN PowerShell Studio product license. This forum does not offer a response time guarantee.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

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: 12899
Joined: Tue May 22, 2007 9:57 am
Contact:

TextBox "Lines" array not assigned when defined in proeprties browser.

Post by jvierra » Mon Aug 20, 2018 1:50 pm

To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build: latest
32 or 64 bit version of product: 64
Operating system: W10
32 or 64 bit OS: 64

When assigning an array to the "Lines" property in a textbox using the property browser this is the code generated:

Code: Select all

	$textbox1.Text = 'com1
comp2
comp3
cmp4
comp5
comp6
comp7
comp8'
It should be:

$textbox1.Lines = 'com1','comp2','comp3','cmp4','comp5','comp6','comp7','comp8'
Interestingly the display is correct in W10 and later but not in W7 and earlier.

See attached example:
Attachments
JobPingTest.psf
(28.04 KiB) Downloaded 10 times

User avatar
davidc
Posts: 5475
Joined: Thu Aug 18, 2011 4:56 am

Re: TextBox "Lines" array not assigned when defined in proeprties browser.

Post by davidc » Mon Aug 20, 2018 2:05 pm

This is the designated .NET behavior for this control. The Lines property is not serialized, instead the TextBox uses the Text property to serialize the text.
David
SAPIEN Technologies, Inc.

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

Re: TextBox "Lines" array not assigned when defined in proeprties browser.

Post by jvierra » Mon Aug 20, 2018 2:14 pm

That is true but you can alter that in the designer by overriding the control to generate an array for the"Lines" property. Currently you are NOT assigning the "Lines" property bu are assigning the content of "Lines" to "Text" which causes the serialization failure.

See: https://docs.microsoft.com/en-us/dotnet ... Base_Lines

TextboxBase.Lines is a string array.

https://docs.microsoft.com/en-us/dotnet ... xtBox_Text

TextBox.Text is a string

The "Lines property in the designed is defined as an array but you are assigning it in the generated code to "Text". The above code snippet is copied from the generated code.

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

Re: TextBox "Lines" array not assigned when defined in proeprties browser.

Post by jvierra » Mon Aug 20, 2018 2:31 pm

I think I see the issue.

When VS creates the textbox it assigns this way:
this.textBox1.Text = "comp1\r\ncomp2\r\ncomp3\r\ncomp4";

The same in PSS but the conversion to a string fails because PS doesn't create the string the same way. The default separator in PowerShell is a space. Casting from a string array to a string fails. Apparently W10 Net has altered this behavior so it works.

This is how it should convert:

$textbox1.Text = "com1`r`n
comp2`r`n
comp3`r`n
cmp4`r`n
comp5`r`n
comp6`r`n
comp7`r`n
comp8`r`n
"
]/b]

The default in the control designer is single "linefeed" (`n) character. W10 now accepts that in some places. Earlier versions of Windows don't.