Virtual Mode Cell Update

4 posts, 2 answers
  1. Hesham Desouky
    Hesham Desouky avatar
    22 posts
    Member since:
    Oct 2012

    Posted 23 Jan 2012 Link to this post

    Hello,

    I am implementing virtual mode for WinForms RadGridView

    Everything working ok except one thing, in my virtual mode implementation user may required additional data from slow data source in such case the data will not be available when grid needs the cell value.
    In this case the cells displays a "Loading..." text until the data is retrieved from the slow source.

    The problem is how to tell the GridView to reread the cells values to update the cells with real content.

    I tried the MasterTemplate.Refresh but this cause the grid scroll returns to the top again and display the first item.

    Is there any method to call to force the grid to re-read the visisble cells values without reseting the scroll?

    I am using 2011 Q2 SP1


  2. Answer
    Julian Benkov
    Admin
    Julian Benkov avatar
    1133 posts
    Member since:
    Sep 2012

    Posted 26 Jan 2012 Link to this post

    Hi Heshman,

    You should call the Update method of GridTableElement to solve this issue. Consider the sample below:

    public partial class VirtualGridForm : Form
    {
        private Random random = new Random((int)DateTime.Now.Ticks);
     
        public VirtualGridForm()
        {
            InitializeComponent();
             
            radGridView.VirtualMode = true;
            radGridView.CellValueNeeded += new GridViewCellValueEventHandler(radGridView_CellValueNeeded);
            radGridView.RowCount = 1000;
            radGridView.ColumnCount = 10;
        }
     
        void radGridView_CellValueNeeded(object sender, GridViewCellValueEventArgs e)
        {
            e.Value = random.Next(1000);
        }
     
        private void button1_Click(object sender, EventArgs e)
        {
            radGridView.TableElement.Update(GridUINotifyAction.DataChanged);
        }
    }

    I hope this helps.

    Kind regards,
    Julian Benkov
    the Telerik team

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

  3. Hesham Desouky
    Hesham Desouky avatar
    22 posts
    Member since:
    Oct 2012

    Posted 29 Jan 2012 Link to this post

    thanks for your reply,

    I am implementing this solution:

    var visibleRows = gridStudy.TableElement.VisualRows.Select(r=>r.RowInfo).ToArray();
    gridStudy.TableElement.Update(GridUINotifyAction.DataChanged, visibleRows);

    It works but I don't know whether the extra code I add to update the visible rows only enhance performanfce or not?

  4. Answer
    Julian Benkov
    Admin
    Julian Benkov avatar
    1133 posts
    Member since:
    Sep 2012

    Posted 01 Feb 2012 Link to this post

    Hello Hesham,

    This additional logic is not needed in virtual mode. RadGridView is optimized for this behavior and CellValueNeeded event will be fired only for the visible cells on the screen.

    Kind 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