Right click cell doesn't read content

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 7 years and 9 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
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Right click cell doesn't read content

Post by stevens »

Product, version and build: latest
32 or 64 bit version of product: 64
Operating system: W2K12R2
32 or 64 bit OS: 64
PowerShell Version: latest

DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM

Hi,

I have this code (below) to make sure when a user clicks a cell in a gridview, it takes the values $Computer and $User. This works fine for a mouse click but not for a right mouse click (tried mouse down, cell mouse down but nothing works), please advise. When a user click left mouse a text appears with computername and username, right mouse nothing happens.

$datagridviewComputer_CellClick = [System.Windows.Forms.DataGridViewCellEventHandler]{
try
{
$Global:ComputerName = $datagridviewComputer.CurrentRow.Cells[0].Value
$Global:UserName = $datagridviewComputer.CurrentRow.Cells[1].Value
Add-Logs -text "Your selection: Computer $ComputerName and User $UserName"
}
DevinL
Posts: 1098
Last visit: Tue Jun 06, 2017 9:15 am

Re: Right click cell doesn't read content

Post by DevinL »

[TOPIC MOVED TO POWERSHELL GUIS FORUM BY MODERATOR]
DevinL
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Right click cell doesn't read content

Post by jvierra »

There is no "Right-Click" in a DGV. The right mouse is dedicated to the context menu.
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Right click cell doesn't read content

Post by stevens »

Ok, so that leaves me fully in the dark. What is the way to make it work then?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Right click cell doesn't read content

Post by jvierra »

stevenbaert wrote:Ok, so that leaves me fully in the dark. What is the way to make it work then?
Make what work? To click a cell just event the "CellContentClick" event. Look at the events under the DGV.
  1. [Codebox=powershell file=Untitled.ps1]
  2. $datagridview1_CellContentClick=[System.Windows.Forms.DataGridViewCellEventHandler]{
  3. #Event Argument: $_ = [System.Windows.Forms.DataGridViewCellEventArgs]
  4.    
  5. }
[/Codebox]
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Right click cell doesn't read content

Post by jvierra »

To capture right click you can capture the MouseDown event like this:
  1. $datagridview1_MouseDown=[System.Windows.Forms.MouseEventHandler]{
  2. #Event Argument: $_ = [System.Windows.Forms.MouseEventArgs]
  3.     Write-Host $_.Button
  4. }
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Right click cell doesn't read content

Post by stevens »

MouseDown was all I need, thanks!
It captures as well left mouse as right mouse actions.
Got rid of other mouseactions.
This topic is 7 years and 9 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