Updating Gridview programmatically

9 posts, 0 answers
  1. Monika Kogler
    Monika Kogler avatar
    30 posts
    Member since:
    Aug 2009

    Posted 29 Jun 2010 Link to this post

    Hi,
    i need to update my gridview programmatically but nothing i have tried is working. thats my scenario:
    i have a grid with several different columns (combobox-, textbox-, checkbox-column), some of them can be edited, some of them are calculated and can't be edited by user. one row is representing one object, the grid is bound via itemsource.
    the following process has to be implemented now:
    1. user changes the value of an editable field
    2. cell_validating-event is fired
    3. in the cell_validating-event, the input is first verified. if the inserted value is okay, 3 other values are generated (bound to 3 non-editable columns)
    4. after assigning the new values the grid needs to be updated (generated values should show up).

    everything is working till step 4. i have tried to assign a new itemsource and call rebind, i have checked on the bindings, but nothing is working. if i load the page containing the grid a second time my data is showing up, but it need to be there directly after the validation! any suggestions?
  2. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 29 Jun 2010 Link to this post

    Hello Monika Kogler,

     Do your data items implement INotifyPropertyChanged?

    Regards,
    Yavor Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Monika Kogler
    Monika Kogler avatar
    30 posts
    Member since:
    Aug 2009

    Posted 29 Jun 2010 Link to this post

    Hi,
    No it doesn't, but I like to avoid the INotifyPropertyChanged interface. Is there any other thing i can do?
    Thx in advance
  5. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 29 Jun 2010 Link to this post

    Hi Monika Kogler,

     The INotifyPropertyChanged interface is the corner-stone of effortless data binding in the WPF and Silverlight worlds. I strongly recommend that you revise your opinion of it.

    Could you please try call Rebind() only, without touching the ItemsSource. Do please note that calling Rebind() every time a cell is changed is a performance hit.

    I still strongly advocate using INotifyPropertyChanged.

    All the best,
    Yavor Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Monika Kogler
    Monika Kogler avatar
    30 posts
    Member since:
    Aug 2009

    Posted 29 Jun 2010 Link to this post

    calling rebind doen't make any changes - the grid is not updated. that's accually one of the things i thought it could work out. any other suggestions?
  7. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 29 Jun 2010 Link to this post

    Hello Monika Kogler,

     It would help us immensely in tracking down the issue if you'd open a support ticket and attach a small sample application that reproduces this issue. I would be very grateful if you do so.

    Sincerely yours,
    Yavor Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Monika Kogler
    Monika Kogler avatar
    30 posts
    Member since:
    Aug 2009

    Posted 29 Jun 2010 Link to this post

    hi,
    i have added my sample to a bug report. hope that helps solving this problem because i really need a solution for this until the end of this week. please let me know if you have any futher suggestions.
  9. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 05 Aug 2010 Link to this post

    Any solution on this?

    I have the same problem (Rebind not working).

    To explain the things - I work with Linq2Sql - which is (unfortunately)  not fully supported by RadGrid.
    So I have to do a lot in code behind.
    Anyhow - I found a nice support sample so this was not to hard - from the first point of view.

    About the problem:
    In the RowEditEnded I take care about inserts like this:
    Snippet created with CBEnhancer
    ImportDirectory iD = e.EditedItem as ImportDirectory;
    if(e.EditOperationType == GridViewEditOperationType.Insert) {
        m_dC.ImportDirectories.InsertOnSubmit(iD);
        m_dC.SubmitChanges();
        rgvDirectories.Rebind();
    This doesn't show the inserted row.
    So I changed to this (from the support code):
    Snippet created with CBEnhancer
    m_dC.ImportDirectories.InsertOnSubmit(iD);
    m_dC.SubmitChanges();
    m_dC.Refresh(System.Data.Linq.RefreshMode.KeepChanges, m_dC.ImportDirectories);
    rgvDirectories.Rebind();
    This doesn't show the newly added row.
    So I solve it "brute force":
    Snippet created with CBEnhancer
    m_dC.ImportDirectories.InsertOnSubmit(iD);
    m_dC.SubmitChanges();
    rgvDirectories.ItemsSource = null;
    //m_dC.Refresh(System.Data.Linq.RefreshMode.KeepChanges, m_dC.ImportDirectories);
    rgvDirectories.ItemsSource = m_dC.ImportDirectories;
    As you may have noticed - I didn't call the (time consuming refresh).
    Instead I "undbind" the Grid - which shows some (handled) "Argument Exceptions" in debug.
    And bind it again - that works!

    A final interesting thing - for delete Rebind works:
    Snippet created with CBEnhancer
    m_dC.ImportDirectories.DeleteOnSubmit(iD);
    m_dC.SubmitChanges();
    //rgvDirectories.ItemsSource = null;
    //m_dC.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, m_dC.ImportDirectories);
    //rgvDirectories.ItemsSource = m_dC.ImportDirectories;
    rgvDirectories.Rebind();

    I know that Linq2Sql is missing Observable.... - but I thought Grid.Rebind() should overcome this problem.
    But it does the job only partial (in delete) - for insert only "brute force" works.

    That's why I aske here since Monika seems to have a similar problem.
    My hope is that here support ticket resulted in a solution.

    Manfred
  10. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 11 Aug 2010 Link to this post

    Hello,

    Why not use a bit more different approach - for example MVVM. I've made for you small example application to illustrate you how to achieve your goal with LINQ to SQL - you can find the project attached. In the previous case rebind didn't worked since it was called during Validating event which is not correct.

    All the best,
    Vlad
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
UI for WPF is Visual Studio 2017 Ready