473,385 Members | 2,044 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.

Is there a way of getting the index of an item in a collection of ToolStripMenuItems?

I use to do this:

Dim index As Integer = CType(sender, MenuItem).Index

but ToolStripMenuItems do not have an Index property so I can set the Tag or
MergeIndex property of those items and use that.

But that is error prone since changes in the menu require that those values
be kept synchronized.

Even though there is no Index property I have the feeling that the
collection might have the equivalent.

Is there a way of getting the index of the item in the collection?

Thanks
Feb 26 '08 #1
5 3728
As in most cases the overall goal could help (and which event are you
handling ?)

My first thought would be first to have the event handled by the specific
event handler tied to this control.

If you need something more generic, my personal preference is to use the
name or just test the object (If sender Is MyObject etc...) rather than the
index.

If you really need the index you'll find an IndexOf method on almost if not
all collections (get at the owner and use the IndexOf method on the
collection that contains these elements to get the index).
--
Patrice

"Academia" <ac************@a-znet.coma écrit dans le message de news:
%2****************@TK2MSFTNGP04.phx.gbl...
>I use to do this:

Dim index As Integer = CType(sender, MenuItem).Index

but ToolStripMenuItems do not have an Index property so I can set the Tag
or MergeIndex property of those items and use that.

But that is error prone since changes in the menu require that those
values be kept synchronized.

Even though there is no Index property I have the feeling that the
collection might have the equivalent.

Is there a way of getting the index of the item in the collection?

Thanks


Feb 26 '08 #2
"Academia" <ac************@a-znet.comschrieb
I use to do this:

Dim index As Integer = CType(sender, MenuItem).Index

but ToolStripMenuItems do not have an Index property so I can set
the Tag or MergeIndex property of those items and use that.

But that is error prone since changes in the menu require that those
values be kept synchronized.

Even though there is no Index property I have the feeling that the
collection might have the equivalent.

Is there a way of getting the index of the item in the collection?
You should have mentioned the type of collection. Is it
ToolStripItemCollection? Why not look at the members available? I see
the IndexOf method. It probably returns the index of the item.
Armin

Feb 26 '08 #3

This is why the method is called:

For Each mI As ToolStripItem In Me.MenuItemGeneral_Tool.DropDownItems

AddHandler mI.Click, AddressOf HandlesTool_Click

Next mI

and this is how index is used

CType(MenuItemGeneral_Tool.DropDownItems(menuTag),
ToolStripMenuItem).Checked = True

===

the ToolStripMenuItem.CheckOnClick doesn't work for me because I don't want
it unchecked automatically.

thanks
"Academia" <ac************@a-znet.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>I use to do this:

Dim index As Integer = CType(sender, MenuItem).Index

but ToolStripMenuItems do not have an Index property so I can set the Tag
or MergeIndex property of those items and use that.

But that is error prone since changes in the menu require that those
values be kept synchronized.

Even though there is no Index property I have the feeling that the
collection might have the equivalent.

Is there a way of getting the index of the item in the collection?

Thanks


Feb 26 '08 #4
Academia wrote:
>
I use to do this:
Dim index As Integer = CType(sender, MenuItem).Index
and this is how index is used

CType(MenuItemGeneral_Tool.DropDownItems(menuTag),
ToolStripMenuItem).Checked = True
You are walking around the block to get next door. There is no need to take the
sender, find its index (or tag), then use that to retrieve the item from the
parent collection. You already have the item; just use it directly.

CType(sender, TooStripMenuItem).Checked = True
Feb 26 '08 #5
I ask sometimes because I want to be sure I'm not missing something simple.

Good thing I don't try to play chess.

thanks

"Steve Gerrard" <my********@comcast.netwrote in message
news:BP******************************@comcast.com. ..
Academia wrote:
>>
I use to do this:
Dim index As Integer = CType(sender, MenuItem).Index
>and this is how index is used

CType(MenuItemGeneral_Tool.DropDownItems(menuTag) ,
ToolStripMenuItem).Checked = True

You are walking around the block to get next door. There is no need to
take the sender, find its index (or tag), then use that to retrieve the
item from the parent collection. You already have the item; just use it
directly.

CType(sender, TooStripMenuItem).Checked = True


Feb 26 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Gerry Abbott | last post by:
Hi all. Could someone tell me is this number fixed when the item is created, or can it be changed? So for example if there are three forms, with index 0,1,2 and form 1 is deleted, does form...
4
by: kscdavefl | last post by:
I ahve a datagrid on a web form. I need to change the value in column 3 as follows. If the value in column 3 reads 0, I want to change it to read YES. How can I accomplish this task. ...
2
by: kscdavefl | last post by:
When I run the following code: private void applicationPermissionGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if (e.Item.ItemType ==...
1
by: DBLWizard | last post by:
Howdy All, I am wondering if there is a way to find the column index by the header name. What I am trying to get away from is using a hardcoded number in the ItemDataBound event. Something...
2
by: Bill Ray | last post by:
I have the following function in my WidgetCollection class. What is a more efficient way of doing this? I tried the commented code below, but I couldn't get it to work. Public Overloads ReadOnly...
1
by: ME | last post by:
I was running into a problem with the DataGridView while binding it to an object Collection. I got it working and I thought others might like to know how. -------------- Problem -------------...
14
by: Rich | last post by:
Yes, I need to store some values in an array type collection object that can hold 3 or more parameters per index. I have looked at the collection object, hashtable object and would prefer not to...
7
by: Pucca | last post by:
Hi: Below is the error I got from the 2 lines of code below. I don't understand why and how to correct it. The actionMenu.DropDownItems has 0 item in its collection at the time of the code. ...
4
by: forest demon | last post by:
I have an IList/Collection that contains items in a ListView. If i click on an item in the ListView, i can capture the index (lv.SelectedItems.Index) and reference the correct item in the...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.