Load layout Catastophy error when bind Menu into GridView

2 posts, 0 answers
  1. Gaurang
    Gaurang avatar
    29 posts
    Member since:
    Dec 2010

    Posted 15 Sep 2011 Link to this post

    Hi,

    I am using Docking control in My Dashboard. There are 5 different grid and scheduler etc...
    Now I am binding menu into all diffrenet GridView at runtime. It done perfectly without any error.

    But my problem is When I LoadLayout and then binde Menu into GridView it does not show any menu into GridView and does not show me any error. Lay out restore perfectly.

    Now If I bind Menu into GridView first and then load layout (LoadLayout) it give me error.
    Error HRESULT E_FAIL has been returned from a call to a COM component.
    and Lay out does not restore. Some time it does not give me the error but if I try to dock any girdview or item it gives me Catastrophy error.


    Binding Menu
    here gv = GridView
                gv.Columns.AddRange(new CrmActivityController().GridViewColumns);
                gv.Columns.Remove(gvCalls.Columns[CurrentLanguage.CrmActivity.LBLTYPE.ToString()]);
                GridViewHeaderMenu.SetIsEnabled(gv, true);
                gv.Columns.Remove(gvCalls.Columns["DefaultContact.Account"]);
                gv.Columns.Remove(gvCalls.Columns["DefaultContact.FullName"]);
     
    -----------------------------------------------------------------------------
     
    public class GridViewHeaderMenu
        {
            public static readonly DependencyProperty IsEnabledProperty
               = DependencyProperty.RegisterAttached("IsEnabled", typeof(bool), typeof(CrmGridViewHeaderMenu),
                                                     new System.Windows.PropertyMetadata(new PropertyChangedCallback(OnIsEnabledPropertyChanged)));
             
            private GridView grid = null;
     
            public GridViewHeaderMenu(GridView grid)
            {
                this.grid = grid;
            }     
     
            public static void SetIsEnabled(DependencyObject dependencyObject, bool enabled)
            {
                dependencyObject.SetValue(IsEnabledProperty, enabled);
            }
     
            public void Attach()
            {
                if (grid != null)
                {
                    grid.RowLoaded += new EventHandler<RowLoadedEventArgs>(RowLoaded);
                }
            }
     
            private static void OnIsEnabledPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
            {
                GridView grid = dependencyObject as GridView;
                if (grid != null)
                {
                    if ((bool) e.NewValue)
                    {
                        GridViewHeaderMenu menu = new GridViewHeaderMenu(grid);
                        menu.Attach();
                    }
                }
            }
            
            private void RowLoaded(object sender, RowLoadedEventArgs e)
            {
                if (e.Row is GridViewHeaderRow)
                {
                    InitializeMenus((GridViewHeaderRow) e.Row);
                }
            }
     
            private void InitializeMenus(GridViewHeaderRow row)
            {
                    RadMenuItem item = new RadMenuItem() { Header = "Choose Columns:" };
                    contextMenu.Items.Add(item);
                    foreach (GridViewColumn column in grid.Columns)
                    {
                        RadMenuItem subMenu = new RadMenuItem()
                                                  {
                                                      Header = column.Header,
                                                      IsCheckable = true,
                                                      IsChecked = true
                                                  };
                        subMenu.SetBinding(RadMenuItem.IsCheckedProperty,
                                           new Binding("IsVisible") { Mode = BindingMode.TwoWay, Source = column });
     
                        item.Items.Add(subMenu);
                    }
                    contextMenu.AddHandler(RadMenuItem.ClickEvent, new RoutedEventHandler(OnMenuItemClick));
                    RadContextMenu.SetContextMenu(grid, contextMenu);
                }
            }
    private void OnMenuItemClick(object sender, RoutedEventArgs e)
            {
    }
    }
    }

    I havae post same problem on Menu Forum.
    Thanks,
    Gaurang
  2. Gaurang
    Gaurang avatar
    29 posts
    Member since:
    Dec 2010

    Posted 19 Sep 2011 Link to this post

    Hi,

    I cretaed one sample application to resolved above problem (When I add RadContextMenu into GirdView my docking going to stop and It gives me error [System.Exception: Error HRESULTE_FAIL has been returned from a call to COM component.] if I try to dock any item. Second is, it can not load my layout means restoring layout using LoadLayout method.) and I found that I when I am using GridViewAutoGenerationColumnsEventArgs Events it gives me error. Because I want to add Hyperling in two diffenrent columns at runtime. For that I used below code.

    <Grid.Resources>
                <telerikcontrols:GridViewDynamicHyperlinkColumn  x:Name="GridViewDataColumnHyperLinkButtonAccount"  IsReadOnly="True">
                    <telerikcontrols:GridViewDynamicHyperlinkColumn.CellStyle>
                        <Style TargetType="telerikcontrols:GridViewCell">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="telerikcontrols:GridViewCell">
                                        <Border BorderThickness="0,0,0.5,0" BorderBrush="Black">
                                            <Grid>
                                                <HyperlinkButton x:Name="hlbAccount" HorizontalContentAlignment="Left" Content="{Binding Account}"
                                                                             VerticalContentAlignment="Center" Foreground="Blue"
                                                                             TargetName="_blank" Click="hlbAccount_Click" Width="Auto" />
                                                <TextBox x:Name="tbAccount"  Text="{Binding ActivityUUID}" Visibility="Collapsed"/>
                                            </Grid>
                                        </Border>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </telerikcontrols:GridViewDynamicHyperlinkColumn.CellStyle>
                </telerikcontrols:GridViewDynamicHyperlinkColumn>
                <telerikcontrols:GridViewDynamicHyperlinkColumn  x:Name="GridViewDataColumnHyperLinkButtonContact"  IsReadOnly="True">
                    <telerikcontrols:GridViewDynamicHyperlinkColumn.CellStyle>
                        <Style TargetType="telerikcontrols:GridViewCell">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="telerikcontrols:GridViewCell">
                                        <Border BorderThickness="0,0,0.5,0" BorderBrush="Black">
                                            <Grid>
                                                <HyperlinkButton x:Name="hlbContact" HorizontalContentAlignment="Left" Content="{Binding Contact}"
                                                                             VerticalContentAlignment="Stretch"  Foreground="Blue"
                                                                             TargetName="_blank" Click="hlbContact_Click"  Width="Auto"/>
                                                <TextBox x:Name="tbContect"  Text="{Binding ContactUUID}" Visibility="Collapsed"/>
                                            </Grid>
                                        </Border>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </telerikcontrols:GridViewDynamicHyperlinkColumn.CellStyle>
                </telerikcontrols:GridViewDynamicHyperlinkColumn>
            </Grid.Resources>
     
    -----------------------------------------------------------------------------------------------------------------------------
     
    <telerik:RadSplitContainer InitialPosition="DockedRight" Orientation="Vertical">
                    <telerik:RadPaneGroup>
                        <telerik:RadPane Header="Pane Right 1" telerik:RadDocking.SerializationTag="PaneRight1">
                            <Grid>
                                <Controls:CrmGridView x:Name="gvData" AutoGenerateColumns="False" AutoGeneratingColumn="gvData_AutoGeneratingColumn"></CrmControls:CrmGridView>
                            </Grid>
                        </telerik:RadPane>
                    </telerik:RadPaneGroup>
    </telerik:RadSplitContainer>
     
    -----------------------------------------------------------------------------------------------------------------------------
     
    private void gvData_AutoGeneratingColumn(object sender, GridViewAutoGeneratingColumnEventArgs e)
            {
                if (e.Column.UniqueName == "ACCOUNT" || e.Column.UniqueName == "CONTACTACCOUNT")
                {
                    GridViewDynamicHyperlinkColumn linkColumn = new GridViewDynamicHyperlinkColumn();
     
                    if (e.Column.UniqueName == "ACCOUNT")
                    {
                        linkColumn.CellStyle = GridViewDataColumnHyperLinkButtonAccount.CellStyle;
                        linkColumn.UniqueName = "DefaultContact.Account";
                    }
                    else if (e.Column.UniqueName == "CONTACTACCOUNT")
                    {
                        linkColumn.CellStyle = GridViewDataColumnHyperLinkButtonContact.CellStyle;
                        linkColumn.UniqueName = "DefaultContact.FullName";
                    }
     
                    linkColumn.DataMemberBinding = (e.Column as Telerik.Windows.Controls.GridViewBoundColumnBase).DataMemberBinding;
                    linkColumn.Header = e.Column.Header;
                    linkColumn.Width = new GridViewLength();
                    linkColumn.IsResizable = true;
                    linkColumn.DisplayIndex = gvData.Columns.Count;
     
                    e.Column = linkColumn;
                }
                else
                {
                    e.Cancel = true;
                }
            }


    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.Controls.ItemCollection.RemoveImpl(Object value)

       at System.Windows.Controls.ItemCollection.RemoveInternal(Object value)

       at System.Windows.PresentationFrameworkCollection`1.Remove(T value)

       at Telerik.Windows.Controls.RadSplitContainer.RemoveFromParent()

       at Telerik.Windows.Controls.Docking.DockingLayoutFactory.CleanUpLayout(RadSplitContainer container)

       at Telerik.Windows.Controls.Docking.DockingLayoutFactory.CleanUpLayout()

       at Telerik.Windows.Controls.RadDocking.LoadLayout(Stream source, Boolean raiseEventsIfNoSerializationTag)

       at Telerik.Windows.Controls.RadDocking.LoadLayout(Stream source)

     



    Please reply me.
    Something I am missing here or not?


    Thanks,
    Gaurang
  3. DevCraft banner
Back to Top