radgridview hierarchy refreshing hierarchy grid closes.

6 posts, 0 answers
  1. Karl
    Karl avatar
    172 posts
    Member since:
    Jun 2009

    Posted 16 Dec 2011 Link to this post

    Hi,
    I have a radgridview setup wth a hierarchy. I would like this grid to refresh every ten seconds as new information could be added to the database from another source, so it needs to be kept up-to-date. I did have a timer which would fire every ten seconds which reloaded the data.

    The only problem is, if I have a row expanded or select a row and the grid reloads the selected row is lost and the sub grids close. Is there any way I can  keep this open while the data refreshes? ie the new row would be added at the bottom?

    Any ideas or pointers would be great.

    Thanks
  2. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 21 Dec 2011 Link to this post

    Hi Karl,

    Thank you for writing.

    Please give a more detailed description of the scenario used. What type of hierarchy mode you are using in your application and how the data is reloaded. Some code snippets or a simple application that demonstrates the issues will be greatly appreciated. Thank you for your cooperation.

    I am looking forward to your reply.

    Greetings,
    Julian Benkov
    the Telerik teamQ3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
  3. Karl
    Karl avatar
    172 posts
    Member since:
    Jun 2009

    Posted 03 Jan 2012 Link to this post

    Hi,

    Thank you for getting back to me.

    I have a grid which I populate this way:

    rg.DataSource = TblOrder.FetchAll();
    rg.MasterTemplate.AllowAddNewRow = false;
    rg.MasterTemplate.AllowCellContextMenu = false;
    rg.MasterTemplate.AllowDeleteRow = false;
    rg.MasterTemplate.AllowEditRow = false;
    rg.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
    GridViewTemplate template = new GridViewTemplate();
    template.AllowAddNewRow = false;

    rg.MasterTemplate.Templates.Add(template);
    template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
    template.AllowAddNewRow = false;
    template.AllowCellContextMenu = false;
    template.AllowDeleteRow = false;
    template.AllowEditRow = false;
    commandColumn = new GridViewCommandColumn();
    commandColumn.HeaderText = "Command";

    rg.CommandCellClick += new CommandCellClickEventHandler(rg_CommandCellClick);
    template.Columns.Add(commandColumn);

    GridViewRelation relation = new GridViewRelation(rg.MasterTemplate);
    relation.ChildTemplate = template;
    relation.RelationName = "WorkOrderSegmentRelationship";
    relation.ParentColumnNames.Add("OrderID");
    relation.ChildColumnNames.Add("OrderIDFK");
    rg.Relations.Add(relation);

    template.DataSource = TblOrderSub.FetchAll();

    The above works without a problem, when i select a row with sub data it displays.

    On the machines there will be a windows service running in the back ground which will be downloading new data and inserting it in to the data base.

    What I want to do is have the grid refresh every 5 minutes for example to display this data. I was going to use a timer which would reload the grid each time, this works however if I am viewing the grid and have a row selected or a sub grid expanded I lose this as the grid is reloaded. Is there away of maintaining the state of the grid when the new data is loaded?

    Any pointers would be great.

    Thanks

  4. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 06 Jan 2012 Link to this post

    Hi Karl,

    The issue is that in your data bound scenario the RadGridView will be Reset after each DataSource change. This will recreate the logical rows in RadGridView control and will reset its current state. The simple solution in this situation is to save expanded DataBoundItems in one Hash table and after reload restore the expanded state. Here is a simple example:

    private void GridForm4_Load(object sender, EventArgs e)
    {
        // TODO: This line of code loads data into the 'northwindDataSet.Products' table. You can move, or remove it, as needed.
        this.productsTableAdapter.Fill(this.northwindDataSet.Products);
        // TODO: This line of code loads data into the 'northwindDataSet.Categories' table. You can move, or remove it, as needed.
        this.categoriesTableAdapter.Fill(this.northwindDataSet.Categories);
     
        HashSet<object> expanded = SaveExpanded();
        this.radGridView1.DataSource = this.northwindDataSet.Products;
        RestoreExpanded(expanded);
    }
     
    private void RestoreExpanded(HashSet<object> expanded)
    {
        foreach (var item in this.radGridView1.Rows)
        {
            if (expanded.Contains(item.DataBoundItem))
            {
                item.IsExpanded = true;
            }
        }
    }
     
    private HashSet<object> SaveExpanded()
    {
        HashSet<object> items = new HashSet<object>();
        foreach (var item in this.radGridView1.Rows)
        {
            if (item.IsExpanded)
            {
                items.Add(item.DataBoundItem);
            }
        }
     
        return items;
    }

    I hope this helps. Do not hesitate to contact us if you have further questions or issues.

    Kind regards,
    Julian Benkov
    the Telerik team

    SP1
    of Q3’11 of RadControls for WinForms is available for download (see what's new).
  5. Karl
    Karl avatar
    172 posts
    Member since:
    Jun 2009

    Posted 06 Jan 2012 Link to this post

    Hi,

    I've tried that and it doesn't seem to work. I've stepped through the code and can see it saving it, but not restoring. Does that code have to be on the Grid4_Load?

    This is where I have put this code:
    HashSet<object> expanded = SaveExpanded(rg);
    rg.DataSource = TblOrder.FetchAll();

    RestoreExpanded(expanded, rg);


    I just added another parameter.

    To load the grid I have this in the ticker_Tick event:
    MyGrid loadGrid = new MyGrid();

    loadGrid.LoadGrid(

     

    this.rgOrders);

    Thanks

     


  6. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 11 Jan 2012 Link to this post

    Hi Karl,

    The restoring logic must be executed after all load and datasource setup operations.

    If you continue to experience the same issues, please send us some part of your data and a sample application that demonstrates the used loading mechanism to investigate the issues locally and find best solution for your application. 

    Please note that you have to open a new support ticket in order to be able to attache your files.
     
    Regards,
    Julian Benkov
    the Telerik team

    SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

Back to Top