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

Error HRESULT E_FAIL has been returned from a call to a COM component.

0 Answers 70 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Maruti
Top achievements
Rank 1
Maruti asked on 10 Oct 2011, 02:48 PM
We have a RadMenuItem in my SL application, i am trying to remove an item from the RadMenuItem but i get this exception -

{System.Exception: Error HRESULT E_FAIL has been returned from a call to a COM component.
   at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
   at MS.Internal.XcpImports.Collection_RemoveAt[T](PresentationFrameworkCollection`1 collection, UInt32 index)
   at System.Windows.PresentationFrameworkCollection`1.RemoveAtImpl(Int32 index)
   at System.Windows.Controls.ItemCollection.RemoveAtImpl(Int32 index)
   at System.Windows.PresentationFrameworkCollection`1.RemoveAt(Int32 index)
   at Telerik.Windows.Controls.CollectionExtensions.RemoveAll[T](IList`1 collection)
   at NEMS.MainPage.Instance_GetTemplateMenuCompleted(Object sender, EventArgs`1 e)}

As I am trying to remove all the submenus from existing RadMenuItem named - "template"
When code reaches on the line - objRadMenuMainMenuMRUConnections.Items.RemoveAll(); , exception occurs.


Telerik.Windows.Controls.RadMenuItem objRadMenuMainMenuMRUConnections = (Telerik.Windows.Controls.RadMenuItem)this.FindName("template");             
                 
                var distinctType = e.Value.Select(i => i.type_mid).Distinct();
                objRadMenuMainMenuMRUConnections.Items.RemoveAll();
                for (int intConn = 0; intConn < distinctType.Count(); intConn++)
                {
                    var typename1 = from n in e.Value where n.type_mid == distinctType.ElementAt(intConn) select n;
                    RadMenuItem objConnPart = new RadMenuItem();
                    objConnPart.Header = typename1.ElementAt(0).type_name.ToString();
                    objConnPart.Name = "typeNameMenu" + objConnPart.Header;                
                 
                    objRadMenuMainMenuMRUConnections.Items.Insert(objRadMenuMainMenuMRUConnections.Items.Count, objConnPart);
                    RadMenuItem objMainMenu = (RadMenuItem)objConnPart;
                    for (int submenu = 0; submenu < typename1.Count(); submenu++)
                    {
                        RadMenuItem objSubMenu = new RadMenuItem();
                        objSubMenu.Header = typename1.ElementAt(submenu).template_name.ToString();
                        objSubMenu.Name = typename1.ElementAt(submenu).template_pid.ToString();
                        objSubMenu.Click += new RadRoutedEventHandler(objSubMenu_Click);
                        objMainMenu.Items.Insert(objMainMenu.Items.Count, objSubMenu);
 
                    }
                }

No answers yet. Maybe you can help?

Tags
Menu
Asked by
Maruti
Top achievements
Rank 1
Share this question
or