I have a problem, if I run a Task for query the eventlog in an runspace, pass my Datagridview to that runspace with a SessionStateProxy Variable and fill the DataGridView with elements in the runspace, it works fine to fill and show the result in the gui, but the problem is, that the scrollbar isn't working. It's displaying but the user can't interact with it:
Here is a little example of my problem, am I doing anything wrong?
- $global:Thread = [PowerShell]::Create().AddScript(
- #------------------------------------------------------------------------
- # Source File Information (DO NOT MODIFY)
- # Source ID: bb36ea54-55c6-48e0-aba7-96d95fb99734
- # Source File:
- #------------------------------------------------------------------------
- <#
- .NOTES
- --------------------------------------------------------------------------------
- Code generated by: SAPIEN Technologies, Inc., PowerShell Studio 2017 v5.4.139
- Generated on: 24.05.2017 10:23
- Generated by:
- --------------------------------------------------------------------------------
- .DESCRIPTION
- GUI script generated by PowerShell Studio 2017
- #>
- #----------------------------------------------
- #region Application Functions
- #----------------------------------------------
- #endregion Application Functions
- #----------------------------------------------
- # Generated Form Function
- #----------------------------------------------
- function Show-Test_psf {
- #----------------------------------------------
- #region Import the Assemblies
- #----------------------------------------------
- [void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
- [void][reflection.assembly]::Load('System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
- [void][reflection.assembly]::Load('System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
- #endregion Import Assemblies
- #----------------------------------------------
- #region Generated Form Objects
- #----------------------------------------------
- [System.Windows.Forms.Application]::EnableVisualStyles()
- $form1 = New-Object 'System.Windows.Forms.Form'
- $datagridview1 = New-Object 'System.Windows.Forms.DataGridView'
- $Column1 = New-Object 'System.Windows.Forms.DataGridViewTextBoxColumn'
- $InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
- #endregion Generated Form Objects
- #----------------------------------------------
- # User Generated Script
- #----------------------------------------------
- $form1_Load={
- #TODO: Initialize Form Controls here
- $global:Thread = [PowerShell]::Create().AddScript(
- {
- for ($i = 0; $i -lt 1000; $i++)
- {
- $datagridview1.Rows.Add("$i")
- }
- })
- $MultiThread = [RunspaceFactory]::CreateRunspace()
- $MultiThread.ApartmentState = "STA"
- $MultiThread.Open()
- $MultiThread.SessionStateProxy.SetVariable("datagridview1", $datagridview1)
- $global:Thread.Runspace = $MultiThread
- $global:Thread.BeginInvoke()
- }
- # --End User Generated Script--
- #----------------------------------------------
- #region Generated Events
- #----------------------------------------------
- $Form_StateCorrection_Load=
- {
- #Correct the initial state of the form to prevent the .Net maximized form issue
- $form1.WindowState = $InitialFormWindowState
- }
- $Form_Cleanup_FormClosed=
- {
- #Remove all event handlers from the controls
- try
- {
- $form1.remove_Load($form1_Load)
- $form1.remove_Load($Form_StateCorrection_Load)
- $form1.remove_FormClosed($Form_Cleanup_FormClosed)
- }
- catch { Out-Null <# Prevent PSScriptAnalyzer warning #> }
- }
- #endregion Generated Events
- #----------------------------------------------
- #region Generated Form Code
- #----------------------------------------------
- $form1.SuspendLayout()
- #
- # form1
- #
- $form1.Controls.Add($datagridview1)
- $form1.AutoScaleDimensions = '6, 13'
- $form1.AutoScaleMode = 'Font'
- $form1.ClientSize = '284, 261'
- $form1.Name = 'form1'
- $form1.Text = 'Form'
- $form1.add_Load($form1_Load)
- #
- # datagridview1
- #
- $datagridview1.ColumnHeadersHeightSizeMode = 'AutoSize'
- [void]$datagridview1.Columns.Add($Column1)
- $datagridview1.Dock = 'Fill'
- $datagridview1.Location = '0, 0'
- $datagridview1.Name = 'datagridview1'
- $datagridview1.Size = '284, 261'
- $datagridview1.TabIndex = 0
- #
- # Column1
- #
- $Column1.AutoSizeMode = 'Fill'
- $Column1.HeaderText = 'Test'
- $Column1.Name = 'Column1'
- $form1.ResumeLayout()
- #endregion Generated Form Code
- #----------------------------------------------
- #Save the initial state of the form
- $InitialFormWindowState = $form1.WindowState
- #Init the OnLoad event to correct the initial state of the form
- $form1.add_Load($Form_StateCorrection_Load)
- #Clean up the control events
- $form1.add_FormClosed($Form_Cleanup_FormClosed)
- #Show the Form
- return $form1.ShowDialog()
- } #End Function
- #Call the form
- Show-Test_psf | Out-Null