473,385 Members | 1,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 2291
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.