locked
Add Event for DataGridView Cell Focus RRS feed

  • Question

  • I am trying to figure out how to get an event fired when a cell gets focus. Does DataGridView have that? Thanks.

    Function CellFocus() {
       Write-Host 'It is fired!'
    }
    $Form = New-Object System.Windows.Forms.Form
    $Form.Size = New-Object System.Drawing.Size(600,400)
    $DataGridView = New-Object System.Windows.Forms.DataGridView
    $DataGridView.Location =  New-Object System.Drawing.Point(5,25)
    $DataGridView.Size = New-Object System.Drawing.Size(565,410)
    #$DataGridView.Add_CellFocus({CellFocus})
    $col1 = New-Object System.Windows.Forms.DataGridViewTextboxColumn
    $col1.Name = 'Col1'
    $col1.Width = 50
    $DataGridView.Columns.Add($col1)
    $col2 = New-Object System.Windows.Forms.DataGridViewTextboxColumn
    $col2.Name = 'Col2'
    $col2.Width = 50
    $DataGridView.Columns.Add($col2)
    $Form.Controls.Add($DataGridView)
    $Form.ShowDialog()

    Thursday, September 27, 2018 9:15 PM

Answers

  • Use this:

    $datagridview1_CellEnter=[System.Windows.Forms.DataGridViewCellEventHandler]{
    #Event Argument: $_ = [System.Windows.Forms.DataGridViewCellEventArgs]
    	
    }
    

    or this:

    $datagridview1_MouseHover={
    	
    }

    or this:

    $datagridview1_CellMouseEnter=[System.Windows.Forms.DataGridViewCellEventHandler]{
    #Event Argument: $_ = [System.Windows.Forms.DataGridViewCellEventArgs]
    	
    }
    


    \_(ツ)_/

    • Marked as answer by Ian3 Thursday, September 27, 2018 10:01 PM
    Thursday, September 27, 2018 9:29 PM
  • This works for me:
    $DataGridView.Add_CellEnter({CellFocus})
    • Marked as answer by Ian3 Thursday, September 27, 2018 10:02 PM
    Thursday, September 27, 2018 10:01 PM

All replies

  • Use this:

    $datagridview1_CellEnter=[System.Windows.Forms.DataGridViewCellEventHandler]{
    #Event Argument: $_ = [System.Windows.Forms.DataGridViewCellEventArgs]
    	
    }
    

    or this:

    $datagridview1_MouseHover={
    	
    }

    or this:

    $datagridview1_CellMouseEnter=[System.Windows.Forms.DataGridViewCellEventHandler]{
    #Event Argument: $_ = [System.Windows.Forms.DataGridViewCellEventArgs]
    	
    }
    


    \_(ツ)_/

    • Marked as answer by Ian3 Thursday, September 27, 2018 10:01 PM
    Thursday, September 27, 2018 9:29 PM
  • This works for me:
    $DataGridView.Add_CellEnter({CellFocus})
    • Marked as answer by Ian3 Thursday, September 27, 2018 10:02 PM
    Thursday, September 27, 2018 10:01 PM