471,092 Members | 1,941 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,092 software developers and data experts.

Determine Control that initiated a ContextMenuStrip?

13
I have a single ContextMenuStrip (with a single menu item) associated with two ListViews, How do I determine which of the two ListViews the menu event occured on?

I could probably find the control through coordinates, but is there an "Object" variable somewhere holding this information?
Apr 20 '08 #1
9 2087
Plater
7,872 Expert 4TB
The events that fire should have a sender object?
Apr 22 '08 #2
horizon
13
The events that fire should have a sender object?
The sender object only returns the menuitem object, I need to know which of the two listview had the menuitem executed over, so I can perform seperate actions depending on the listview the user selected the menu over.

I'll state it again the contextMenuStrip has only one menuitem assigned to it

> "Refresh"

and to it I have the following on click event assigned

private void refreshListToolStripMenuItem_Click(object sender, EventArgs e)
{
!!! sender == refreshListToolStripMenuItem !!!
}

I just need to know which listview to refersh, very simple although .NET is making it very difficult, should probably just create two identical contextMenuStrip and get it over and done with instead of troubling you guys.

And thanks Plater for taking the time to reply.
Apr 23 '08 #3
Plater
7,872 Expert 4TB
Well ok, an event is fired when the menu itself is shown on the listbox (so in that you could have a variable keep track of the sender)

So attach a listener for each listbox to the event. In the event say like:
lastsender=sender;

And be sure to have lastsender originaly declared outside the event handlers so each of them can see it.

Then in your menu items event you can look at the last sender variable and refresh them?
Apr 23 '08 #4
horizon
13
Well ok, an event is fired when the menu itself is shown on the listbox (so in that you could have a variable keep track of the sender)

So attach a listener for each listbox to the event. In the event say like:
lastsender=sender;

And be sure to have lastsender originaly declared outside the event handlers so each of them can see it.

Then in your menu items event you can look at the last sender variable and refresh them?
Ok so answering my first post, "there is no such object", unless creating custom flags/switches?, so like I said I'll just create two separate but identical contextMenus and call it a day!

Thanks once again Plater for your help... it's just a shame that whatever strong points .NET has to offer it's still lacking in very simple and expected behavior found within other languages, here's another fine example with listview's and listbox's missing a very crucial SelectedIndexChanging event... nough said thanks again.
Apr 23 '08 #5
Plater
7,872 Expert 4TB
Both the Listbox and the ListView contain selectedindexchanging events. They clearly show up in my visual studio at least?
Apr 23 '08 #6
horizon
13
Ok so I never mentioned that I was just using a normal c# windows project (on Windows XP), from what I gather only asp .net offers access to the selectedindexchanging event property.

Unless your confusing "SelectedIndexChanged" <<with>> "SelectedIndexChanging" or have built your own listview wraper I can't see how you could possibly access that event within a standard windows project. Would you care to provide an example?
Apr 24 '08 #7
Plater
7,872 Expert 4TB
Ah yes, I was confusing changed with changing.
But now I cannot fathom why you would need to know about "changing" over "changed"?

What use does it offer you?
Apr 24 '08 #8
horizon
13
Doesn't notpad.exe prompt you whether you'd like to save an edited file before closing notepad or even cancel the exit command altogether? same thing!

If I had a list of files within a listview, and somewhere else on the form I allowed data input associated with that selected file in the listview, wouldn't it be appropriated to alert the user attempting to select another file if they'd like to save any modified data first or cancel (ie; stay put on the same listview selected item)?

Anyway I know this is all off-topic from my original question so I'd better leave it here for now and thanks for showing interest in my petty problems Plater, if I have any further questions regarding this I'll follow up within another thread in case others are having the same difficulties as I am.
Apr 24 '08 #9
Plater
7,872 Expert 4TB
Well I am still confused. Notepad notes change of state (which would change of index) not changing of state. Regardless, now I've forgotten. Was your original problem solved?
Apr 24 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

88 posts views Thread by Mike | last post: by
1 post views Thread by =?Utf-8?B?QnJhZA==?= | last post: by
1 post views Thread by John | last post: by
9 posts views Thread by =?Utf-8?B?Z2luYWNyZXNzZQ==?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.