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

performance of the view is very slow using nested RowDetailsTemplateSelectors and DataTemplates

1 Answer 321 Views
GridView
This is a migrated thread and some comments may be shown as answers.
KR
Top achievements
Rank 1
Veteran
KR asked on 10 Sep 2019, 03:47 AM

Hi,

This view basically displays Questions, Question Choices and selects or displays the answer as well. The Question Choices can be a Yes/No, MultipleSelect, MultipleChoice or FreeText.  The view has a RadGridView on line 260 and this grid has RowDetailsTemplate which displays question number and question text in a RadGridView . This RadGridView has has RowDetailsTemplateSelector which displays the Question Choices which is either Yes/NO or Multiple Choice or Free Text etc based on the  Question Type. This in turn calls the DataTemplates. Basically with this complex nested GridViews and Templates and the ModelView methods, the view takes at least 3 minutes to load 30 questions. 

How can I improve the performance of this View?

Your guidance is appreciated.

 

View:

<UserControl.Resources>
           <DataTemplate x:Key="SurveyQuestionMultipleChoiceDataTemplate">
            <StackPanel Grid.Column="1" Orientation="Vertical" Width="Auto" HorizontalAlignment="Left" Margin="35,0,0,0"  >
                <RadioButton  HorizontalAlignment="Left"   VerticalAlignment="Center" Content="{Binding SurveyChoiceText}" IsChecked="{Binding IsChecked}"  FontSize="13"
                                        GroupName="SurveyQuestionRadioGroup" />
            </StackPanel>
        </DataTemplate>
 
        <DataTemplate x:Key="SurveyQuestionMultipleSelectDataTemplate">
            <StackPanel Grid.Column="1" Orientation="Vertical" Width="Auto" HorizontalAlignment="Left"  Margin="30,5,0,0" >
                <CheckBox  HorizontalAlignment="Left" HorizontalContentAlignment="Center" Content="{Binding SurveyChoiceText}"  IsChecked="{Binding IsChecked}" FontSize="13"
                                                              telerik:StyleManager.Theme="Office_Black" />
            </StackPanel>
        </DataTemplate>
 
        <DataTemplate x:Key="SurveyQuestionsRankingDataTemplate">
            <StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Left"  Margin="23,0,0,0" Width="Auto">
                <ComboBox Name="cbxRank"  DisplayMemberPath="RankNumberID"
                          VerticalAlignment="Center"
                          HorizontalAlignment="Left"
                          Margin="10,10,0,0"
                          ItemsSource="{Binding Rank}"  >
                </ComboBox>
                <TextBlock Text="{Binding SurveyChoiceText}"  TextWrapping="Wrap" Width="Auto" VerticalAlignment="Center" Margin="5,0,0,0" FontSize="13" />
            </StackPanel>
        </DataTemplate>
    </ResourceDictionary>
</UserControl.Resources>
<Grid>
    <Border Margin="20">
        <Grid Width="Auto">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.Resources>
                <telerik:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
                 
                <DataTemplate x:Key="YesNoTemplate" >
                    <StackPanel Orientation="Vertical" >
                        <StackPanel Orientation="Horizontal"  Margin="30,10,10,15" Width="Auto">
                            <RadioButton IsChecked="{Binding  SrvyAnswer.IsYesChecked}" Content="Yes" VerticalAlignment="Center" GroupName="YesNo" />
                            <RadioButton IsChecked="{Binding  SrvyAnswer.IsNoChecked}"  Content="No" VerticalAlignment="Center" GroupName="YesNo" />
                        </StackPanel>
                        <StackPanel Orientation="Horizontal"  Margin="30,0,0,5">
                            <TextBlock Text="{Binding SrvyAnswer.Comments}" IsEnabled="False" Height="Auto" Width="1400"  TextWrapping="Wrap" FontSize="13" Margin="5,10,10,15" />
                        </StackPanel>
                    </StackPanel>
 
                </DataTemplate>
                 
                <DataTemplate x:Key="MultipleChoiceTemplate">
 
                    <telerik:RadListBox ItemsSource="{Binding SurveyQuestionAnswers}" VerticalAlignment="Top" 
                            ItemTemplate="{StaticResource SurveyQuestionMultipleChoiceDataTemplate}" />
 
                </DataTemplate>
                 
                <DataTemplate x:Key="MultipleSelectTemplate">
                    <StackPanel Orientation="Vertical">
                        <telerik:RadListBox ItemsSource="{Binding SurveyQuestionAnswers}" VerticalAlignment="Top"  BorderThickness="0"  Margin="0,0,10,10"
                                ItemTemplate="{StaticResource SurveyQuestionMultipleSelectDataTemplate}" />
 
                        <StackPanel Orientation="Horizontal" Visibility="{Binding SurveyAnswersCommentForMultipleSelect,  Converter={StaticResource NullToVisibilityConverter}  }">
                            <TextBlock Name="txtTotalResponses" Text="{Binding SurveyAnswersCommentForMultipleSelect}"  Width="1200" TextWrapping="Wrap"
                                                            Grid.Column="1"  FontWeight="Regular"  FontSize="13"
                                                            HorizontalAlignment="Left" VerticalAlignment="Center"  Margin="40,0,0,10"  />
                            </StackPanel>
                    </StackPanel>
                </DataTemplate>
                 
                <DataTemplate x:Key="FreeTextTemplate">
                    <Border BorderThickness="0" BorderBrush="Black" Margin="35,0,0,0" Padding="4">
                        <StackPanel Orientation="Horizontal" >
                            <TextBlock Text="{Binding SrvyAnswer.SelectedAnswer}" IsEnabled="False" Height="Auto" Width="1400"  TextWrapping="Wrap" FontSize="13"  />
                        </StackPanel>
                    </Border>
                </DataTemplate>
                 
                <DataTemplate x:Key="RankingTemplate">
                    <telerik:RadListBox ItemsSource="{Binding SurveyQuestionAnswers}" VerticalAlignment="Top"
                            ItemTemplate="{StaticResource SurveyQuestionsRankingDataTemplate}" />
                </DataTemplate>
 
                <SurveyConverter:SurveyQuestionTypeConverter x:Key="sqtconverter" />
 
                <SurveyTemplateRules:ConditionalDataTemplateSelector x:Key="selector"
                                                  ConditionConverter="{StaticResource sqtconverter}">
                    <SurveyTemplateRules:ConditionalDataTemplateSelector.Rules>
                        <SurveyTemplateRules:ConditionalDataTemplateRule DataTemplate="{StaticResource YesNoTemplate}">
                            <SurveyTemplateRules:ConditionalDataTemplateRule.Value>
                                <sys:Int32>1</sys:Int32>
                            </SurveyTemplateRules:ConditionalDataTemplateRule.Value>
                        </SurveyTemplateRules:ConditionalDataTemplateRule>
                        <SurveyTemplateRules:ConditionalDataTemplateRule DataTemplate="{StaticResource MultipleChoiceTemplate}">
                            <SurveyTemplateRules:ConditionalDataTemplateRule.Value>
                                <sys:Int32>2</sys:Int32>
                            </SurveyTemplateRules:ConditionalDataTemplateRule.Value>
                        </SurveyTemplateRules:ConditionalDataTemplateRule>
                        <SurveyTemplateRules:ConditionalDataTemplateRule DataTemplate="{StaticResource MultipleSelectTemplate}">
                            <SurveyTemplateRules:ConditionalDataTemplateRule.Value>
                                <sys:Int32>3</sys:Int32>
                            </SurveyTemplateRules:ConditionalDataTemplateRule.Value>
                        </SurveyTemplateRules:ConditionalDataTemplateRule>
                        <SurveyTemplateRules:ConditionalDataTemplateRule DataTemplate="{StaticResource FreeTextTemplate}">
                            <SurveyTemplateRules:ConditionalDataTemplateRule.Value>
                                <sys:Int32>4</sys:Int32>
                            </SurveyTemplateRules:ConditionalDataTemplateRule.Value>
                        </SurveyTemplateRules:ConditionalDataTemplateRule>
                        <SurveyTemplateRules:ConditionalDataTemplateRule DataTemplate="{StaticResource RankingTemplate}">
                            <SurveyTemplateRules:ConditionalDataTemplateRule.Value>
                                <sys:Int32>5</sys:Int32>
                            </SurveyTemplateRules:ConditionalDataTemplateRule.Value>
                        </SurveyTemplateRules:ConditionalDataTemplateRule>
                    </SurveyTemplateRules:ConditionalDataTemplateSelector.Rules>
                </SurveyTemplateRules:ConditionalDataTemplateSelector>
                 
                <DataTemplate x:Key="RowDetailsTemplateForQuestions">
                    <telerik:RadGridView Name="surveyQuestionsGrid"
                                 ItemsSource="{Binding SurveyQuestions}"
                                        AutoGenerateColumns="False"
                                        IsReadOnly="True"
                                        ShowColumnSortIndexes="False"
                                        CanUserDeleteRows="False"
                                        CanUserInsertRows="False"
                                        CanUserSortColumns="False"
                                        CanUserFreezeColumns="False"
                                        CanUserGroupColumns="False"
                                        CanUserSelect="False"
                                        CanUserSortGroups="False"
                                        ShowGroupPanel="False"
                                        ShowColumnHeaders="False"
                                        GroupRenderMode="Flat"
                                        CanUserSelectColumns="False"
                                        GridLinesVisibility="None"
                                        RowIndicatorVisibility ="Collapsed"
                                        BorderBrush="White"                                           
                                        ScrollViewer.HorizontalScrollBarVisibility="Visible"
                                        ScrollViewer.VerticalScrollBarVisibility="Visible" 
                                        ScrollViewer.CanContentScroll="True"
                                        RowDetailsTemplateSelector="{StaticResource selector}"
                                        RowDetailsVisibilityMode="Visible">
                        <telerik:RadGridView.Columns>
                            <telerik:GridViewDataColumn  Width="Auto">
                                <telerik:GridViewDataColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding SortOrder}" HorizontalAlignment="Right" VerticalAlignment="Top"  Height="Auto" FontWeight="Bold" TextWrapping="Wrap"  />
                                        <!--<Label Content="." HorizontalAlignment="Left" VerticalAlignment="Top"  Height="Auto" FontWeight="Bold"/>-->
                                    </DataTemplate>
                                </telerik:GridViewDataColumn.CellTemplate>
                            </telerik:GridViewDataColumn>
                            <telerik:GridViewDataColumn  Width="Auto">
                                <telerik:GridViewDataColumn.CellTemplate>
                                    <DataTemplate >
                                        <TextBlock Text="{Binding QuestionText}"  HorizontalAlignment="Left" VerticalAlignment="Top"  Height="Auto" FontWeight="Bold"  Width="1700" TextWrapping="Wrap"  />
                                        <!--<TextBlock TextAlignment="Left" TextWrapping="Wrap" Width="1700"  Text="{Binding QuestionText}" FontWeight="Bold"  Margin="0,10,0,10" ></TextBlock>-->
                                    </DataTemplate>
                                </telerik:GridViewDataColumn.CellTemplate>
                            </telerik:GridViewDataColumn>
                        </telerik:RadGridView.Columns>
                    </telerik:RadGridView>
                </DataTemplate>
 
            </Grid.Resources>
 
 
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,10,0,0" Grid.Row="1">
                <TextBlock Text="View Details Sort by Jurisdiction - " Grid.Row="0"  FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="14" FontFamily="Segoe UI Semibold" />
                <TextBlock Text="{Binding SurveyTitle}" Grid.Row="0"  FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="14" FontFamily="Segoe UI Semibold" />
            </StackPanel>
             
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0,10,0,0" Grid.Row="2" Width="Auto">
                <telerik:RadButton Content="Back To Survey Search" Width="150" Height="25"  Grid.Row="0"  HorizontalAlignment="Left"
                                        Margin="5 0 0 5" CornerRadius="10"
                                         Cursor="Hand"
                                        Command="{Binding BackToSurveySearch}">
 
                    <ToolTipService.ToolTip>
                        <ToolTip Content="Back to Survey Search" />
                    </ToolTipService.ToolTip>
                </telerik:RadButton>
                <telerik:RadButton Content="Aggregate Results" Width="170" Height="25"  Grid.Row="0"  HorizontalAlignment="Left"
                                        Margin="10 0 0 5" CornerRadius="10"
                                         Cursor="Hand"
                                        Command="{Binding AggregateResults}">
 
                    <ToolTipService.ToolTip>
                        <ToolTip Content="Aggregate Results" />
                    </ToolTipService.ToolTip>
                </telerik:RadButton>
                <telerik:RadButton Content="Details Sorted by Question" Width="170" Height="25"  Grid.Row="0"  HorizontalAlignment="Left"
                                        Margin="10 0 0 5" CornerRadius="10"
                                         Cursor="Hand"
                                        Command="{Binding DetailsSortedByQuestion}">
 
                    <ToolTipService.ToolTip>
                        <ToolTip Content="View all details Sorted by Question" />
                    </ToolTipService.ToolTip>
                </telerik:RadButton>
 
            </StackPanel>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,10,0,0" Grid.Row="3">
                <TextBlock Text="Sort by Jurisdiction - " Grid.Row="0"  FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="12" FontFamily="Segoe UI Semibold" />
                <telerik:RadComboBox x:Name="radComboBoxJurisdictionOptions"
                                                 Width="220"  VerticalAlignment="Center" SelectedIndex="0"
                                                 SelectedValuePath="StateCode"
                                                 DisplayMemberPath="StateName"
                                                 Height="25"
                                                 ItemsSource="{Binding Jurisdictions}"
                                                 SelectedValue="{Binding SelectedJurisdictionCode}"
                                                 SelectedItem="{Binding SelectedSurveyJurisdiction}"
                                                 Command="{Binding ChangeJurisdictionCommand}"
                                                 CommandParameter="{Binding Path=SelectedItem, ElementName=radComboBoxJurisdictionOptions }"
                                                 AllowMultipleSelection="False"/>                   
            </StackPanel>
 
 
            <StackPanel Orientation="Horizontal" Margin="0,10,0,10" Width="Auto"  Grid.Row="4">
                    <telerik:RadGridView  x:Name="rgvResponses" Width="Auto"
 
                                        ItemsSource="{Binding SurveyResponses}"
                                        AutoGenerateColumns="False"
                                        IsReadOnly="True"
                                        ShowColumnSortIndexes="False"
                                        CanUserDeleteRows="False"
                                        CanUserInsertRows="False"
                                        CanUserSortColumns="False"
                                        CanUserFreezeColumns="False"
                                        CanUserGroupColumns="False"
                                        CanUserSelect="False"
                                        CanUserSortGroups="False"
                                        ShowGroupPanel="False"
                                        ShowColumnHeaders="False"
                                        GroupRenderMode="Flat"
                                        CanUserSelectColumns="False"
                                        GridLinesVisibility="None"
                                        RowIndicatorVisibility ="Collapsed"
                                        BorderBrush="White"
                                        AlternationCount="1"
                                        AlternateRowBackground="LightGray"
                                        ScrollViewer.VerticalScrollBarVisibility="Visible"
                                        RowDetailsTemplate="{StaticResource RowDetailsTemplateForQuestions}"
                                        RowDetailsVisibilityMode="Visible">
                        <telerik:RadGridView.Columns>
                            <telerik:GridViewDataColumn  Width="Auto">
                                <telerik:GridViewDataColumn.CellTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Vertical" Margin="10,10,10,10">
                                            <StackPanel Orientation="Horizontal">
                                                <telerik:Label Content="Name:"  FontWeight="Bold" Grid.Row="1" Grid.Column="0" Margin="0,0,5,0" HorizontalContentAlignment="Right" HorizontalAlignment="Right" VerticalAlignment="Center" Width="150" />
                                                <telerik:Label Name="txtAuthor" Content="{Binding FullName, Mode=OneWay}" Grid.Column="1" Grid.Row="0" FontWeight="Regular" HorizontalAlignment="Left" VerticalAlignment="Center"  Width="Auto"  />
                                            </StackPanel>
                                            <StackPanel Orientation="Horizontal">
                                                 <telerik:Label Content="Attachment:"  FontWeight="Bold" Grid.Row="2" Grid.Column="0" Margin="0,0,5,0" HorizontalContentAlignment="Right" HorizontalAlignment="Right" VerticalAlignment="Center" Width="150" />
                                                 <TextBlock Grid.Column="1" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Center"  Width="Auto">
                                                    <Hyperlink Command="{Binding OpenAttachmentCommand}" CommandParameter="{Binding SurveyID}" >
                                                        <TextBlock Text="{Binding FileName, Mode=OneWay}" FontWeight="Regular" ></TextBlock>
                                                    </Hyperlink>
                                                </TextBlock>
                                            </StackPanel>
                                            <StackPanel Orientation="Horizontal">
                                                <telerik:Label Content="Contact Info/Comments:"  FontWeight="Bold"  Grid.Row="3" Grid.Column="0" Margin="0,0,5,0" HorizontalAlignment="Right" VerticalAlignment="Top"  Width="150"/>
                                                <TextBlock  Grid.Row="2" Grid.Column="1" Text="{Binding Comments, Mode=OneWay}"  Margin="0,0,5,0"  TextWrapping="Wrap"  Height="Auto" Width="Auto" FontWeight="Regular"
                                                              HorizontalAlignment="Left" VerticalAlignment="Center"/>
                                            </StackPanel>
                                            <StackPanel Orientation="Horizontal">
                                            <telerik:Label Content="Jurisdiction:"  FontWeight="Bold" Grid.Row="4" Grid.Column="0" Margin="0,0,5,0"  HorizontalContentAlignment="Right" HorizontalAlignment="Right" VerticalAlignment="Center"  Width="150" />
                                                <telerik:Label  Name="txtJurisdiction" Content="{Binding Jurisdiction, Mode=OneWay}"  Grid.Row="3" Grid.Column="1" FontWeight="Regular" HorizontalAlignment="Left" VerticalAlignment="Center" Width="Auto"/>
                                            </StackPanel>
                                        </StackPanel>
                                    </DataTemplate>
                                </telerik:GridViewDataColumn.CellTemplate>
                            </telerik:GridViewDataColumn>
                        </telerik:RadGridView.Columns>
                 </telerik:RadGridView>
 
            </StackPanel>
            <StackPanel Grid.Row="5" Width="Auto" >
            <telerik:RadDataPager x:Name="radDataPager"
                            PageSize="1"
                            IsTotalItemCountFixed="True"
                            DisplayMode="All"
                           ScrollViewer.VerticalScrollBarVisibility="Visible"
                            FontSize="12"
                            AutoEllipsisMode="Both"
                            NumericButtonCount="10"
                            Margin="0,10,0,0"
                            Style="{StaticResource RadDataPagerStyle1}"
                            Source="{Binding Items, ElementName=rgvResponses}" />
            </StackPanel>
        </Grid>
    </Border>
</Grid>

 

ViewModel:

namespace .Survey.ViewModels
{
 
     
    public class SortByJurisdictionViewModel : BindableBase, INavigationAware
    {
        private IEventAggregator _eventAggregator;
        private ILogger _logger;
        private IRegionManager _regionManager;
        private SurveyDB _surveyDB;
        private SurveyService _surveyService;
        public DelegateCommand<object> BackToSurveySearch { get; private set; }
        public DelegateCommand<object> DetailsSortedByQuestion { get; private set; }
        public DelegateCommand<object> AggregateResults { get; private set; }
        public DelegateCommand<object> OpenAttachmentCommand { get; private set; }
 
 
        #region Page Properties
 
        private int _surveyID;
        public int SurveyID
        {
            set
            {
                _surveyID = value;
                RaisePropertyChanged("SurveyID");
            }
            get
            {
                return _surveyID;
            }
        }
 
        private string _surveyTitle;
        public string SurveyTitle
        {
            set
            {
                _surveyTitle = value;
                RaisePropertyChanged("SurveyTitle");
            }
            get
            {
                return _surveyTitle;
            }
        }
 
        public SurveyResponse _surveyResponseItems;
        public SurveyResponse SurveyResponseItems
        {
            get
            {
                return _surveyResponseItems;
            }
            set
            {
                _surveyResponseItems = value;
                RaisePropertyChanged("SurveyResponseItems");
            }
        }
 
 
        public ObservableCollection<SurveyResponse> _surveyResponses { set; get; }
        public ObservableCollection<SurveyResponse> SurveyResponses
        {
            set
            {
                _surveyResponses = value;
                RaisePropertyChanged("SurveyResponses");
            }
            get
            {
                return _surveyResponses;
            }
        }
        public ObservableCollection<SurveyQuestion> _surveyQuestions { set; get; }
        public ObservableCollection<SurveyQuestion> SurveyQuestions
        {
            set
            {
                _surveyQuestions = value;
                RaisePropertyChanged("SurveyQuestions");
            }
            get
            {
                return _surveyQuestions;
            }
        }
 
        List<SurveyJurisdiction> _jurisdictions;
        public List<SurveyJurisdiction> Jurisdictions
        {
            get
            {
                return this._jurisdictions;
            }
            set
            {
                _jurisdictions = value;
                RaisePropertyChanged("Jurisdictions");
            }
        }
        private SurveyJurisdiction _selectedSurveyJurisdiction;
        public SurveyJurisdiction SelectedSurveyJurisdiction
        {
            set
            {
                _selectedSurveyJurisdiction = value;
                RaisePropertyChanged("SelectedSurveyJurisdiction");
            }
            get
            {
                return _selectedSurveyJurisdiction;
            }
        }
 
        private ICommand changeJurisdictionCommand = null;
 
        public ICommand ChangeJurisdictionCommand
        {
            get
            {
                return this.changeJurisdictionCommand;
            }
            set
            {
                if (this.changeJurisdictionCommand != value)
                {
                    this.changeJurisdictionCommand = value;
                    RaisePropertyChanged("ChangeJurisdictionCommand");
                }
            }
        }
 
 
        #endregion
 
        public SortByJurisdictionViewModel(ILogger logger, SurveyDB survey, IEventAggregator ea, SurveyService surveyService, NetForumCore netForumCoreDB, IRegionManager rm)
        {
            _logger = logger;
            _eventAggregator = ea;
            _surveyDB = survey;
            _regionManager = rm;
            _netForumCoreDB = netForumCoreDB;
            _surveyService = surveyService;
 
            _eventAggregator.GetEvent<AppEnvironmentChange>().Subscribe(OnEnvironmentChange);
            BackToSurveySearch = new DelegateCommand<object>(LaunchSurveySearch);
            DetailsSortedByQuestion = new DelegateCommand<object>(LaunchDetailsSortedByQuestion);
            AggregateResults = new DelegateCommand<object>(LaunchAggregateResults);
            OpenAttachmentCommand = new DelegateCommand<object>(OnClickOpenAttachmentCommand);
 
            this.ChangeJurisdictionCommand = new Telerik.Windows.Controls.DelegateCommand(this.OnJurisdictionChanged);
        }
 
        private void OnClickOpenAttachmentCommand(object param)
        {
 
            string url = "https://xxx.xxx.org/Survey/User/FileDetail.aspx?SurveyFile=" + param;
            Utility.OpenExternalLink(url);
 
        }
 
        private void OnJurisdictionChanged(object param)
        {
            var sj = param as SurveyJurisdiction;
            LoadRecordsForJurisdiction(sj);
        }
 
        private void LoadRecordsForJurisdiction(SurveyJurisdiction sj)
        {
            if(sj != null) GetSurveyResponses(_logger, SurveyID,sj.StateCode, -1);
        }
        private void LaunchDetailsSortedByQuestion(object obj)
        {
            var uri = new Uri("SortByQuestion", UriKind.RelativeOrAbsolute);
            NavigationParameters p = new NavigationParameters();
            p.Add("SurveyID", SurveyID);
            p.Add("SurveyTitle", SurveyTitle);
            _regionManager.RequestNavigate(SurveyModule.ContentRegionName, uri, p);
        }
 
        private void LaunchAggregateResults(object obj)
        {
            var uri = new Uri("AggregateResults", UriKind.RelativeOrAbsolute);
            NavigationParameters p = new NavigationParameters();
            p.Add("SurveyID", SurveyID);
            p.Add("SurveyTitle", SurveyTitle);
            _regionManager.RequestNavigate(SurveyModule.ContentRegionName, uri, p);
        }
 
        private void LaunchSurveySearch(object obj)
        {
            var uri = new Uri("SurveySearch", UriKind.RelativeOrAbsolute);
            _regionManager.RequestNavigate("ContentRegion", uri);
        }
 
        private void OnEnvironmentChange(Environments obj)
        {
            // GetRecords();
            RaisePropertyChanged(); // broadcast full refresh
        }
 
        #region navigation methods
        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            var surveyID = navigationContext.Parameters["SurveyID"];
            var title = navigationContext.Parameters["SurveyTitle"];
 
            _surveyID = UConvert.ConvertToInt32(surveyID);
            _surveyTitle  = UConvert.ConvertToString(title);
            RaisePropertyChanged("SurveyTitle");
            GetSurveyResponses(_logger, SurveyID, string.Empty, -1);
            FillJurisdictionsDropDown();
        }
 
 
        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return true;
        }
 
        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
        }
 
        #endregion
 
        private void FillJurisdictionsDropDown()
        {
 
                this._jurisdictions = _surveyService.GetAllJurisdictions(_logger, _netForumCoreDB);
                // Remove states not in responses
                List<SurveyJurisdiction> removeRows = new List<SurveyJurisdiction>();
                foreach (SurveyJurisdiction s in _jurisdictions)
                {
                    string jur = UConvert.ConvertToString(s.StateCode);
                    if (GetSurveyResponsesCount(SurveyID, jur) == 0)
                    {
                        removeRows.Add(s);
                    }
                }
 
                foreach (SurveyJurisdiction surj in removeRows)
                {
                    _jurisdictions.Remove(surj);
                }
 
                SurveyJurisdiction sj = new SurveyJurisdiction();
                sj.StateCode = sj.StateName = sj.StateKey = "";
                _jurisdictions.Insert(0, sj);
 
                Jurisdictions = _jurisdictions;
                RaisePropertyChanged("Jurisdictions");
 
        }
 
 
        public int GetSurveyResponsesCount(int surveyID, string Juris)
        {
            DataTable dt = _surveyDB.GetSurveyResponses(SurveyID, Juris);
            if (dt != null)
            {
                return dt.Rows.Count;
            }
            return -1;
        }
 
        public void GetSurveyResponses(ILogger ilogger, int surveyID, string Juris, int SurveyResponseID)
        {
            ObservableCollection<SurveyResponse> surveyResponseItems = new ObservableCollection<SurveyResponse>();
            DataTable dt = _surveyDB.GetSurveyResponses(SurveyID, Juris);
            try
            {
                if (dt != null)
                {
                    if ((dt.Rows.Count > 0))
                    {
                        foreach (DataRow row in dt.Rows)
                        {
                            SurveyResponse sItem = new SurveyResponse(ilogger, _surveyDB);
 
                            sItem.SurveyID = UConvert.ConvertToInt32(row["SurveyID"]);
                            sItem.SurveyResponseID = UConvert.ConvertToInt32(row["SurveyResponseID"]);
                            sItem.Deleted = UConvert.ConvertToInt32(row["Deleted"]);
 
                            sItem.ResponseDate = UConvert.ConvertToDateTime(row["ResponseDate"]);
                            sItem.FullName = UConvert.ConvertToString(row["FullName"]);
 
                            if(string.IsNullOrEmpty(sItem.FullName) )
                                sItem.FullName = "Anonymous";
 
                            sItem.UserName = UConvert.ConvertToString(row["UserName"]);
                            sItem.Jurisdiction = UConvert.ConvertToString(row["Jurisdiction"]);
                            sItem.Comments = UConvert.ConvertToString(row["Comments"]).Trim();
 
                            if (row["FileImage"] != DBNull.Value)
                            {
 
                                if (row["FileName"] != null && (Convert.ToString(row["FileName"]).Trim() != string.Empty))
                                    sItem.FileName = Convert.ToString(row["FileName"]);
                                sItem.FileType = Convert.ToString(row["FileType"]);
 
                                sItem.FileSize = UConvert.ConvertToInt32(row["FileSize"]);
                                sItem.FileImage = Convert.ToString(row["FileImage"]);
                            }
 
                            sItem.SurveyQuestions = GetSurveyQuestions(ilogger, sItem.SurveyID, sItem.SurveyResponseID);
                           // sItem.SurveyQuestionAnswers = GetQuestionAnswers(sItem.SurveyQuestionID);
 
 
                            surveyResponseItems.Add(sItem);
                        }
                        SurveyResponses = surveyResponseItems;
 
                    }
                }
            }
            catch (Exception ex)
            {
                _logger?.LogError($"Failed during GetSurveyResponses method {ex.Message}");
                throw;
            }
        }
 
        public ObservableCollection<SurveyQuestion> GetSurveyQuestions(ILogger ilogger, int surveyID, int surveyResponseID)
        {
            ObservableCollection<SurveyQuestion> surveyQuestions = new ObservableCollection<SurveyQuestion>();
 
            DataTable dsQuestions = _surveyDB.GetQuestions(surveyID);
 
            if (dsQuestions != null)
            {
                if (dsQuestions != null && dsQuestions.Rows.Count > 0)
                {
                    foreach (DataRow row in dsQuestions.Rows)
                    {
                        SurveyQuestion sq = new SurveyQuestion(ilogger, _surveyDB);
                        sq.SortOrder = UConvert.ConvertToInt32(row["SortOrder"]);
                        sq.SurveyQuestionID = UConvert.ConvertToInt32(row["SurveyQuestionID"]);
                        sq.SurveyQuestionTypeID = UConvert.ConvertToInt32(row["SurveyQuestionTypeID"]);
                        sq.SurveyID = UConvert.ConvertToInt32(row["SurveyID"]);
                        sq.AllowComment = UConvert.ConvertToBoolean(row["AllowComment"]);
                        sq.QuestionText = UConvert.ConvertToString(row["QuestionText"]);
 
                        if (sq.SurveyQuestionTypeID == 3)
                        {
                            sq.SurveyAnswers = GetSurveyAnswersForMultipleSelect(surveyResponseID, sq.SurveyQuestionID);
                            foreach (var answer in sq.SurveyAnswers)
                            {
                                //iterate only one record as all field values for comments are same
                                sq.SurveyAnswersCommentForMultipleSelect = answer.Comments;
                                break;
                            }
                                 
                            sq.SurveyQuestionAnswers = GetQuestionAnswers(sq.SurveyQuestionID, sq.SurveyAnswers); //choices
                        }
                        else
                        {
                            sq.SrvyAnswer = GetSurveyAnswer(surveyResponseID, sq.SurveyQuestionID);
                            sq.SurveyQuestionAnswers = GetQuestionAnswers(sq.SurveyQuestionID, sq.SrvyAnswer); //choices
                        }
 
 
                        surveyQuestions.Add(sq);
                    }
                }
            }
 
            return surveyQuestions;
        }
 
        public ObservableCollection<SurveyQuestionAnswer> GetQuestionAnswers(int surveyQuestionID , SurveyAnswer surveyAnswer) //, int surveyQuestionTypeID)
        {
            DataTable dtSurveyQuestionChoices = null;
            ObservableCollection<SurveyQuestionAnswer> surveyQuestionnAnswers = new ObservableCollection<SurveyQuestionAnswer>();
            try
            {
                dtSurveyQuestionChoices = _surveyDB.GetQuestionAnswers(_logger, surveyQuestionID);
                if (dtSurveyQuestionChoices != null && dtSurveyQuestionChoices.Rows.Count > 0)
                {
                    foreach (DataRow row in dtSurveyQuestionChoices.Rows)
                    {
                        SurveyQuestionAnswer surveyQuestionAnswer = new SurveyQuestionAnswer(_logger, _surveyDB);
                        surveyQuestionAnswer.SurveyChoiceText = UConvert.ConvertToString(row["SurveyChoiceText"]);
                        surveyQuestionAnswer.SurveyChoiceID = UConvert.ConvertToInt32(row["SurveyChoiceID"]);
                        surveyQuestionAnswer.SortOrder = UConvert.ConvertToInt32(row["SortOrder"]);
                        surveyQuestionAnswer.SurveyQuestionID = UConvert.ConvertToInt32(row["SurveyQuestionID"]);
                        surveyQuestionAnswer.IsChecked =  (surveyAnswer.SelectedAnswerValue.Equals(surveyQuestionAnswer.SurveyChoiceID))?  true : false;
 
                        surveyQuestionnAnswers.Add(surveyQuestionAnswer);
                    }
                }
            }
            catch
            {
                throw;
            }
            return surveyQuestionnAnswers;
        }
 
        public ObservableCollection<SurveyQuestionAnswer> GetQuestionAnswers(int surveyQuestionID, ObservableCollection<SurveyAnswer> surveyAnswers) //, int surveyQuestionTypeID)
        {
            DataTable dtSurveyQuestionChoices = null;
            ObservableCollection<SurveyQuestionAnswer> surveyQuestionnAnswers = new ObservableCollection<SurveyQuestionAnswer>();
            try
            {
                dtSurveyQuestionChoices = _surveyDB.GetQuestionAnswers(_logger, surveyQuestionID);
                if (dtSurveyQuestionChoices != null && dtSurveyQuestionChoices.Rows.Count > 0)
                {
                    foreach (DataRow row in dtSurveyQuestionChoices.Rows)
                    {
                        SurveyQuestionAnswer surveyQuestionAnswer = new SurveyQuestionAnswer(_logger, _surveyDB);
                        surveyQuestionAnswer.SurveyChoiceText = UConvert.ConvertToString(row["SurveyChoiceText"]);
                        surveyQuestionAnswer.SurveyChoiceID = UConvert.ConvertToInt32(row["SurveyChoiceID"]);
                        surveyQuestionAnswer.SortOrder = UConvert.ConvertToInt32(row["SortOrder"]);
                        surveyQuestionAnswer.SurveyQuestionID = UConvert.ConvertToInt32(row["SurveyQuestionID"]);
                        foreach (var answer in surveyAnswers)
                        {
                            if (answer.SelectedAnswerValue.Equals(surveyQuestionAnswer.SurveyChoiceID))
                            {
                                surveyQuestionAnswer.IsChecked = true;
                                break;
                            }
                            else
                            {
                                surveyQuestionAnswer.IsChecked = false;
                            }
                        }
 
                        surveyQuestionnAnswers.Add(surveyQuestionAnswer);
                    }
                }
            }
            catch
            {
                throw;
            }
            return surveyQuestionnAnswers;
        }
 
        public ObservableCollection<SurveyAnswer>  GetSurveyAnswersForMultipleSelect(int surveyResponseID, int surveyQuestionID) //, int surveyQuestionTypeID)
        {
            DataTable dtSurveyAnswers = null;
            ObservableCollection<SurveyAnswer>   surveyAnswers = new ObservableCollection<SurveyAnswer>();
            try
            {
                dtSurveyAnswers = _surveyDB.GetSurveyAnswer(_logger, surveyResponseID, surveyQuestionID);
                if (dtSurveyAnswers != null && dtSurveyAnswers.Rows.Count > 0)
                {
                    foreach (DataRow row in dtSurveyAnswers.Rows)
                    {
                        SurveyAnswer surveyAnswer = new SurveyAnswer(_logger, _surveyDB);
 
                        surveyAnswer.SurveyAnswerID = UConvert.ConvertToInt32(row["SurveyAnswerID"]);
                        surveyAnswer.SurveyResponseID = UConvert.ConvertToInt32(row["SurveyResponseID"]);
                        surveyAnswer.SurveyQuestionID = UConvert.ConvertToInt32(row["SurveyQuestionID"]);
                        surveyAnswer.Comments = UConvert.ConvertToString(row["Comments"]);
                        surveyAnswer.SelectedAnswer = UConvert.ConvertToString(row["SelectedAnswer"]);
                        surveyAnswer.SelectedAnswerValue = UConvert.ConvertToInt32(row["SelectedAnswerValue"]);
 
                        surveyAnswers.Add(surveyAnswer);
                    }
                }
            }
            catch
            {
                throw;
            }
            return surveyAnswers;
        }
 
        public SurveyAnswer GetSurveyAnswer(int surveyResponseID, int surveyQuestionID) //, int surveyQuestionTypeID)
        {
            DataTable dtSurveyAnswers = null;
            SurveyAnswer surveyAnswer = new SurveyAnswer(_logger, _surveyDB);
            try
            {
                dtSurveyAnswers = _surveyDB.GetSurveyAnswer(_logger, surveyResponseID, surveyQuestionID);
                if (dtSurveyAnswers != null && dtSurveyAnswers.Rows.Count > 0)
                {
                    foreach (DataRow row in dtSurveyAnswers.Rows)
                    {
                        surveyAnswer.SurveyAnswerID = UConvert.ConvertToInt32(row["SurveyAnswerID"]);
                        surveyAnswer.SurveyResponseID = UConvert.ConvertToInt32(row["SurveyResponseID"]);
                        surveyAnswer.SurveyQuestionID = UConvert.ConvertToInt32(row["SurveyQuestionID"]);
                        surveyAnswer.Comments = UConvert.ConvertToString(row["Comments"]);
                        surveyAnswer.SelectedAnswer = UConvert.ConvertToString(row["SelectedAnswer"]);
                        surveyAnswer.SelectedAnswerValue = UConvert.ConvertToInt32(row["SelectedAnswerValue"]);
 
                        //For Radio button YES Answer
                        if (surveyAnswer.SelectedAnswerValue == 1)
                            surveyAnswer.IsYesChecked = true;
                        else
                            surveyAnswer.IsYesChecked = false;
                        //For Radio button NO Answer
                        if (surveyAnswer.SelectedAnswerValue == 0)
                            surveyAnswer.IsNoChecked = true;
                        else
                            surveyAnswer.IsNoChecked = false;
                    }
                }
            }
            catch
            {
                throw;
            }
            return surveyAnswer;
        }
 
    }
}

Thanks!

1 Answer, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 12 Sep 2019, 11:53 AM
Hi,

The performance degradation comes from the fact that RadGridView is measured with infinity since it is placed in StackPanel. Please note that when the GridView is measured with infinity, the UI Virtualization does not work.

You can also check the Degraded Performance help article for a reference.

Regards,
Yoan
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
KR
Top achievements
Rank 1
Veteran
Answers by
Yoan
Telerik team
Share this question
or