This is a migrated thread and some comments may be shown as answers.

Saving / Loading Layouts with ContextMenuStrip

3 Answers 94 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 23 Apr 2014, 04:28 AM
I am using Visual Studio 2013 w/ Telerik 2014.1.402.40 for WinForms. I've been working on implementing the Save / Load layout functionality that comes with the RadGridView and everything is working great with the exception of one thing...

My grid has a System.Windows.Forms.ContextMenuStrip assigned to it. There are various items in the menu that do different things. When I load my grid it works find. If I save a layout, then load it back to the grid, the context menu still appears, but clicking items within it no longer work.

I opened one of the saved layouts and noticed it has a section in it relating to the contextmenustrip, but I don't understand this, or why saving the grid layout would affect the ContextMenuStrip that is assigned to it.

There must be something I'm missing, thanks for any info.

Matt

3 Answers, 1 is accepted

Sort by
0
Matt
Top achievements
Rank 1
answered on 23 Apr 2014, 04:42 AM
Here is a quick test project I put together. Load it up, right click the grid, and select the item in the context menu. You will get a message box stating success. Then click the button to save the layout, then click the button to restore the layout. Try to select the item in the context menu again, and you will no longer see the message box. Download the test project that was created in VS 2013 at the following link:

http://resources.rock-pond.com/LayoutTest.zip
0
Matt
Top achievements
Rank 1
answered on 23 Apr 2014, 04:47 AM
I've performed some other testing and found a workaround... It seems that re-assigning the ContextMenuStrip after loading the layout resolves the issue.

            radGridView1.LoadLayout(@"C:\test.xml");
            radGridView1.ContextMenuStrip = null;
            radGridView1.ContextMenuStrip = contextMenuStrip1;
0
George
Telerik team
answered on 25 Apr 2014, 12:31 PM
Hello Matt,

Thank you for contacting us.

All the properties of RadGridView are being serialized, including the ContextMenuStrip. When you load the layout the context menu is being recreated, however the items no longer have event handlers, since they are completely new instances, that is why your handler is not being invoked. You can either reassign the context menu as in your case or re-subscribe to the events of the items.

Let me know if you have further questions.

Regards,
George
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
Matt
Top achievements
Rank 1
Answers by
Matt
Top achievements
Rank 1
George
Telerik team
Share this question
or