GridView QueryableCollectionView add new item issue

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

    Posted 16 Apr 2013 Link to this post

    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. 

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

    Posted 18 Apr 2013 Link to this post

    Any news?
  3. Nedyalko Nikolov
    Admin
    Nedyalko Nikolov avatar
    871 posts

    Posted 22 Apr 2013 Link to this post

    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.

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

    Posted 09 May 2013 Link to this post

    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

  5. Nedyalko Nikolov
    Admin
    Nedyalko Nikolov avatar
    871 posts

    Posted 10 May 2013 Link to this post

    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.

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

    Posted 01 Jul 2013 Link to this post

    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?
  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 04 Jul 2013 Link to this post

    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 >>
Back to Top