Scroll to child row

5 posts, 0 answers
  1. Lorenzo Sforzini
    Lorenzo Sforzini avatar
    4 posts
    Member since:
    Jul 2010

    Posted 18 Mar 2011 Link to this post

    I have a hierarchic GridView and I want to scroll to the selected row after a new databind of the control.
    If I do

    this.radGridView1.TableElement.ScrollToRow(this.radGridView1.CurrentRow);

    no problem if the current row is a parent row but if the current row is a child row the GridView scroll to the end.
    How to scroll to a selected child row?
    Thanks

  2. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 19 Mar 2011 Link to this post

    Hello Lorenzo,

    You could try parsing the Rows collection of the grid view or the Template's Row collection if you just want child rows, and when you reach your desired row you could just call EnsureVisible() on that row.

    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga

    Telerik WinForms MVP
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Lorenzo Sforzini
    Lorenzo Sforzini avatar
    4 posts
    Member since:
    Jul 2010

    Posted 21 Mar 2011 Link to this post

    Thank you. That solves my problem
  5. Lorenzo Sforzini
    Lorenzo Sforzini avatar
    4 posts
    Member since:
    Jul 2010

    Posted 16 Jun 2011 Link to this post

    Even about scroll. I have this code refreshing the GridView:

    List<int> selectedRowsIndexes = new List<int>();
    List<int> selectedRowsIndexesTemplate = new List<int>();
     
    this.radGridView1.BeginEdit();
    foreach (GridViewDataRowInfo row in this.radGridView1.SelectedRows)
    {
        if (this.radGridView1.Rows.IndexOf(row) == -1)
        {
            selectedRowsIndexesTemplate.Add(this.radGridView1.Templates[0].Rows.IndexOf(row));
        }
        else
        {
            selectedRowsIndexes.Add(this.radGridView1.Rows.IndexOf(row));
        }
    }
     
    this.radGridView1.DataSource = lstMaster;
    this.radGridView1.Templates[0].DataSource = lstDetail;
     
    foreach (var item in this.radGridView1.ChildRows)
    {
        if (item.ChildRows.Count > 0)
        {
            item.IsExpanded = true;
        }
    }
     
    foreach (int index in selectedRowsIndexes)
    {
        if (this.radGridView1.Rows.Count > index)
        {
            this.radGridView1.Rows[index].IsSelected = true;
            this.radGridView1.Rows[index].IsCurrent = true;
            this.radGridView1.Rows[index].EnsureVisible();
        }
        else if (this.radGridView1.Rows.Count > 0)
        {
            this.radGridView1.Rows[0].IsSelected = true;
            this.radGridView1.Rows[0].IsCurrent = true;
            this.radGridView1.Rows[0].EnsureVisible();
        }
    }
     
    foreach (int index in selectedRowsIndexesTemplate)
    {
        if (this.radGridView1.Templates[0].Rows.Count > index)
        {
            this.radGridView1.Templates[0].Rows[index].IsSelected = true;
            this.radGridView1.Templates[0].Rows[index].IsCurrent = true;
            this.radGridView1.Templates[0].Rows[index].EnsureVisible();
        }
        else if (this.radGridView1.Templates[0].Rows.Count > 0)
        {
            this.radGridView1.Templates[0].Rows[0].IsSelected = true;
            this.radGridView1.Templates[0].Rows[0].IsCurrent = true;
            this.radGridView1.Templates[0].Rows[0].EnsureVisible();
        }
        else if (this.radGridView1.Rows.Count > 0)
        {
            this.radGridView1.Rows[0].IsSelected = true;
            this.radGridView1.Rows[0].IsCurrent = true;
            this.radGridView1.Rows[0].EnsureVisible();
        }
    }
     
    this.radGridView1.CurrentRow.EnsureVisible();
    this.radGridView1.TableElement.EnsureRowVisible(this.radGridView1.CurrentRow);
    this.radGridView1.EndEdit();

    When I ribind the GridView the selected row is no longer in the datasource because its state change and the rows are filtered. At the end of the function, my intention is that the current row is the following row than the original selected and the GridView scroll to ensure the new selected row is visible. If the orginal selected row is a child row, the following row is selected but the GridView doesn't scroll to ensure that is visible. I have WinControl version 2010.3.10.1215.
    What I can do?
    Thanks
  6. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 21 Jun 2011 Link to this post

    Hi Lorenzo Sforzini,

    Thank you for writing.

    Have you tried your scenario with the latest release Q1 2011 SP1 (2011.1.11.419) ? It contains many fixes and numerous improvements. It is possible that described case could work properly.

    Let me know whether the latest version helped.

    Regards,
    Martin Vasilev
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
Back to Top
UI for WinForms is Visual Studio 2017 Ready