472,811 Members | 1,981 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,811 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 2256
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

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

Similar topics

88
by: Mike | last post by:
Is there a way to determine what a user's default email client is? I read a post from 3 years ago that said no. I guess I'm hoping something has come along since then.
5
by: Dan | last post by:
Hi, I'd like to find out the control that caused a postback to be raised. Obviously this could simply done in a control event handler. I am not going to do this method and would like no...
2
by: Lucky | last post by:
hi guys, i'm working on the context menu for the controls. the problem i'm facing right now is like this : i want to use one context menu for more then one controls lets say i want to use one...
1
by: Ron M. Newman | last post by:
I have a context menu strip. I can Add elements to its "Items", but there is nothing in there to add a sub context menu strip. Menu Item 1 Item 2 Sub Item 1 <-- impossible to add! How do...
1
by: =?Utf-8?B?QnJhZA==?= | last post by:
i have a menu system that is generated dynamically everything works good except for one minor astetic.... I click on a menu item that displays a ContextMenuStrip Popup Menu If an item on...
3
by: ommail | last post by:
I have two RichTextBox controls on a form, and single ContextMenuStrip control which serves for both textboxes. I need to determine which RichTextBox control invokes an event handler in...
1
by: John | last post by:
Hi I am using the below code to get properties and then sub properties on an object; Dim Prop As PropertyDescriptor Dim Props As PropertyDescriptorCollection Props =...
3
by: eljainc | last post by:
Hello, I am trying to figure out how to efficiently do the following: Say I have 10 TextBox fields on a form. From each of those, I would like to have a right click context menu. There are 10...
9
by: =?Utf-8?B?Z2luYWNyZXNzZQ==?= | last post by:
Hi, I have a form (Form1) with a ContextMenuStrip (ContextMenuStrip1). If I pass Form1 to a Utility Sub with the following code: Public Sub Utility(theForm as Object) with theForm For Each...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.