Activating a controls event from another control....

G

george

I'm have a little trouble understanding how to do this, but what i wanna do is have it so when the user clicks on an item in the menustrip,
it activates the column click event in a listview that i have on the form. In VB6 it wasn't very hard, but VB.Net is bit different and can't
figureout how to do it.... Anyway, when the user clicks on the menustrip item:

Private Sub ToolStripMenuItem3_Click(ByVal _
sender As System.Object, ByVal e As _
System.EventArgs) Handles _
ToolStripMenuItem3.Click

'Code sends click event to column...

End Sub

It'll activate the column click event...

Private Sub lstvFiles_ColumnClick _
(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.ColumnClickEventArgs) _
Handles lstvFiles.ColumnClick

'Do whatever..

End Sub

I'd like to send '2' as the column being "clicked" (out of the 3 columns 0,1,2 that i have) when the user clicks the menu strip item and
having trouble figuring out what arguments i'm supposed to fill in for 'sender' and 'e'.
Any help would be appriciated.

-george
 
N

Nathan Sokalski

What you normally do is simply add the Handles clause for the control to the
Sub for that control. A Sub can have multiple Handles clauses, as follows:

Private Sub lstvFiles_ColumnClick(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.ColumnClickEventArgs) Handles lstvFiles.ColumnClick,
ToolStripMenuItem3.Click

Doing this will have this Sub handle both the lstvFiles.ColumnClick and
ToolStripMenuItem3.Click events. The parameters for the Sub must obviously
be compatible, which they are in this case since
System.Windows.Forms.ColumnClickEventArgs inherits System.EventArgs. If you
do want to call one from the other by having separate Subs, you can do
something like the following:

Private Sub ToolStripMenuItem3_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles ToolStripMenuItem3.Click
'If desired, you can declare new variables here of type System.Object and
System.Windows.Forms.ColumnClickEventArgs and set their properties instead
of passing sender and e
Me.lstvFiles_ColumnClick(sender,e)
End Sub

Hopefully this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top