Rad Grid View items source not binding / items source is not cleared...

1 posts, 0 answers
  1. Karthik
    Karthik avatar
    10 posts
    Member since:
    Jul 2012

    Posted 28 Jun 2013 Link to this post

    Hello,

    I am using Silverlight Rad GridView, i had two docks panels, one is to display summary and one is to display the details of the orders.
    I have a double click operation on row in the summary and "summary" button in the detail page, on double click of a record it displays the detailed records of that selected order...on summary button click it bring back summary dock...

    when double click and directed to detail page, the detailed data of that order is displayed as expected(say. 50 records)...
    back to summary page is updating the edited records,

    second time if I double click the same product(1), the detailed data is display (say 50 records), but after few seconds the grid is refreshed with all the records of all the orders (say 10,000 records).

    i am using stored procedures to retrieve the data. we check the event log if it is firing the stored procedure after details page, but event log shows one time call, some time the grid is refreshed twice or thrice in some time interval, 
    this issues is not consistent, it is not repeating on every double click... 

    Can anyone please help me out with this issue, thank you very much...
    Cs file:
     
            private void OnCellDoubleClick_Stores(object sender, RadRoutedEventArgs args)
            {
                GridViewCell strCell = args.OriginalSource as GridViewCell;
                if (strCell != null && (strCell.Column.Header.ToString() == "Store ID" || strCell.Column.Header.ToString() == "Store Name" || strCell.Column.Header.ToString() == "Cust Store ID"))
                {
                    storeSummaryViewModel.SelectedProduct = strCell.ParentRow.Item as SummaryByStores;
     
                    string strIds = (strCell.ParentRow.Item as SummaryByStores).StoreId_Xref;
     
                    string plannerIds = (strCell.ParentRow.Item as SummaryByStores).PlannerId;
                     
     
                    orderManagementHeader.Text = strIds + " | " + (strCell.ParentRow.Item as SummaryByStores).StoreName + " | " + (strCell.ParentRow.Item as SummaryByStores).customerStoreID;
                    pfoViewModel.StoreIds = strIds;
                    pfoViewModel.PFODouleClickPlanner = plannerIds;
                    List<string> StoreIds = new List<string>();
                    StoreIds.Add(strIds);
                    foreach (var item in StoreIds)
                    {
                        pfoViewModel.SelectedStoreIds.Add(item);
                    }
                    this.ClickedCell = strCell;
                    grdProducts.Columns["StoreId_XRef"].IsVisible = false;
                    grdProducts.Columns["StoreName"].IsVisible = false;
                    grdProducts.Columns["customerStoreID"].IsVisible = false;
                    grdProducts.Columns["PlanningPolicy"].IsVisible = false;
                    grdProducts.Columns["OrderMultiple"].IsVisible = false;
                    selectedDoubleClickGrid = "Stores";
                    pfoViewModel.PFODouleClick = "Planner";
                    DrillDown();
                    pfoViewModel.PFODouleClick = "Store";
                    pfoViewModel.PFODouleClickStore = strIds;
     
                }
            }
     
     private void DrillDown()
            {
                pfoViewModel.RefreshRecords();
                gridPane.IsSelected = true;
                //btnCustApply.IsEnabled = false;
                //btnStrApply.IsEnabled = false;
                //tbiRefresh.IsEnabled = false;
     
                tbiBackToSummary.Visibility = Visibility.Visible;
                ProductSummarygridPane.Visibility = Visibility.Collapsed;
                SummarygridPane.Visibility = Visibility.Collapsed;
     
                customerfilterPane.IsHidden = true;
                storefilterPane.IsHidden = true;
                bDrillDown = true;
                pfoSlider.Visibility = Visibility.Collapsed;
                tbSlider.Visibility = Visibility.Collapsed;
     
     
            }
     
            private void BackToSummary()
            {
                tbiBackToSummary.Visibility = Visibility.Collapsed;
                //btnCustApply.IsEnabled = true;
                //btnStrApply.IsEnabled = true;
                tbiRefresh.IsEnabled = true;
                pfoViewModel.SelectedProductIds.Clear();
     
                // if (pfoViewModel.PFOSelectByTab != null)
                pfoViewModel.PFODouleClick = "BackToSummary";
     
                //pfoViewModel.SelectedStoreIds.Clear();
     
                if (selectedDoubleClickGrid == "Product")
                {
                    ProductSummarygridPane.IsSelected = true;
                    pfoViewModel.ProductIds = CheckedProductIDs;
     
                    //if (pfoViewModel.PFOSelectByTab == null)
                    //    productSummaryViewModel.GetProductSummary(LoadStoredIds, LoadCustomers, LoadPlannerIds);
     
                    if (pfoViewModel.PFOSelectByTab == "CustomerEdit" || pfoViewModel.PFOSelectByTab == "StoreEdit")
                        productSummaryViewModel.GetProductSummary(ApplyStores, ApplyCustomer, ApplyPlanner);
     
                    grdProducts.Columns["InventoryId"].IsVisible = true;
                    grdProducts.Columns["InventoryDescription"].IsVisible = true;
                    grdProducts.Columns["CustomerItemNum"].IsVisible = true;
     
                    //GridViewRow grsRow = grdProductSummary.SelectedItem as GridViewRow;
                    grdProductSummary.SelectedItem = productSummaryViewModel.SelectedProduct;
     
     
                }
                else if (selectedDoubleClickGrid == "Stores")
                {
                    pfoViewModel.StoreIds = CheckedStoreIDs;
                    SummarygridPane.IsSelected = true;
                    string StoreIds = pfoViewModel.PFODouleClickStore;
                    string planners = pfoViewModel.PFODouleClickPlanner;
     
                    //if (pfoViewModel.PFOSelectByTab == null)
                    //    storeSummaryViewModel.GetStoreSummary(LoadStoredIds, LoadCustomers, LoadPlannerIds);
     
                    if (pfoViewModel.PFOSelectByTab == "CustomerEdit" || pfoViewModel.PFOSelectByTab == "StoreEdit")
                        storeSummaryViewModel.GetStoreSummary(ApplyStores, ApplyCustomer, ApplyPlanner);
     
     
                    // LoadStoreSummary(ApplyStores, ApplyCustomer, ApplyPlanner);
                    grdProducts.Columns["StoreId_XRef"].IsVisible = true;
                    grdProducts.Columns["StoreName"].IsVisible = true;
                    grdProducts.Columns["customerStoreID"].IsVisible = true;
                    //grdProducts.Columns["PlanningPolicy"].IsVisible = true;
                    //grdProducts.Columns["OrderMultiple"].IsVisible = true;
                    //grdProducts.Columns["StoreTier"].IsVisible = true;
                }
                pfoViewModel.RefreshRecords();
     
                orderManagementHeader.Text = ApplicationStrings.OrderGridPanelTitle;
                ProductSummarygridPane.Visibility = Visibility.Visible;
                SummarygridPane.Visibility = Visibility.Visible;
                grdProducts.Columns["PlanningPolicy"].IsVisible = true;
                grdProducts.Columns["OrderMultiple"].IsVisible = true;
                grdProducts.Columns["StoreTier"].IsVisible = true;
                PlannerChecked = false;
                customerfilterPane.IsHidden = false;
                pfoViewModel.CanExecuteEdit = true;
                storefilterPane.IsHidden = false;
                pfoSlider.Visibility = Visibility.Visible;
                tbSlider.Visibility = Visibility.Visible;
                if (pfoViewModel.PFOSelectByTab == "StoreEdit") //pfoViewModel.PFOSelectByTab == "Store" ||
                {
                    storefilterPane.IsSelected = true;
                }
                else if (pfoViewModel.PFOSelectByTab == "CustomerEdit")
                {
                    customerfilterPane.IsSelected = true;
                }
     
                //bDrillDown = false;
                //List<SummaryByProducts> lst = new List<SummaryByProducts>();
                //lst.Add(productSummaryViewModel.SelectedProduct);
                //productSummaryViewModel.AddPFOsToSelected(lst);
     
                //customerfilterPane.Visibility = Visibility.Visible;
                //storefilterPane.Visibility = Visibility.Visible;
            }
     
     
    ViewModel:
     
     
          
      
     
            public string ApplyCustomer { get; set; }
            public string ApplyStores { get; set; }
            public string ApplyPlanner { get; set; }
     
      
     
     
            /// <summary>
            /// Page (Current)
            /// Used by OrderPager_PageIndexChanged
            /// </summary>
            public int Page
            {
                get { return pageCurrent; }
                set
                {
                    //if (pageCurrent == value)
                    //    return;
                   
                        pageCurrent = value;
                        RaisePropertyChanged("Page");
                        // Re-load...
                        RefreshRecords();
                    
                }
            }
            private int pageCurrent = 0;  // Default
     
     
            /// <summary>
            /// PageSize
            /// Used to grab the amount of data to match the grid height
            /// </summary>
            public int PageSize
            {
                get { return pageSize; }
                set
                {
                    pageSize = value;
     
                     
     
                    // Re-load...
                    RefreshRecords();
     
                    RaisePropertyChanged("PageSize");
                }
            }
            private int pageSize = 50;  // Default
     
     
     
            /// <summary>
            /// PagedCollectionView
            /// Represent a 'single' page of data
            /// </summary>
            public BrightstarQueryableCollectionView PagedCollectionView
            {
                get { return pagedCollectionView; }
                set { pagedCollectionView = value; }
            }
            private BrightstarQueryableCollectionView pagedCollectionView;
     
     
     
     
            #endregion
     
     
            /// <summary>OnInternalLoadCompleted</summary>  
            /// <remarks>Event Handler for the InternalLoadCompleted event
            /// This function handles the response to the raising of an InternalLoadCompleted event.
            /// If no errors or cancellation occurs in the retrieval of results, the current contents of thecollection
            /// of PFOs is cleared and the results retrieved added to that collection.
            /// Finally the LoadCompleted event is raised to notify listeners that the processing is completed.
            /// </remarks>
            private void OnInternalLoadCompleted(object sender, LoadCompletedEventArgs eventArgs)
            {
                try
                {
                    lock (lockLoad)
                    {
                        // Execute on UI Thread
                        Application.Current.RootVisual.Dispatcher.BeginInvoke(() =>
                            {
                                if (eventArgs.Error == null && eventArgs.IsCancelled == false)
                                {
                                    // Clear the list
                                    ItemList.Clear();
     
                                    // Create the new PFO Summary Items
                                    foreach (PFO item in eventArgs.Entities)
                                        ItemList.Add(item);
     
     
     
                                    // Set Selected Item and check if we can Export
                                    if (ItemList.Count > 0)
                                    {
                                        SelectedItem = ItemList[0];
                                        CanExecuteExport = true;
                                        CanExecuteSubmitData = true;
                                    }
                                    else
                                    {
                                        SelectedItem = null;
                                        CanExecuteExport = false;
                                        CanExecuteSubmitData = true;
                                    }
     
                                    //---------------------------------------------
                                    // Can only manually upload if the current user
                                    // is Brightstar Employee or System Administrator
                                    //---------------------------------------------
                                    CanExecuteManualUpload = !WebContext.Current.User.IsInRole("Customer");
                                    CanExecuteEdit = SelectedLineItems.Count > 0 && !IsGridReadOnly;
                                    canExecuteProductUpdateConstrain = !WebContext.Current.User.IsInRole("Customer");
     
                                    // MyObservableCollection
                                    MyObservableCollection.SuspendNotifications();
                                    MyObservableCollection.Clear();
                                    MyObservableCollection.AddRange(ItemList);
                                    MyObservableCollection.ResumeNotifications();
     
                                    // PagedCollectionView
                                    pageSize = PageSize;
                                    PagedCollectionView.PageSize = PageSize;
                                    PagedCollectionView.SetTotalItemsCount(eventArgs.TotalEntityCount);
                                    PagedCollectionView.SetIsLoading(false);
                                    PagedCollectionView.Refresh();
     
                                    // Not needed now - DSW
                                    // PagedCollectionView.CollectionChanged += pagedCollectionView_CollectionChanged;
     
                                    if (ItemList.Count > 0)
                                        TotalPrice = String.Format("{0:C2}", ItemList.First().DummyTotalPrice);
                                    else
                                        TotalPrice = String.Format("{0:C2}", 0);
                                    RaisePropertyChanged("PagedCollectionView");
                                    RaisePropertyChanged("PageSize");
                                }
     
                                // Indicate end of processing
                                IsProcessing = false;
     
                                // Raise Completed Event
                                if (LoadCompleted != null)
                                    LoadCompleted(this, eventArgs);
                            });
                    }
                }
                catch (Exception)
                {
                    int i = 0;
                    throw;
                }
            }
     
     
            /// <summary>
            /// LoadPagedData
            /// Initial entry point...
            /// </summary>
            public void LoadPagedData()
            {
                if (PagedCollectionView == null)
                {
                    MyObservableCollection = new RadObservableCollection<PFO>();
     
                    PagedCollectionView = new BrightstarQueryableCollectionView(MyObservableCollection);
     
                    // Dynamic Page Size              
                    PagedCollectionView.PageSize = PageSize;
     
                    PagedCollectionView.MoveToFirstPage();
                }
     
                RefreshRecords();
            }
     
     
            /// <summary>
            /// RefreshRecords
            /// </summary>
            public void RefreshRecords()
            {
                //if (PFOSliderPage == false || PFOSelectByTab != "CustomerEdit" || PFOSelectByTab != "StoreEdit")
                //{
                //    pageSize = 50;
                //}
     
                string customerIds = string.Join("|", SelectedCustomerIds);
                string planners = string.Join("|", SelectedPlannerIds);
                string productIds = string.Join("|", SelectedProductIds);
     
                //if (PFODouleClick == "Store" || PFODouleClick == "Planner" || PFODouleClick == "Product")
                //{
                //    pageSize = 5000;
                //}
               
     
                if (PagedCollectionView != null)
                    PFOSelectByStores(PagedCollectionView.PageIndex, PageSize, customerIds, planners,productIds); //, CustomerId, PlannerId
            }
     
     
            ///// <summary>
            ///// pagedCollectionView_CollectionChanged
            ///// </summary>
            //void pagedCollectionView_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
            //{
            //    //if (PagedCollectionView != null)
            //    //{
            //    //    PagedCollectionView.CollectionChanged -= pagedCollectionView_CollectionChanged;
     
            //    //    PagedCollectionView.SetIsLoading(true);
     
            //    //    RefreshRecords();
            //    //}
            //}
     
            #endregion
     
            #region "Custom Select Procedures"
     
            /// <summary>PFOSelectByStores</summary>  
            /// <remarks>
            /// This function retrieves a collection of PFO's using a WCF RIA Service.
            /// It first raises the LoadStarted to notify listeners that the process has started.
            /// Then creates the query to retrieve  the PFOs, executes that query, finally raising the
            /// InternalLoadCompleted event to processing the results.
            /// </remarks>
            public void PFOSelectByStores(int pageIndex, int pageCount, string customerId, string planners,string productIds)
            {
                try
                {
                    // Raise Started Event
                    if (LoadStarted != null)
                        LoadStarted(this, null);
     
                    // Indicate start of processing
                    IsProcessing = true;
     
                    // Set processing message
                    ProcessingMessage = ApplicationStrings.LoadingPleaseWaitMsg;
     
                    
                    if (PFODouleClick == "Store")
                    {
                        StoreIds = PFODouleClickStore;
                        customerId = ApplyCustomer;
     
                        if (!WebContext.Current.User.IsInRole("Customer"))
                        planners = PFODouleClickPlanner;
                        customerId = ApplyCustomer;
                         
                    }
     
                    if (PFODouleClick == "Planner" && !WebContext.Current.User.IsInRole("Customer"))
                    {
                        planners = PFODouleClickPlanner;
                        customerId = ApplyCustomer;
     
     
     
                        //StoreIds = PFODouleClickStore;
                    }
                    if (PFODouleClick == "Product")
                    {
                        customerId = PFODouleClickCustomer;
                        StoreIds = ApplyStores;
                        planners = ApplyPlanner;
                    }
     
                    if (PFODouleClick == "BackToSummary" || PFODouleClick == "Save" )
                    {
                     customerId = ApplyCustomer ;
                     StoreIds = ApplyStores;
                     planners = ApplyPlanner;
                    }
     
                    //if (PFODouleClick == null && SelectionChanged == false)
                    //{
                    //    customerId = string.Join("|", SelectedCustomerIds);
                    //    planners = string.Join("|", SelectedPlannerIds);
                    //    StoreIds = string.Join("|", SelectedStoreIds);
                    //}
                     
     
                    //===================================================================
                    // DSW - Design Issue:
                    // StoreIds is a string limited to 2038 characters
                    // Cricket has more store Ids than the 2038 limitation
                    // 10,000 stores * 6 chars = 60,000 chars
                    // [Query(HasSideEffects = true)]
                    //===================================================================
     
                    // Create the query to load all PFO Items
                    EntityQuery<PFO> query = Context.PFOSelectByStoresQuery(StoreIds, (int)SelectedExceptionFilterType, pageIndex, pageCount, UserId, SortColumn,productIds
     
    , customerId, planners); //, SortColumn);
     
                    // Execute the query
                    Context.Load<PFO>(query, LoadBehavior.RefreshCurrent, op =>
                    {
                        // Raise Internal Completed Event for processing the result
                        if (InternalLoadCompleted != null)
                            InternalLoadCompleted(this, new LoadCompletedEventArgs(op));
     
                        // Indicate end of processing
                        IsProcessing = false;
     
                    }, null);
                }
                catch (Exception ex)
                {
                    //String str = ex.Message;
                    //if (ex.InnerException != null)
                    //    str += " - Inner: " + ex.InnerException.Message;
     
                    //MessageBox.Show(str, "Orders", MessageBoxButton.OK);
                    throw;
                }
            }
     
    Detail Xaml
     
                                        <telerik:RadGridView x:Name="grdProducts"
                                            Grid.Row="1"
                                            Grid.Column="0" Width="Auto"
                                            VerticalContentAlignment="Stretch"
                                            HorizontalAlignment="Stretch"                                     
                                            ItemsSource="{Binding PagedCollectionView, Mode=TwoWay, Source={StaticResource PFOViewModel}}"                                     
                                            IsReadOnly="{Binding IsGridReadOnly, Source={StaticResource PFOViewModel}}"                                               
                                            Sorting="grdProducts_Sorting"
                                            Sorted="grdProducts_Sorted" >
     
    Summary XAML
        <telerik:RadGridView x:Name="grdSummaryStores"
                                            Grid.Row="1"
                                            Grid.Column="0" Width="Auto"
                                            VerticalContentAlignment="Stretch"
                                            HorizontalAlignment="Stretch"                                     
                                            ItemsSource="{Binding ItemList,  Mode=TwoWay, Source={StaticResource StoreSummaryViewModel}}"                                  
                                            IsReadOnly="{Binding IsGridReadOnly, Source={StaticResource PFOViewModel}}" 
                                            AutoExpandGroups="False">
Back to Top