VirtualQueryableCollectionView insert new item and save to database

5 posts, 0 answers
  1. Deng
    Deng avatar
    19 posts
    Member since:
    Apr 2012

    Posted 11 Jun 2012 Link to this post

    Hi telerik,

    I am confused how to use RadGridView with VirtualQueryableCollectionView in order for data virtualization, but some issues encountered when I insert a new item, let me clarify.

    I use the below code to set datacontext of a window, 
    var query = _context.Taxes.OrderBy(o => o.TaxID); //Order_Details.OrderBy(o => o.OrderID);
               var view = new VirtualQueryableCollectionView(query) {LoadSize = 10 };
               DataContext = view;

    but there are some specified points, the Tax table only have 7 records, those records can show in grid correctly,but if I use blow code for inserting a new item,
               
    private void Button_Click(object sender, RoutedEventArgs e)
        {
            (DataContext as VirtualQueryableCollectionView).AddNew(new Tax() { TaxCode = "45",TaxPercentage2 = 0.34f });
        }

    this new item will not display in grid expect adding this statement
             
    (DataContext as   VirtualQueryableCollectionView).VirtualItemCount++;

    But executing this statement will refresh the collection and grid,  I don't want to do this. so my questions are
    1. How can I show all records if called insert statement?
    2. How to save a new records to database? 
    I did this using below statements currently:
             
    (DataContext as  VirtualQueryableCollectionView).Insert(0, newItem);
               context.CreateObjectSet<TValue>().AddObject(newItem);
               context.SaveChanges();

    if I can add use VirtualQueryableCollectionView's AddNew/AddNewItem/Insert add a item to VirtualQueryableCollectionView and then call someone method to save it to database directly without needing executing context.CreateObjectSet<TValue>().AddObject(newItem);
    ? if yes, could you provide a sample project for me? thanks very much.
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 12 Jun 2012 Link to this post

    Hello,

     The virtual collection is designed to handle mostly read-only scenarios. You can add/remove records from your source directly (in this case your Taxes table) and reload the collection when/if needed. 

    Regards,
    Vlad
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. Deng
    Deng avatar
    19 posts
    Member since:
    Apr 2012

    Posted 12 Jun 2012 Link to this post

    Thanks for your replying.  like I said , if I set VirtualItemCount = 10, but the table  only has 7 records, the RadGridView only show 7 records. if I add a new item, the new item would not show in RadGridView unless calling VirtualItemCount++ , what is I do not want. so Please tell me how to add new item and show it
     without call VirtualItemCount++ .
  4. Richard
    Richard avatar
    3 posts
    Member since:
    Mar 2013

    Posted 05 Jul 2013 Link to this post

    Hi Vlad,

    Just reviving this thread. Are there any solution to this issue apart from setting the VirtualItemCount to a new value? As we all know, if that property changes, all other data loaded already are being reloaded which is not really ideal.

    Thanks.
  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 10 Jul 2013 Link to this post

    Hi,

    It is not possible to update just a single property's value.

    You can also invoke the ResetItems() method for the virtual collection. Please note that this method will not raise Reset CollectionChange however it will set null for all the loaded items. 

    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