CurrentCell in RadGridView errors out when not in visible view

2 posts, 0 answers
  1. Xeeyee
    Xeeyee avatar
    1 posts
    Member since:
    Mar 2014

    Posted 09 Jun Link to this post

    I have a radgridview in WinsForm. I created data entry number pad (buttons) for the user interface. When the table loads up, the current cell (focused cell) is set to the first cell in the upper left. When the user presses the number pad button, it enters the data to the currentcell's value. It works all fine and dandy until the table gets bigger and requires scrolling to see other cells. My problem is, when the user scrolls away from the currentcell and the currentcell is not in sight there will be an error if any button referencing the currentcell is pressed. It seems that when the currentcell is not in view, it cannot access the currentcell. Is there a way around this or resolve this?
  2. Dess
    Dess avatar
    1561 posts

    Posted 09 Jun Link to this post

    Hello Xeeyee,

    Thank you for writing. 

    The RadGridView.CurrentCell property returns a GridDataCellElement. However, when the current cell is outside the visible area, this property will return null. Due to the UI virtualization in RadGridView, cell elements are created only for currently visible cells and are being reused during operations like scrolling, filtering, grouping and so on. If you need to assign a new value to the current cell that is now visible, feel free to access the relevant GridViewCellInfo. Here is a sample code snippet:
    public Form1()
        DataTable dt = new DataTable();
        for (int i = 0; i < 3; i++)
            dt.Columns.Add("Col" + i);
        for (int i = 0; i < 100; i++)
            dt.Rows.Add("Data " + i + ".0", "Data " + i + ".1", "Data " + i + ".2");
        this.radGridView1.DataSource = dt;
        this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
    private void radButton1_Click(object sender, EventArgs e)
        if (this.radGridView1.CurrentRow != null && this.radGridView1.CurrentColumn != null)
            this.radGridView1.CurrentRow.Cells[this.radGridView1.CurrentColumn.Name].Value = DateTime.Now.ToLongTimeString();

    I hope this information helps. Should you have further questions I would be glad to help.

    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  3. DevCraft R3 2016 release webinar banner
Back to Top