wlo413 Posted February 25, 2009 Report Share Posted February 25, 2009 Is it possible to remove some of the items in the context menu that shows up when a user right mouse clicks on a chart? I am using chart1.ContextMenu.MenuItems.RemoveAt(1); however, this keeps throwing a NullReferenceException. Likewise, is it possible to add an item, previously removed, back into the context menu? What I want to do is, hide the Data Grid item until a certain condition is met. Once this condition is satisfied, show the Data Grid item. I want to do the same thing to the Data Grid item on the toolbar as well. Quote Link to comment Share on other sites More sharing options...
CarlosAC Posted February 25, 2009 Report Share Posted February 25, 2009 Hi wlo413. Even though the command will always be present in the chart , you can hide the item to the end user. Following code show how to remove Pie Gallery item from Gallery Types Menu. Int32 index = chart1.Commands[CommandId.Gallery].SubCommands.IndexOf((Int32)CommandId.Pie); chart1.Commands[CommandId.Gallery].SubCommands.RemoveAt(index); If you want to add it again, you should use following code: chart1.Commands[CommandId.Gallery].SubCommands.Add(CommandId.Pie); Quote Link to comment Share on other sites More sharing options...
wlo413 Posted February 25, 2009 Author Report Share Posted February 25, 2009 Ok, that example makes sense. However, which attribute of CommandID refers to the context menu?Also, when I apply the example to remove the Data Grid item from the tool bar in my code snippet: Int32 index = chart1.Commands[CommandId.ToolBar].SubCommands.IndexOf((Int32)CommandId.DataGrid);chart1.Commands[CommandId.ToolBar].SubCommands.RemoveAt(index);I get an ArgumentOutOfRangeException because the index is always returning -1. I can remove the DataGrid item from the toolbar by manually figuring out its index and using this:chart1.ToolBar.RemoveAt(14);But I can't seem to add the DataGrid item back becausechart1.Commands[CommandId.ToolBar].SubCommands.Add(CommandId.DataGrid);doesn't appear to be doing anything. Quote Link to comment Share on other sites More sharing options...
CarlosAC Posted February 26, 2009 Report Share Posted February 26, 2009 Hi wlo413. If you want to get the Main Context Menu, please use following code: Command myCommand = chart1.Commands[CommandId.ContextMenuBack]; Now, regarding to DataGrid, you are confused about Toolbar Command and Chart Quote Link to comment Share on other sites More sharing options...
wlo413 Posted February 26, 2009 Author Report Share Posted February 26, 2009 Hello Carlos Thanks for the help, that was exactly what I needed. However to correct a typo in your code example to remove the Data Grid from the main context menu. Int32index = chart1.Commands[CommandId.ContextMenuBack].SubCommands.IndexOf((Int32)CommandId.DataGrid); chart1.Commands[CommandId.Gallery].SubCommands.RemoveAt(index); CommandID.Gallery should be replaced with CommandID.ContextMenuBack I knew exactly what you meant though Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.