Completed
Last Updated: 12 Feb 2016 08:53 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 30 Dec 2015 08:03
Category: GridView
Type: Bug Report
0
FIX. RadGridView - HasChildRows property returns always true in self-reference hierarchy although the child row does not have any child rows
To reproduce: use the following code snippet and try to delete a child row:

public Form1()
{
    InitializeComponent();

    DataTable dt = new DataTable();
    dt.Columns.Add("Id", typeof(int));
    dt.Columns.Add("ParentId", typeof(int));
    dt.Columns.Add("Name", typeof(string));

    for (int i = 0; i < 5; i++)
    {
        dt.Rows.Add(i, null, "Item" + i);
    }

    Random rand = new Random();
    for (int i = 5; i < 30; i++)
    {
        dt.Rows.Add(i, rand.Next(0, 5), "Child item" + i);
    }
    this.radGridView1.Relations.AddSelfReference(this.radGridView1.MasterTemplate, "Id", "ParentId");
    this.radGridView1.DataSource = dt;
    this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;

    this.radGridView1.UserDeletingRow += radGridView1_UserDeletingRow;
}

private void radGridView1_UserDeletingRow(object sender, Telerik.WinControls.UI.GridViewRowCancelEventArgs e)
{
    if (this.radGridView1.CurrentRow.HasChildRows())
    {
        DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete this row?",
            "Delete Row confirmation", MessageBoxButtons.YesNo);
        if (dialogResult == DialogResult.No)
        {
            e.Cancel = true;
        }
    }
}

Workaround: use the RadGridView.CurrentRow.ChildRows.Count property.
0 comments