Context Menu - Display Member, Value member
-
Hi All, I have a ContextMenu. At the leaf node user want to see both the Code and description as follows. 1 - Employee 2 - Customer 3 - Administrator Is there any property similar to ValueMember (as we have in ComboBox) in MenuItem. I want to be able to get value of code i.e. 1 or 2 or 3 when a leaf node is selected. Thanks Ruchi
-
Hi All, I have a ContextMenu. At the leaf node user want to see both the Code and description as follows. 1 - Employee 2 - Customer 3 - Administrator Is there any property similar to ValueMember (as we have in ComboBox) in MenuItem. I want to be able to get value of code i.e. 1 or 2 or 3 when a leaf node is selected. Thanks Ruchi
You mean like
MenuItem.Index
?Microsoft MVP, Visual C# My Articles
-
You mean like
MenuItem.Index
?Microsoft MVP, Visual C# My Articles
No, not index. code and Description can be 167 - Employee 256 - Administrator 234 - Customer So what I am displaying on the leaf node in above information. But when any of above node is selected, I want to get 167 or 256 or 234 as the value. LIke in combobox, we set Display member and valuemember. Rigth now I am tokenizing the leaf node upon selection as - dealNo = dealNo.Substring(0, dealNo.IndexOf("-", 0)); to get the reqired piece of information.
-
No, not index. code and Description can be 167 - Employee 256 - Administrator 234 - Customer So what I am displaying on the leaf node in above information. But when any of above node is selected, I want to get 167 or 256 or 234 as the value. LIke in combobox, we set Display member and valuemember. Rigth now I am tokenizing the leaf node upon selection as - dealNo = dealNo.Substring(0, dealNo.IndexOf("-", 0)); to get the reqired piece of information.
The
MenuItem
isn't a data-binding control like theComboBox
. What you see is what you get - there is nothing "behind the scenes" that track information like this. That doesn't mean you can't add it, though. Extend theMenuItem
class with your own and add a property to hold this information. In theMenuItem.Click
handler elsewhere in your code, you cast thesender
(the first parameter) to yourMenuItem
derivative class and get the value of that property.Microsoft MVP, Visual C# My Articles
-
The
MenuItem
isn't a data-binding control like theComboBox
. What you see is what you get - there is nothing "behind the scenes" that track information like this. That doesn't mean you can't add it, though. Extend theMenuItem
class with your own and add a property to hold this information. In theMenuItem.Click
handler elsewhere in your code, you cast thesender
(the first parameter) to yourMenuItem
derivative class and get the value of that property.Microsoft MVP, Visual C# My Articles
Thanks for prompt response. You are a genius. Ruchi:)