h41msh1c0r
Goto Top

Powershell Button in Column im Datagridview deaktivieren

Hi@All,

ich bekomme mein DatagridView nun ordentlich gefüllt. Die Events werden auch korrekt ausgeführt.
Jetzt fehlt mit noch das deaktivieren des aktuellen Button's in der Zeile bis der Job zuende ist.

Alle Versuche den Button auf deaktiviert zu setzen sind bisher gescheitert.

		$datagridview1.Rows[$_.RowIndex].Cells[6].....

Ein Disable Property habe ich bisher nicht ausmachen können.

Das was ich bisher gefunden habe war mit Verweis auf https://msdn.microsoft.com/en-us/library/ms171619.aspx

Wenn ich die C# Sourcen richtig lese MUSS der Button "überschrieben" werden damit man ihn disablen kann?
Gibt es keine andere Möglichkeit den Button zu disablen?

;(

Gruß

EDIT:

Eine andere Idee die aufkam ist die Zelle auf Readonly zu setzen und erst wenn der Job durch ist sie wieder auf true zu setzen, d.h. bei jedem weiteren Klick wird er Klick ignoriert. Nur egal ob ich die Zelle auf false setze, es wird nicht angezogen.

		$datagridview1.Rows[$_.RowIndex].Cells[6].ReadOnly = $false

Content-Key: 286838

Url: https://administrator.de/contentid/286838

Printed on: April 20, 2024 at 13:04 o'clock

Mitglied: 114757
Solution 114757 Oct 28, 2015 updated at 12:58:25 (UTC)
Goto Top
Mögliche Variante ...
function GenerateForm {

#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null  
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null  
#endregion

#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$dataGridView1 = New-Object System.Windows.Forms.DataGridView
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
$timer = New-Object System.Windows.Forms.Timer
#endregion Generated Form Objects


$script:status = $false
$timer.Interval = 4000
$timer.add_Tick({
    $script:status = $false
    $dataGridView1.Refresh()
})

#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
#Provide Custom Code for events specified in PrimalForms.

$handler_dataGridView1_CellContentClick= {
    if (!$script:status){ 
        $timer.Start()
        $script:status = $true
    }
    
}

$handler_dataGridView1_CellPainting= 
{
    if ($script:status -and $_.ColumnIndex -eq 1 -and $_.RowIndex -eq 0){ 
        $_.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
    }

}

$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
	$form1.WindowState = $InitialFormWindowState
}

#----------------------------------------------
#region Generated Form Code
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 211
$System_Drawing_Size.Width = 292
$form1.ClientSize = $System_Drawing_Size
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$form1.Name = "form1"  
$form1.Text = "Primal Form"  
$form1.add_Closing({
    $timer.Dispose()
})

$System_Windows_Forms_DataGridViewTextBoxColumn_5 = New-Object System.Windows.Forms.DataGridViewTextBoxColumn
$System_Windows_Forms_DataGridViewTextBoxColumn_5.HeaderText = "Name"  
$System_Windows_Forms_DataGridViewTextBoxColumn_5.Name = ""  
$System_Windows_Forms_DataGridViewTextBoxColumn_5.Width = 100

$dataGridView1.Columns.Add($System_Windows_Forms_DataGridViewTextBoxColumn_5)|Out-Null
$System_Windows_Forms_DataGridViewButtonColumn_6 = New-Object System.Windows.Forms.DataGridViewButtonColumn
$System_Windows_Forms_DataGridViewButtonColumn_6.HeaderText = "Button"  
$System_Windows_Forms_DataGridViewButtonColumn_6.Name = ""  
$System_Windows_Forms_DataGridViewButtonColumn_6.Text = "Klick"  
$System_Windows_Forms_DataGridViewButtonColumn_6.Width = 100

$dataGridView1.Columns.Add($System_Windows_Forms_DataGridViewButtonColumn_6)|Out-Null
$dataGridView1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 12
$dataGridView1.Location = $System_Drawing_Point
$dataGridView1.Name = "dataGridView1"  
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 151
$System_Drawing_Size.Width = 268
$dataGridView1.Size = $System_Drawing_Size
$dataGridView1.TabIndex = 0
$dataGridView1.add_CellPainting($handler_dataGridView1_CellPainting)
$dataGridView1.add_CellContentClick($handler_dataGridView1_CellContentClick)

$form1.Controls.Add($dataGridView1)

#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($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null

} #End Function
GenerateForm
Gruß jodel32
Member: H41mSh1C0R
H41mSh1C0R Oct 28, 2015 at 12:58:20 (UTC)
Goto Top
Hi Jodel,

danke für das Beispiel das läuft 1A.

Gruß