Job Handling

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.
This topic is 8 years and 5 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.
Locked
User avatar
monoeagle
Posts: 108
Last visit: Fri Jan 26, 2024 10:44 am

Job Handling

Post by monoeagle »

hi,

The following Job works:
if ($_.ColumnIndex -eq 6)
{

#
# place to disable the button in the cell??
# $datagridview1.Rows[$_.RowIndex].Cells[1].Control = $false
#

$tb_FileCounter.Text = "Kopierte Dateien: "
$pgb_robocopy.Value = 0
$source = $AblageFZDatenSnb
$destination = ($AblageFZDaten + "\" + $(get-date -f MM-dd-yyyy_HH_mm) + "_" + $datagridview1.Rows[$_.RowIndex].Cells[1].value).toString();
$global:totalcnt = (Robocopy $source $destination /MIR /E /ETA /L /NC /NP).length - 1

Add-JobTracker -Name "JobCopyUploadFZDaten" -ArgumentList $source, $destination `
-JobScript {
Param ($source, $destination)
robocopy $source $destination /MIR /E /ETA /NC /NP /R:10 /W:10 /TEE /LOG:"C:\temp\logfile_$(get-date -f MM-dd-yyyy_HH_mm)_Upload_FZDaten.log"
}`
-UpdateScript {
Param ($Job)

$global:currentcnt += ($Job | Receive-Job).Count
$percent = ($global:currentcnt / $global:totalcnt) * 100

if ($percent -lt 100)
{
$pgb_robocopy.Value = $percent
}
}`
-CompletedScript {
Param ($Job)
$pgb_robocopy.Value = 100

#
# place to enable the button in the cell after Job is finished??
# $datagridview1.Rows[$_.RowIndex].Cells[1].Control = $true
#
}
}
But if I want to disable the Button in the cell until the job is finished where it has to be placed?
If the Place is correct, the "method" Control which is used in many examples doesn't exist.
Do you have any hint?

Setting Cell to:

$datagridview1.Rows[$_.RowIndex].Cells[1].visible = $false

It delivers: not possible, read only


greetings
monoeagle
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Job Handling

Post by jvierra »

"visible" means it is on the screen. If false it is not visible on the screen. It is not a settable property.

Inside of the cell is a reference to the control. You can disable the button.
User avatar
monoeagle
Posts: 108
Last visit: Fri Jan 26, 2024 10:44 am

Re: Job Handling

Post by monoeagle »

hi jvierra,

how do I get access to the reference?

$datagridview1.Rows[$_.RowIndex].Cells[1].Control = $true

Doesn't work. I also can't find any setfunction in the list which opens after the .....Cells[1]. point.

A lot of sites writes examples like this:

DataGridView1.Rows(i).Cells(2).ReadOnly = False

and refers to h...ps....msdn.mic....ft.c../en-us/libr ... 71619.aspx, but if I set ...Cells[1].ReadOnly = $true it doesn't work.

greetz
monoeagle
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Job Handling

Post by jvierra »

Set the cell to ReadOnly and, n a click, test the readonly property. If it is $true then ignore the click. Set the cell to false when the job completes.
User avatar
monoeagle
Posts: 108
Last visit: Fri Jan 26, 2024 10:44 am

Re: Job Handling

Post by monoeagle »

$handler_dataGridView1_CellPainting =
{

if ($_.ColumnIndex -eq 5)
{
$_.Paint($_.CellBounds, [System.Windows.Forms.DataGridViewPaintParts]::Background)
$_.Graphics.DrawString("- job running -", (New-Object System.Drawing.Font("Arial", 10)), (new-object System.Drawing.SolidBrush("Gray")), (new-Object System.Drawing.PointF(($_.CellBounds.Left + 2), ($_.CellBounds.Top + 2))))
$_.Handled = $true
}

}

The Eventhandler works as an example. Now I have to modify the correct row and the marker when the handler will be run. =)
This topic is 8 years and 5 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.
Locked