Completed
Last Updated: 14 Oct 2015 12:38 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 29 Dec 2014 11:14
Category: GridView
Type: Bug Report
1
FIX. RadGridView - EnsureVisible(true) method does not expand the parent row if the specific parent row is not expanded at least once
To reproduce:

private void Form1_Load(object sender, EventArgs e)
{
    this.productsTableAdapter.Fill(this.nwindDataSet.Products);
    this.categoriesTableAdapter.Fill(this.nwindDataSet.Categories);

    radGridView1.DataSource = nwindDataSet.Categories;
    radGridView1.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;

    GridViewTemplate template = new GridViewTemplate();
    template.DataSource = nwindDataSet.Products;
    template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
    radGridView1.MasterTemplate.Templates.Add(template);

    GridViewRelation relation = new GridViewRelation(radGridView1.MasterTemplate);
    relation.ChildTemplate = template;
    relation.RelationName = "CategoriesProducts";
    relation.ParentColumnNames.Add("CategoryID");
    relation.ChildColumnNames.Add("CategoryID");
    radGridView1.Relations.Add(relation);

     this.radGridView1.CurrentRow = this.radGridView1.MasterTemplate.Templates.First().Rows[this.radGridView1.MasterTemplate.Templates.First().Rows.Count - 1];
}

Workaround:

this.radGridView1.MasterTemplate.ExpandAll();
this.radGridView1.MasterTemplate.CollapseAll();
this.radGridView1.CurrentRow = this.radGridView1.MasterTemplate.Templates.First().Rows[this.radGridView1.MasterTemplate.Templates.First().Rows.Count - 1];


Another scenario: if you try to add a new row to the child template on the RadButton.Click event and call the EnsureVisible(true) method, it will not affect the grid, until you expand/collapse the parent row:

private void radButton1_Click(object sender, EventArgs e)
{
    //add the new row to the child template
    DataRow newRow = this.nwindDataSet.Products.Rows.Add();
    newRow["CategoryID"] = 3;
    newRow["ProductName"] = "NewProduct";

    this.radGridView1.CurrentRow = this.radGridView1.MasterTemplate.Templates.First().Rows[this.radGridView1.MasterTemplate.Templates.First().Rows.Count - 1];
    this.radGridView1.CurrentRow.EnsureVisible(true);
}

Workaround:

private void radButton1_Click(object sender, EventArgs e)
{
    //keep expanded rows
    List<GridViewRowInfo> expandedRows = new List<GridViewRowInfo>();
    foreach (GridViewRowInfo row in this.radGridView1.Rows)
    {
        if (row.IsExpanded)
        {
            expandedRows.Add(row);
        }
    }
    
    //add the new row to the child template
    DataRow newRow = this.nwindDataSet.Products.Rows.Add();
    newRow["CategoryID"] = 3;
    newRow["ProductName"] = "NewProduct";

    //refresh the rows
    this.radGridView1.MasterTemplate.ExpandAll();
    this.radGridView1.MasterTemplate.CollapseAll();

    foreach (GridViewRowInfo rowToExpand in expandedRows)
    {
        rowToExpand.IsExpanded = true;
    }
    this.radGridView1.CurrentRow = null;
    this.radGridView1.CurrentRow = this.radGridView1.MasterTemplate.Templates.First().Rows[this.radGridView1.MasterTemplate.Templates.First().Rows.Count - 1];
    this.radGridView1.CurrentRow.EnsureVisible(true);
}
0 comments