Datagridview not loading results after exe is built

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION 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.
This topic is 5 years and 7 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.
User avatar
okurt@leumit.co.il
Posts: 3
Last visit: Sat Nov 30, 2019 11:41 pm

Datagridview not loading results after exe is built

Post by okurt@leumit.co.il »

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

Hello all,
I have a problem with powershell studio after compiling a script to an exe:
I have a DataGridView which is loaded with the built in function: Load-DataGridView
while working with the Powershell studio or after exporting the project to PS1 file,
the datagridview displays all results perfectly.
after converting the project to an exe (build to 32bit or 64bit exe), some of the users report that
they can not see the data in the datagridview, it just appears as blank.
the same users on the same PC can run the exported ps1 file and everything works fine.
the same problem occurs even when using any compilation and on any OS type (windows 7 & 10, 32bit and 64bit)

I will appreciate any help you can offer.

thank you in advance,
Oren
User avatar
Alexander Riedel
Posts: 8488
Last visit: Tue Apr 16, 2024 8:42 am
Answers: 20
Been upvoted: 37 times

Re: Datagridview not loading results after exe is built

Post by Alexander Riedel »

You left out what product version you are using.
Additionally, since you say it only happens on some machines but not others, you need to include for which powershell version you build
and what PowerShell version is on the machines where it doesn't work.
Additionally we need some code or information as to what you put in that datagridview.
As you can imagine it makes a fundamental difference whether the data cannot be added to the view or whether the data does not get generated in the first place.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
okurt@leumit.co.il
Posts: 3
Last visit: Sat Nov 30, 2019 11:41 pm

Re: Datagridview not loading results after exe is built

Post by okurt@leumit.co.il »

I am using PowerShell Studio 2018 v5.5.153 (latest, as noted)
I am using powershell 5 and compile the exe to use powershell v5 host on both 32 and 64 bit
As described - I have tested the exe and the ps1 files on the same machines with the same users - the ps1 works fine and the exe does not.
the code I am using is as follows:
Load-DataGridView -DataGridView $datagridviewADQueryResults -Item $table

and the function is:
function Load-DataGridView
{
<#
.SYNOPSIS
This functions helps you load items into a DataGridView.

.DESCRIPTION
Use this function to dynamically load items into the DataGridView control.

.PARAMETER DataGridView
The ComboBox control you want to add items to.

.PARAMETER Item
The object or objects you wish to load into the ComboBox's items collection.

.PARAMETER DataMember
Sets the name of the list or table in the data source for which the DataGridView is displaying data.

#>
Param (
[ValidateNotNull()]
[Parameter(Mandatory = $true)]
[System.Windows.Forms.DataGridView]$DataGridView,
[ValidateNotNull()]
[Parameter(Mandatory = $true)]
$Item,
[Parameter(Mandatory = $false)]
[string]$DataMember
)
$DataGridView.SuspendLayout()
$DataGridView.DataMember = $DataMember

if ($Item -is [System.ComponentModel.IListSource]`
-or $Item -is [System.ComponentModel.IBindingList] -or $Item -is [System.ComponentModel.IBindingListView])
{
$DataGridView.DataSource = $Item
}
else
{
$array = New-Object System.Collections.ArrayList

if ($Item -is [System.Collections.IList])
{
$array.AddRange($Item)
}
else
{
$array.Add($Item)
}
$DataGridView.DataSource = $array
}

$DataGridView.ResumeLayout()
}

this is how the form is displayed in exe (the datagridview is marked in red):
AdminThingError.png
AdminThingError.png (19.57 KiB) Viewed 2053 times
additionally - I know the the data is retrived because I have some more info on the form that is taken from the same data
for example - the rowcount of the data is assigned to a label text (marked in green in the attached image, 18 is the expected number):
$lblRecordCount.Text = $table.Rows.Count

If you need any more data, please tell me and I will provide it.

thank you,
Oren.
User avatar
Alexander Riedel
Posts: 8488
Last visit: Tue Apr 16, 2024 8:42 am
Answers: 20
Been upvoted: 37 times

Re: Datagridview not loading results after exe is built

Post by Alexander Riedel »

From the screen shot it is not possible to determine if the construction of the Datagridview fails, meaning the control is not even there, or if it simply has no data.
I suggest to comment out the code that fills the grid and and just hard some test data and send it to the grid. Then we know if the grid even exists.
As you point out that this only occurs on some machines but not others. This is usually due to missing .config files, missing .NET framework versions etc.
Please verify that you are deploying the generated .config file along with the exe. Compare the installed .NET versions from a machine where it works with a machine where it does not.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
okurt@leumit.co.il
Posts: 3
Last visit: Sat Nov 30, 2019 11:41 pm

Re: Datagridview not loading results after exe is built

Post by okurt@leumit.co.il »

Hi Alexander,
I have figured it out:
It does not concern the Datagridview at all.... the problem was in the data table creation:
when using ps1 script. and executing commands with "out-null"(for example: $table.Columns.Add($property) > null , or "command | out-null"), the null file is created in the execution directory.
When using an exe, the null file is created in the windows directory.
in my organization, users do not have write access to the windows directory, therefore the data was not constructed correctly and could not be loaded to the datagridview.
thank you for your help.

best regards,
Oren
This topic is 5 years and 7 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.