Redirect to another page using GridViewDynamicHyperlinkColumn.

2 posts, 0 answers
  1. Frank
    Frank avatar
    1 posts
    Member since:
    Aug 2013

    Posted 29 Aug 2013 Link to this post

    Greetings.

    The code below (see partial XAML and C#) display the grid of "Prospects".
    Prospect's First, Last, and Middle name are GridViewDynamicHyperlinkColumn. User can click on one of those three columns and be redirected to the Prospect's edit form.
    All this works perfectly until user decides to sort the grid (no matter which column).
    After the grid has been sorted, clicking on First, Last, or Middle name has NO EFFECT.

    Am I missing something?
    If there is anything wrong, I certainly can't see it anymore.
    Please help.

    Thank you,

    Frank M.

     

    private void OnProspectGridUnLoaded(object sender, Telerik.Windows.Controls.GridView.RowUnloadedEventArgs e) {
        var row = e.Row as GridViewRow;
        if (row != null) {
            ((HyperlinkButton)row.Cells[0].Content).RemoveHandler(FrameworkElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(OnProspectLinkClicked));
            ((HyperlinkButton)row.Cells[1].Content).RemoveHandler(FrameworkElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(OnProspectLinkClicked));
            ((HyperlinkButton)row.Cells[2].Content).RemoveHandler(FrameworkElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(OnProspectLinkClicked));
        }
    }
     
    private void OnProspectGridLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e) {
        var row = e.Row as GridViewRow;
        if (row != null) {
            ((HyperlinkButton)row.Cells[0].Content).AddHandler(FrameworkElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(OnProspectLinkClicked), true);
            ((HyperlinkButton)row.Cells[1].Content).AddHandler(FrameworkElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(OnProspectLinkClicked), true);
            ((HyperlinkButton)row.Cells[2].Content).AddHandler(FrameworkElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(OnProspectLinkClicked), true);
        }
    }
     
     
    private void OnProspectLinkClicked(object sender, MouseButtonEventArgs e) {
        try {
            Type type = e.Source.GetType();
            if (type == typeof(System.Windows.Controls.ContentPresenter)) {
                DataRowView rowView = (DataRowView)((Telerik.Windows.Controls.GridView.GridViewCell)((((Telerik.Windows.Controls.GridView.HyperlinkButton)(sender)).Parent))).ParentRow.Item;
                DataRow selectedRow = (DataRow)rowView.Row;
                if (selectedRow != null && selectedRow[0] != DBNull.Value) {
                    ProspectInformation.ProspectId = Convert.ToString(selectedRow["ProspectGuid"]);
                    if (ProspectInformation.ProspectId != null && ProspectInformation.ProspectId != string.Empty) {
                        ((POWERPitch.Base.TabPanel)(((TabControl)parent).Parent)).IsFromHomePage = true;
                        ((POWERPitch.Base.TabPanel)(((TabControl)parent).Parent)).LinkName = Contexts.QuickLinkNames.OPEN_PROSPECT;
                        ((TabControl)parent).SelectedIndex = 2;
                    }
                }
            }
        } catch (Exception ex) {
            IPMessageBox.ShowExceptionMessage("Exception in HomeForAgents.OnProspectLinkClicked " + ex.Message);
        }
    }

     

    <telerik:RadBusyIndicator DisplayAfter="0" x:Name="radBusyIndicator" Background="Transparent"
        HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" >
     
     <telerik:RadGridView Name="searchResultsGridView" EnableRowVirtualization="True" CanUserSortColumns="True"
        ColumnWidth="*" CanUserDeleteRows="False" IsReadOnly="True" IsFilteringAllowed="False" CanUserInsertRows="False"
        VerticalAlignment="Top" RowLoaded="OnSearchResultsGridLoaded" SelectionChanged="OnSearchResultsSelectionChanged"
        RowUnloaded="OnSearchResultsGridUnLoaded" Height="Auto" Width="Auto" Margin="5,3,5,0" Style="{StaticResource
        GridViewStyle}" HeaderRowStyle="{StaticResource HeaderStyle}" >
     
     <telerik:RadGridView.Columns>
     
         <telerik:GridViewDataColumn Name="createDateCol" Header="Last Updated" Width="Auto" DataMemberBinding="{Binding
            CreatedDate}" HeaderCellStyle="{StaticResource ColumnHeaderStyle}" CellStyle="{StaticResource
            gridcellStyle}"/>
     
         <telerik:GridViewDynamicHyperlinkColumn Name="lastNameCol" Header="Last Name" Width="Auto"
             DataMemberBinding="{Binding LastName}" HeaderCellStyle="{StaticResource ColumnHeaderStyle}"
            CellStyle="{StaticResource gridcellStyle}"/>
     
         <telerik:GridViewDynamicHyperlinkColumn Name="firstNameCol" Header="First Name" Width="Auto"
            DataMemberBinding="{Binding FirstName}" HeaderCellStyle="{StaticResource ColumnHeaderStyle}"
            CellStyle="{StaticResource gridcellStyle}"/>
     
         <telerik:GridViewDataColumn Name="dateOfBrthCol" Header="Age" Width="Auto" DataMemberBinding="{Binding DOB}"
            HeaderTextAlignment="Center" TextAlignment="Center" HeaderCellStyle="{StaticResource ColumnHeaderStyle}"
            CellStyle="{StaticResource gridcellStyle}"/>
     
         <telerik:GridViewDataColumn Name="genderCol" Header="G" Width="Auto" DataMemberBinding="{Binding Gender}"
            HeaderCellStyle="{StaticResource ColumnHeaderStyle}" CellStyle="{StaticResource gridcellStyle}"/>
     
         <telerik:GridViewDataColumn Name="stateCol" Header="ST" Width="Auto" DataMemberBinding="{Binding StateCode}"
            HeaderCellStyle="{StaticResource ColumnHeaderStyle}" CellStyle="{StaticResource gridcellStyle}"/>
     
         <telerik:GridViewDataColumn Name="quoteIdCol" Header="Quote/Illustration" Width="Auto"
            HeaderTextAlignment="Left"     TextAlignment="Left" DataMemberBinding="{Binding QuoteId}"
             HeaderCellStyle="{StaticResource ColumnHeaderStyle}" CellStyle="{StaticResource gridcellStyle}"/>
     
         <telerik:GridViewDynamicHyperlinkColumn Name="prodDescCol" Header="Product Summary" UniqueName="prodDescCol"
             DataMemberBinding="{Binding ProductDesc}" HeaderCellStyle="{StaticResource ColumnHeaderStyle}"
            CellStyle="{StaticResource gridcellStyle}"/>
     
         <telerik:GridViewDataColumn Name="annPremCol" Header="Annual Premium" Width="Auto" DataMemberBinding="{Binding
            AnnualPremium}" HeaderTextAlignment="Right" TextAlignment="Right" HeaderCellStyle="{StaticResource
            ColumnHeaderStyle}" CellStyle="{StaticResource gridcellStyle}"/>
     
         <telerik:GridViewDataColumn Name="agntCdCol" Header="Agent Code" Width="Auto" DataMemberBinding="{Binding
            AgentCode}" HeaderTextAlignment="Right" TextAlignment="Right" HeaderCellStyle="{StaticResource
            ColumnHeaderStyle}" CellStyle="{StaticResource gridcellStyle}"/>
     
         <telerik:GridViewDataColumn Name="agntNameCol" Header="Agent Name" Width="Auto" DataMemberBinding="{Binding
            AgentName}" HeaderCellStyle="{StaticResource ColumnHeaderStyle}" CellStyle="{StaticResource gridcellStyle}"/>
     
         <telerik:GridViewDataColumn Name="gaCodeCol" Header="GA Code" Width="Auto" DataMemberBinding="{Binding GACode}"
             HeaderTextAlignment="Right" TextAlignment="Right" HeaderCellStyle="{StaticResource ColumnHeaderStyle}"
            CellStyle="{StaticResource gridcellStyle}"/>
     
         </telerik:RadGridView.Columns>
     
       </telerik:RadGridView>
     
     </telerik:RadBusyIndicator>
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 03 Sep 2013 Link to this post

    Hello,

    I have tested the code you shared (except from the code executed when the OnProspectGridUnLoaded
    event is raised). No matter if I sorted the GridView this handler was invoked.

    Would you please check how your code is executed? You can also check our "Column Types" WPF Demo on how to configure the GridViewDynamicHyperlinkColumn in xaml.

    Regards,
    Didie
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top