Completed
Last Updated: 30 Jun 2014 12:28 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 23 Jun 2014 14:44
Category: GridView
Type: Bug Report
0
FIX. RadGridView - NullReferenceException when dragging columns in the child template
To reproduce:
Use the code snippet below:

static DataSet ds;

public form1()
{
    InitializeComponent(); 
    GridviewStyling(radGridView1);
    ds = PrepareDataset();
    BuildGrid();

    //Set_Hierarchy();
    for (int i = 0; i < radGridView1.Templates.Count; i++)
        GridviewTemplateStyling(radGridView1.Templates[i]);

    this.radGridView1.TableElement.PageViewMode = PageViewMode.ExplorerBar;
    this.radGridView1.ViewCellFormatting += radGridView1_ViewCellFormatting;
}

       void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
    GridDetailViewCellElement detailCell = e.CellElement as GridDetailViewCellElement;
    if (detailCell != null)
    {
        GridViewHierarchyRowInfo hierarchyRow = (GridViewHierarchyRowInfo)((GridViewDetailsRowInfo)detailCell.RowInfo).Owner;
        detailCell.PageViewElement.Header.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
        RadPageViewElement el = detailCell.PageViewElement as RadPageViewExplorerBarElement;
        if (el != null)
        {
            for (int i = 0; i < el.Items.Count; i++) // detailCell.PageViewElement.Items.Count
            {
                RadPageViewItem item = detailCell.PageViewElement.Items[i];
                GridViewInfo viewInfo = hierarchyRow.Views[i];
                item.MaxSize = new Size(0, 1);
                item.Visibility = Telerik.WinControls.ElementVisibility.Hidden;
                if (viewInfo.ChildRows.Count != 0)
                {
                    item.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
                }
            }
        }
    }
}

private DataSet PrepareDataset()
{
    Random r = new Random();
    DataSet ds = new DataSet("DS");

    //snir
    DataTable dtFirst = new DataTable("Snir");
    dtFirst.Columns.Add("pId", typeof(int));
    dtFirst.Columns.Add("Col1", typeof(int));
    dtFirst.Columns.Add("Col", typeof(string));
    dtFirst.Columns.Add("Col3", typeof(int));
    dtFirst.Columns.Add("Col4", typeof(string));
    for (int i = 0; i < 5; i++)
        dtFirst.Rows.Add(1, i, "snirsnirsnir" + r.Next(0, 100).ToString(),
            r.Next(0, 35), "snir" + r.Next(0, 100).ToString());

    // jenny
    DataTable dtSecond = new DataTable("Jenny");
    dtSecond.Columns.Add("pId", typeof(int));
    dtSecond.Columns.Add("Col1", typeof(int));
    dtSecond.Columns.Add("Col2", typeof(string));
    dtSecond.Columns.Add("Col3", typeof(int));
    dtSecond.Columns.Add("Col4", typeof(string));
    dtSecond.Columns.Add("Col5", typeof(string));
    dtSecond.Columns.Add("Col6", typeof(string));
    for (int i = 0; i < 5; i++)
        dtSecond.Rows.Add(2, i, "CnC" + r.Next(0, 100).ToString(),
            r.Next(0, 35), "jenny" + r.Next(0, 100).ToString(), "col5", "col6");

    //index
    DataTable table1 = new DataTable("Index");
    table1.Columns.Add("TableId", typeof(int));
    table1.Columns.Add("TableName", typeof(string));
    table1.Columns.Add("UpdateType", typeof(int));
    table1.Rows.Add(1, dtFirst.TableName, r.Next(0, 3));
    table1.Rows.Add(2, dtSecond.TableName, r.Next(0, 3));

    ds.Tables.AddRange(new DataTable[] { table1, dtFirst, dtSecond });

    return ds;
}

private void BuildGrid()
{
    // bind the master template
    this.radGridView1.DataSource = ds;
    this.radGridView1.DataMember = "Index";

    //templates
    GridViewTemplate template1 = new GridViewTemplate();
    template1.DataSource = ds.Tables[1];
    template1.Columns[0].IsVisible = false;
    template1.EnableHierarchyFiltering = false;
    template1.ShowGroupedColumns = false;

    radGridView1.Templates.Add(template1);

    GridViewTemplate template2 = new GridViewTemplate();
    template2.DataSource = ds.Tables[2]; // 1:snir   // 2:jenny
    radGridView1.Templates.Add(template2);
    template1.AllowDragToGroup = false;

    //relations
    GridViewRelation relation1 = new GridViewRelation(radGridView1.MasterTemplate);//, template2);
    relation1.RelationName = "myRelation1";
    relation1.ChildTemplate = radGridView1.Templates[0];
    relation1.ChildColumnNames.AddRange(new string[] { "pId" });
    relation1.ParentColumnNames.Add("TableId");
    radGridView1.Relations.Add(relation1);

    GridViewRelation relation2 = new GridViewRelation(radGridView1.MasterTemplate);//, template2);
    relation2.RelationName = "myRelation2";
    relation2.ChildTemplate = radGridView1.Templates[1];
    relation2.ChildColumnNames.AddRange(new string[] { "pId" });
    relation2.ParentColumnNames.Add("TableId");
    radGridView1.Relations.Add(relation2);
}

private void GridviewStyling(RadGridView rgv)
{
    //radGridView1 styling
    rgv.AllowAddNewRow = false;
    rgv.EnableGrouping = false;
    rgv.AllowDragToGroup = false;

    rgv.AllowDrop = false;
    rgv.AllowEditRow = false;
    rgv.AllowDrop = false;
    rgv.AllowRowResize = false;

    rgv.AllowColumnResize = false;
    rgv.AutoExpandGroups = true;
    rgv.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
    rgv.EnableCustomGrouping = false;

    rgv.ShowColumnHeaders = true;
    rgv.ShowRowHeaderColumn = false;
    rgv.ShowGroupPanel = false;
}

private void GridviewTemplateStyling(GridViewTemplate gvt)
{
    //template styling
    gvt.AllowAddNewRow = false;
    gvt.Columns[0].IsVisible = false;
    gvt.ShowChildViewCaptions = false;

    gvt.AllowDragToGroup = false;
    gvt.AllowRowResize = false;
    gvt.AllowColumnResize = false;
    gvt.AutoExpandGroups = true;

    gvt.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
    gvt.ShowRowHeaderColumn = false;
    gvt.ShowColumnHeaders = true;
}

private string GetEnumString(int n)
{
    switch (n)
    {
        case (int)TableUpdateModeEnum.INSERT:
            return "INSERT";
        case (int)TableUpdateModeEnum.UPDATE:
            return "UPDATE";
        case (int)TableUpdateModeEnum.UPDATE_OR_INSERT:
            return "UPDATE/DELETE";
        case (int)TableUpdateModeEnum.DELETE_OR_INSERT:
            return "INSERT/DELETE";
        default:
            return "";
    }
}

public enum TableUpdateModeEnum
{
    [Description("Snir")]
    INSERT = 0,
    [Description("Liraz")]
    UPDATE_OR_INSERT = 1,
    [Description("Jenny")]
    UPDATE = 2,
    [Description("Tsuria")]
    DELETE_OR_INSERT = 3
};        

Scenario:
1.Expand a master row.
2.Start dragging columns from the child template.
3.When your are dragging over the thick border , the exception occur.
0 comments