Completed
Last Updated: 08 Jun 2015 13:03 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 31 Mar 2015 07:23
Category: GridView
Type: Bug Report
0
FIX. RadGridView - missing rows in self-referencing hierarchy when the Rows.AddNew() is used
To reproduce:

public Form1()
{
    InitializeComponent();

    GridViewDecimalColumn idColumn = new GridViewDecimalColumn("ID");         
    radGridView1.MasterTemplate.Columns.Add(idColumn);

    GridViewDecimalColumn parentIdColumn = new GridViewDecimalColumn("ParentID");         
    radGridView1.MasterTemplate.Columns.Add(parentIdColumn);

    GridViewTextBoxColumn nameColumn = new GridViewTextBoxColumn("Name");
    radGridView1.MasterTemplate.Columns.Add(nameColumn);

    GridViewTextBoxColumn addressColumn = new GridViewTextBoxColumn("Address");
    radGridView1.MasterTemplate.Columns.Add(addressColumn);

    GridViewTextBoxColumn typeColumn = new GridViewTextBoxColumn("Type");
    radGridView1.MasterTemplate.Columns.Add(typeColumn);

    radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
    this.radGridView1.Relations.AddSelfReference(this.radGridView1.MasterTemplate, "ID", "ParentID");

    AddNewRow("1", null, "Project", "USA", "Project");
    AddNewRow("2", "1", "Site 1", "New York", "Site");
    AddNewRow("3", "2", "Bldg 1", "Road 1", "Building");
    AddNewRow("4", "1", "Site 2", "New York", "Site");
    AddNewRow("5", "4", "Bldg 2", "Road 2", "Building");
    AddNewRow("20", "3", "Floor 1", "Road 20", "Floor");
    AddNewRow("30", "3", "Floor 2", "Road 30", "Floor");
    AddNewRow("40", "3", "Floor 3", "Road 40", "Floor");
}

public void AddNewRow(
    params object[] values)
{
    if (values.Length != radGridView1.Columns.Count)
        return;

    GridViewRowInfo newRow = radGridView1.Rows.AddNew();
    newRow.Cells[0].Value = values[0];
    newRow.Cells[1].Value = values[1];
    newRow.Cells[2].Value = values[2];
    newRow.Cells[3].Value = values[3];
    newRow.Cells[4].Value = values[4];
}

When you run the project you will notice that the last row is missing (AddNewRow("40", "3", "Floor 3", "Road 40", "Floor");). Please refer to the attached screenshots.

Workaround: use the Rows.Add(params) method instead:
0 comments