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

Abnormal behaviour of Radgrid when using VirtualQueryableCollectionView

0 Answers 145 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ram
Top achievements
Rank 1
Ram asked on 05 Oct 2011, 01:38 PM
Hello,

   I'm using the telerik Radgrid in our project, which is used to display search result of data having more than 20000 rows and the data rebind to the grid every time the user change the search criteria and click on search button.

As the data binded to the grid is too much, I have implemented VirtualQueryableCollectionView, to overcome the performance issues while loading.

Everything works fine, when the grid get loaded for the first time, but after loading if I scroll down to some far point let's say in middle
and never move the scroller again and search again by changing the search criteria (which will return the less no. of rows for eg. 5 or 6)
then in that case the ItemsLoading event of VirtualQueryableCollectionView fires and even the data loads to the grid but the rows are not visible to the user, it seems as if no data has been loaded in the grid.

But actually the data got binded, and if I use my mouse cursor to scroll (though their is no scroll bar) the rows become visible and which seems to be abnormal behavior of the grid.

The similar issue is already posted in the forum, but in that thread their is no response from the Telerik Team for solution. ( Link for Ref. http://www.telerik.com/community/forums/wpf/gridview/radgridview-with-virtualqueryablecollectionview-loaded-via-wcf-problem.aspx )

I have added code snippets for your reference, showing how I am defining the grid and binding it.

Please revert back as soon as possible.

Thanks
Ramnadh
///This is the xaml code for defining the grid columns and style for List View
 
<telerik:RadBusyIndicator DisplayAfter="0"  x:Name="radBusyIndicator" Background="Transparent" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" >
                    <telerik:RadGridView Name="grid" IsReadOnly="True" CanUserDeleteRows="False" CanUserInsertRows="False" CanUserSortColumns="False" ColumnWidth="*" Height="Auto" Width="Auto" ItemsSource="{Binding}" >
                        <telerik:RadGridView.Columns>
                            <telerik:GridViewDataColumn Name="agentCodeCol"  DataMemberBinding="{Binding AgentCode}" HeaderTextAlignment="Right" TextAlignment="Right" Header="Agent Code" />
                            <telerik:GridViewDataColumn Name="lastNameCol" DataMemberBinding="{Binding LastName}" Header="Last Name" />
                            <telerik:GridViewDataColumn Name="firstNameCol" DataMemberBinding="{Binding FirstName}" Header="First Name" />
                            <telerik:GridViewDataColumn Name="cityCol" DataMemberBinding="{Binding city}" Header="City" />
                            <telerik:GridViewDataColumn Name="stateCol" DataMemberBinding="{Binding StateCode}" Header="State" />
                            <telerik:GridViewDataColumn Name="zipCol" DataMemberBinding="{Binding Zip}" Header="ZIP" TextAlignment="Right" HeaderTextAlignment="Right" />
                            
                            <telerik:GridViewDataColumn Name="editProfileCol" Header="Edit Profile" HeaderTextAlignment="Center" >
                                <telerik:GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Button x:Name="editProfileBtn" Content="Edit"  Click="OnEditProfileBtnClick" Width="70" Height="16" />
                                    </DataTemplate>
                                </telerik:GridViewColumn.CellTemplate>
                            </telerik:GridViewDataColumn>
                            <telerik:GridViewDataColumn Name="swapInCol" Header="Swap In" >
                                <telerik:GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Button Content="Swap In" Style="{StaticResource buttonStyle}" Click="OnSwapInBtnClick" Width="70" Height="16"/>
                                    </DataTemplate>
                                </telerik:GridViewColumn.CellTemplate>
                            </telerik:GridViewDataColumn>
                        </telerik:RadGridView.Columns>
                    </telerik:RadGridView>
                </telerik:RadBusyIndicator>
 
 
<Style x:Key="lvStyle" TargetType="{x:Type ListView}">
            <Setter Property="VirtualizingStackPanel.IsVirtualizing" Value="True"/>
            <Setter Property="VirtualizingStackPanel.VirtualizationMode" Value="Recycling"/>
            <Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="True"/>
            <Setter Property="ListView.ItemsSource" Value="{Binding}"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsLoading}" Value="True">
                    <Setter Property="ListView.Cursor" Value="Wait"/>
                    <Setter Property="ListView.Background" Value="LightGray"/>
                </DataTrigger>
            </Style.Triggers>
 </Style>
 
 
//Code for binding the grid using VirtualQueryableCollectionView
 
DataTable totalRowCountDT = searchResDS.Tables[0];   //Getting the table from Database
                    if (totalRowCountDT != null && totalRowCountDT.Rows.Count > 0 && totalRowCountDT.Rows[0][0] != DBNull.Value) {
                        int numItems = Convert.ToInt32(totalRowCountDT.Rows[0][0]);
                        AgentProvider agentProvider = new AgentProvider(numItems, 0);
                        var view = new VirtualQueryableCollectionView<Agent>() { LoadSize = 500, VirtualItemCount = agentProvider.FetchCount() };
                        view.ItemsLoading += (s, args) => {
                            ShowOrHideProgressBar(true);
                            view.Load(args.StartIndex, agentProvider.FetchRange(args.StartIndex, args.ItemCount));
                            ShowOrHideProgressBar(false);
 
                                                                                
                        };
                        
                        grid.DataContext = view;
 
 
//Method to show and hide the RadBusyIndicator
 public void ShowOrHideProgressBar(bool showOrHide) {
            this.radBusyIndicator.IsBusy = showOrHide;
        }
 
 
//Class to provide data for Grid to while scrolling
   
 public class AgentProvider : IItemsProvider<Agent> {
        private readonly int _count;
        private readonly int _fetchDelay;
 
        /// <summary>
        /// Initializes a new instance of the <see cref="DemoCustomerProvider"/> class.
        /// </summary>
        /// <param name="count">The count.</param>
        /// <param name="fetchDelay">The fetch delay.</param>
        public AgentProvider(int count, int fetchDelay) {
            _count = count;
            _fetchDelay = fetchDelay;
        }
 
        /// <summary>
        /// Fetches the total number of items available.
        /// </summary>
        /// <returns></returns>
        public int FetchCount() {
            Trace.WriteLine("FetchCount");          
            return _count;
        }
 
        /// <summary>
        /// Fetches a range of items.
        /// </summary>
        /// <param name="startIndex">The start index.</param>
        /// <param name="count">The number of items to fetch.</param>
        /// <returns></returns>
        public IList<Agent> FetchRange(int startIndex, int count) {
            Trace.WriteLine("FetchRange: " + startIndex + "," + count);
            AgentEntity agentEntity = new AgentEntity();
            DataSet searchResDS = agentEntity.GetAllAgentDetails(
                                                                        VirtualizationHelper.AgetStruct.LastName
                                                                   ,    VirtualizationHelper.AgetStruct.FirstName
                                                                   ,    VirtualizationHelper.AgetStruct.AgentCode
                                                                   ,    VirtualizationHelper.AgetStruct.Email
                                                                   ,    VirtualizationHelper.AgetStruct.Phone
                                                                   ,    VirtualizationHelper.AgetStruct.Zip
                                                                   ,    VirtualizationHelper.AgetStruct.StateId
                                                                   ,    VirtualizationHelper.AgetStruct.UserId
                                                                   ,    VirtualizationHelper.AgetStruct.IsCurrentUsrHomeOffUsr
                                                                   ,    startIndex
                                                                   ,    startIndex+count
                                                                   , UserInfo.IsCurrentUserLoggedInUser);
            DataTable agenttDT = searchResDS.Tables[1];
            List<Agent> list = new List<Agent>();
            foreach (DataRow row in agenttDT.Rows) {
                Agent agent = new Agent {
                        AgentCode = Convert.ToString(row["AgentCode"])
                    ,   LastName = Convert.ToString(row["LastName"])
                    ,   FirstName = Convert.ToString(row["FirstName"])
                    ,   city = Convert.ToString(row["city"])
                    ,   StateCode = Convert.ToString(row["StateCode"])
                    ,   Zip = Convert.ToString(row["Zip"])
                    ,   GACode = Convert.ToString(row["GACode"])
                    ,   AgentGuid = Convert.ToString(row["AgentGuid"])
                };
                list.Add(agent);
            }
            return list;
        }
    }


 

No answers yet. Maybe you can help?

Tags
GridView
Asked by
Ram
Top achievements
Rank 1
Share this question
or