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

Keep grid rows updated (without scrolling to top or losing column layout) on CRUD operations when the datasource is bound to a generic IList<T>

2 Answers 113 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Carlo
Top achievements
Rank 1
Carlo asked on 08 Jun 2017, 08:12 AM

Greetings. We're considering to adopt your suite of components as a standard for our future applications.

At the moment, I'm trying to understand if your WinForms GridView component behavior suits our current workflow.

 

Consider the following class structure (Master -> each master has "n" Slaves -> each slave has "k" SubSlaves):

   public class MasterEntity

    {
        public Int32 Id { get; set; }
        public String Name { get; set; }

        public IList<SlaveEntity> Slaves { get; set; }
    }

    public class SlaveEntity
    {
        public Int32 Id { get; set; }
        public String PropA { get; set; }
        public Decimal PropB { get; set; }

        public IList<SubSlaveEntity> SubSlaves { get; set; }
    }

    public class SubSlaveEntity
    {
        public Int32 Id { get; set; }
        public String PropC { get; set; }
    }

I assign the dataSource of the grid to an IList<MasterEntity>: as you can see all the lists involved are generic ILists (not BindingLists) and each class doesn't implement the INotifyPropertyChanged interface.

Following the instructions in this page (http://docs.telerik.com/devtools/winforms/gridview/hierarchical-grid/binding-to-hierarchical-data-automatically), I'm able to display the rows in a proper hierarchical grid (through AutoGenerateHierarchy property). I'm also able to properly configure the layout of each column at each hierarchy level.

Now, what I want to achieve is the following:

When I add/delete/edit a row (at each hierarchy level, Master, Slave or SubSlave) I need the changes to be reflected in the grid, without it scrolling to the top or losing the column layout settings. Of course, since we're using normal Lists (not BindingLists) and the entities doesn't implement INotifyPropertyChanged, I know that the grid must be notified of each operation performed on its datasource. At the moment I've only managed to achieve this when I change a property of an entity at the first hierarchy level (Master):

1.(radGrid.Datasource as IList<MasterEntity>)[0].Name = "NEW NAME";
2.radGrid.TableElement.Update(GridUINotifyAction.DataChanged);

 

but I also need this to work when I do the following:

1.(radGrid.Datasource as IList<MasterEntity>).Add(new MasterEntity(){ .. });
2.-> how to notify the grid about the new master entity?
1.
 (radGrid.Datasource as IList<MasterEntity>)[0].Slaves[0].PropA = "NEW PROP A VALUE";
2.-> how to notify the grid about the change in a property value in that slave entity?
1.(radGrid.Datasource as IList<MasterEntity>)[0].Slaves.Add(new SlaveEntity(){ .. });
2.-> how to notify the grid about the new slave entity in the first master entity?

 

..and so on, I need to be able to perform ADD / DELETE / CHANGE ENTITY PROPERTIES at each hierarchy level and properly notify the grid about each operation, while keeping the current column layout (at each hierarchy level) and without the grid scrolling to the top.

Thanks for the kind help.

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 09 Jun 2017, 09:22 AM
Hi Carlo,

You need to refresh the templates and save/restore the scroll value:
int scrollValue = radGridView1.TableElement.VScrollBar.Value;
  
radGridView1.MasterTemplate.Refresh();
radGridView1.Templates[0].Refresh();
radGridView1.Templates[0].Templates[0].Refresh();
 
radGridView1.TableElement.VScrollBar.Value = scrollValue;

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Carlo
Top achievements
Rank 1
answered on 12 Jun 2017, 07:39 AM
Excellent. The proposed solution works as intended.
Tags
GridView
Asked by
Carlo
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Carlo
Top achievements
Rank 1
Share this question
or