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-ID: 286838

Url: https://administrator.de/forum/powershell-button-in-column-im-datagridview-deaktivieren-286838.html

Ausgedruckt am: 16.04.2025 um 11:04 Uhr

114757
Lösung 114757 28.10.2015 aktualisiert um 13:58:25 Uhr
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
H41mSh1C0R
H41mSh1C0R 28.10.2015 um 13:58:20 Uhr
Goto Top
Hi Jodel,

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

Gruß