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

VirtualQueryableCollectionView insert new item and save to database

4 Answers 128 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Deng
Top achievements
Rank 1
Deng asked on 11 Jun 2012, 03:31 PM
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.

4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 12 Jun 2012, 06:15 AM
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 >>

0
Deng
Top achievements
Rank 1
answered on 12 Jun 2012, 07:34 PM
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++ .
0
Richard
Top achievements
Rank 1
answered on 05 Jul 2013, 05:32 AM
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.
0
Dimitrina
Telerik team
answered on 10 Jul 2013, 07:38 AM
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 >>
Tags
GridView
Asked by
Deng
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Deng
Top achievements
Rank 1
Richard
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or