Hello, I see there is a $datagridview1_cellcontentclick event, but I'm trying to use the keyboard to move around in the grid and update information based on that.
Is there a similar event for keyboard movement through rows/cells?
When a row is clicked, it updates several labels with information from the row. I would like to be able to move up and down with the keyboard and also have it populate these labels, not just using the mouse.
events with datagridview and keyboard
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.
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.
- supportMIB
- Posts: 62
- Last visit: Thu Feb 29, 2024 11:17 am
- supportMIB
- Posts: 62
- Last visit: Thu Feb 29, 2024 11:17 am
Re: events with datagridview and keyboard
I tried using the _CellEnter but no luck.
I still have to use a mouseclick to pull to the labels
I still have to use a mouseclick to pull to the labels
Code: Select all
$datagridview1_CellEnter = [System.Windows.Forms.DataGridViewCellEventHandler]{
#id
$label1.Text = $datagridview1.rows[$datagridview1.CurrentCell.RowIndex].Cells[0].Value.ToString()
#log type
$label2.Text = $datagridview1.rows[$datagridview1.CurrentCell.RowIndex].Cells[11].Value.ToString()
#source
$label3.Text = $datagridview1.rows[$datagridview1.CurrentCell.RowIndex].Cells[9].Value.ToString()
#eventID
$label4.Text = $datagridview1.rows[$datagridview1.CurrentCell.RowIndex].Cells[1].Value.ToString()
#Level
$label5.Text = $datagridview1.rows[$datagridview1.CurrentCell.RowIndex].Cells[22].Value.ToString()
#User
if ($datagridview1.rows[$datagridview1.CurrentCell.RowIndex].Cells[15].Value.ToString())
{
if ((Get-ADUser -filter * | ? { $_.sid -eq ($datagridview1.rows[$datagridview1.CurrentCell.RowIndex].Cells[15].Value.ToString()) }).samaccountname)
{
$label6.Text = (Get-ADUser -filter * | ? { $_.sid -eq ($datagridview1.rows[$datagridview1.CurrentCell.RowIndex].Cells[15].Value.ToString()) }).samaccountname
}
elseif ($datagridview1.rows[$datagridview1.CurrentCell.RowIndex].Cells[15].Value.ToString() -eq "S-1-5-7")
{
$label6.Text = "Anonymous"
}
elseif ($datagridview1.rows[$datagridview1.CurrentCell.RowIndex].Cells[15].Value.ToString() -eq "S-1-5-18")
{
$label6.Text = "Local System"
}
elseif ($datagridview1.rows[$datagridview1.CurrentCell.RowIndex].Cells[15].Value.ToString() -eq "S-1-5-19")
{
$label6.Text = "Local Service"
}
elseif ($datagridview1.rows[$datagridview1.CurrentCell.RowIndex].Cells[15].Value.ToString() -eq "S-1-5-20")
{
$label6.Text = "Network Service"
}
}
else
{
$label6.Text = "N/A"
}
#OpCode
$label7.Text = $datagridview1.rows[$datagridview1.CurrentCell.RowIndex].Cells[23].Value.ToString()
#Logged
$label8.Text = $datagridview1.rows[$datagridview1.CurrentCell.RowIndex].Cells[16].Value.ToString()
#task category
If ($datagridview1.rows[$datagridview1.CurrentCell.RowIndex].Cells[24].Value.ToString())
{
$label9.text = $datagridview1.rows[$datagridview1.CurrentCell.RowIndex].Cells[24].Value.ToString()
}
else
{
$label9.Text = "None"
}
#Keywords
$label10.Text = $datagridview1.rows[$datagridview1.CurrentCell.RowIndex].Cells[25].Value.ToString()
#Computer
$label11.Text = $datagridview1.rows[$datagridview1.CurrentCell.RowIndex].Cells[14].Value.ToString()
$label2.Visible = $true
$label3.Visible = $true
$label4.Visible = $true
$label5.Visible = $true
$label6.Visible = $true
$label7.Visible = $true
$label8.Visible = $true
$label9.Visible = $true
$label10.Visible = $true
$label11.Visible = $true
$eid = ($datagridview1.rows[$datagridview1.CurrentCell.RowIndex].Cells[1].Value).trim()
$source = ($datagridview1.rows[$datagridview1.CurrentCell.RowIndex].Cells[9].Value).trim()
$linklabel1.Text = "http://www.eventid.net/display.asp?eventid=$eid&source=$source"
}
Re: events with datagridview and keyboard
Works fine for me:
Do this:
Be sure the events are tied to the grid event.
Do this:
- $datagridview1_CellEnter=[System.Windows.Forms.DataGridViewCellEventHandler]{
- #Event Argument: $_ = [System.Windows.Forms.DataGridViewCellEventArgs]
- Write-Host 'Enter'
- }
- $datagridview1_CellLeave=[System.Windows.Forms.DataGridViewCellEventHandler]{
- #Event Argument: $_ = [System.Windows.Forms.DataGridViewCellEventArgs]
- Write-Host 'Leave'
- }