Page 1 of 1

ContextMenuStrip question

Posted: Thu Apr 16, 2020 1:49 pm
by Domtar
hi everyone,

in a GUI i'm working on, i would like to use the same ContextMenuStrip that i would associate to a few datagridview to select an item. since it's the same function that is running, it's only logical to use the same strip.

I've created 2 datagridview, associated my strip to each, now i'm trying to understand how to get the calling control.

is there a way to identify the control who called the strip?

thank you!

Re: ContextMenuStrip question

Posted: Thu Apr 16, 2020 3:17 pm
by jvierra
Use the same event for all controls that share the strip. The current control that the strip is associated with is the "$contextmenustrip1.SourceControl"

Example:

Code: Select all

$testToolStripMenuItem_Click={
	Write-Host $contextmenustrip1.SourceControl.Name
}

Re: ContextMenuStrip question

Posted: Thu Apr 16, 2020 3:32 pm
by jvierra
Here is a better example:

Code: Select all

$testToolStripMenuItem_Click={
	Write-Host $this.Name
	Write-Host $contextmenustrip1.SourceControl.Name
}

$testerToolStripMenuItem_Click={
	Write-Host $this.Name
	Write-Host $contextmenustrip1.SourceControl.Name
}

Re: ContextMenuStrip question

Posted: Thu Apr 16, 2020 6:35 pm
by Domtar
exactly what i was looking for :-)

thank you J.