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

GridView QueryableCollectionView add new item issue

6 Answers 294 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Deng
Top achievements
Rank 1
Deng asked on 16 Apr 2013, 05:34 PM
Hi  all,

I use GridView + DataPager with QueryableCollectionView , mainly do CURD operations, everything worked well but add new item.
Please note I assign IQueryable source to QueryableCollectionView for solving huge data performance issue.  When I call gridVIew's BeginInsert();  , one new row will be shown in first row of GridView.  That's fine, but there are some questions. 

1. The insert row will disappear if I click another row(With setting ActionOnLostFocus = ActionOnLostFocus.None),   I cannot find it in grid view any more. because I have added it to EF ObjectContext, so if I do this once and then SaveChanges() , the two entries will be inserted into database! 
I have used AddingNewDataItem Event , but I still can not find the new item in QueryableCollectionView and GridView.Items

 public void AddingNewDataItem(object sender, GridViewAddingNewEventArgs e)
        {
            var entity = copyItem ?? new TOrginal();
            copyItem = null;
            IntializeNewItem(entity);

            var model = new TModel { Model = entity };
            CurrentItem = model;
            e.NewObject = model;
           // AddModelToCollection(e, model);

            if (CheckItemIsNew(CurrentItem)) return;
            CommonManager.Add(entity);
        }

next..I also try to insert Item into QueryableCollectionView directly, the gridview even do not show new item..

So I only can do delete it from EF context when CurrentItem change...

2. How to make Insert Row always visible when Adding new Row and Click other rows of this grid.??? 

Can you please give me some hint? It driven me crazy.

If you cannot solve this, can you please give me one solution for big data and CURD mechanism. 

6 Answers, 1 is accepted

Sort by
0
Deng
Top achievements
Rank 1
answered on 19 Apr 2013, 03:07 AM
Any news?
0
Nedyalko Nikolov
Telerik team
answered on 22 Apr 2013, 02:16 PM
Hi,

You could use our RadEntityFrameworkDataSource control for CRUD operations out-of-the-box as shown in this online help article. For dealing with large amounts of data you could use RadDataPager or some filtering.

Could you please provide me with a little bit more info about your scenario - how do you get IQueryable source, do you handle RadGridView.RowEditEnded event, how do you use QueryableCollectionView (a sample project which I can debug on my side will be great)?

Regards,
Nedyalko Nikolov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Deng
Top achievements
Rank 1
answered on 09 May 2013, 09:17 AM
Hi Nedyalko,

Thanks for you reply.

Sorry for delay reply.  I updated my demo application to Skydrive, please download it :
https://skydrive.live.com/?cid=a045953f8cbc2de7&id=A045953F8CBC2DE7%21222&authkey=!AFC86DB5oolC19w

 I want to add new item to QueryableCollectionView directly, and the GridView will update.
  But below code is useless!!!!!!!
 var viewmode =  this.DataContext as ViewModel;
 viewmode.QueryableCollectionView.AddNew(new Address());
viewmode.QueryableCollectionView.AddNewItem(new Address());


  What I did now is make GridView.BeginInsert.
public void AddingNewDataItem(object sender, GridViewAddingNewEventArgs e)
        {
            e.NewObject = new Address();
        }



   But it throw many issues
            1. If I click other row in this grid, this new Item row will be disappeared
            2. I have to make many code to control it, besides, it is very unreadable.

  I want to add new item to QueryableCollectionView directly, and the GridView will update.
  I don't require new item must be showed in InsertRow, only if it can be showed in GridView and not disappear

Thanks very much.

Regards,
Dely

0
Nedyalko Nikolov
Telerik team
answered on 10 May 2013, 10:26 AM
Hello,

The problem comes from the fact that you are providing QueryableCollectionView with IQueryable data source. IQueryable does not support adding new items (in order to add new items your data source should implement IList interface). Furthermore EntityFramework creates a proxy Address object (Address_23423..) and you cannot add Address object to that collection. You could handle RadGridView.RowEditEnded and update your database manually or change the original data source to something that implements IList.

Regards,
Nedyalko Nikolov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Deng
Top achievements
Rank 1
answered on 01 Jul 2013, 07:31 PM
Hi Nikolov ,

Thanks for your reply.

as you said, if I change data source to IList, It will load all data into memory, our application has big data. Can you please provide a small project to handle this condition?
0
Dimitrina
Telerik team
answered on 04 Jul 2013, 12:42 PM
Hello,

For example the List<T> and ObservableCollection<T> collections implement this interface. You can check the msdn for more information and details on IList.
Then you can find this help article on using ObservableCollection<T> (that implements IList). 

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
Deng
Top achievements
Rank 1
Nedyalko Nikolov
Telerik team
Dimitrina
Telerik team
Share this question
or