Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1010
Binding to TreeGridModel,
posted

When binding to a TreeGridModel, I'm receiving a NullReferenceException. Object reference not set to an instance of object exception. 

In my view I'm binding to a TreeGridModel..

@model XNamespace.Models.XModel

<div>@(Html.Infragistics().TreeGrid(Model.XTreeGridModel)) </div>

XTreeGridModel is basiscally a property in my XModel class to return a TreeGridModel.

In my XModel class, I'm constructing TreeGridModel

// Create
m_treeGridModel = new TreeGridModel();

// Set properties
m_treeGridModel.ID = "treeGridModel";
m_treeGridModel.AutoGenerateColumns = false;
m_treeGridModel.AutoGenerateLayouts = false;
//m_treeGridModel.PrimaryKey = ColumnIndex.StrategyInstId.ToString();
//m_treeGridModel.ForeignKey = ColumnIndex.PID.ToString();
m_treeGridModel.PrimaryKey = "ID";
m_treeGridModel.ForeignKey = "PID";
m_treeGridModel.LoadOnDemand = false;
m_treeGridModel.InitialExpandDepth = 1;
m_treeGridModel.Columns = new List<GridColumn>();
m_treeGridModel.Columns.Add(new GridColumn() { HeaderText = "ID", Key = "ID", DataType = "number", Width = "0%", Hidden = true });
m_treeGridModel.Columns.Add(new GridColumn() { HeaderText = "PID", Key = "PID", DataType = "number", Width = "0%", Hidden = true });
m_treeGridModel.Columns.Add(new GridColumn() { HeaderText = "Name", Key = "Name", DataType = "string", Width = "10%" });
m_treeGridModel.Columns.Add(new GridColumn() { HeaderText = "Date Modified", Key = "DateModified", DataType = "string", Width = "10%" });
m_treeGridModel.Columns.Add(new GridColumn() { HeaderText = "Type", Key = "Type", DataType = "string", Width = "10%" });
m_treeGridModel.Columns.Add(new GridColumn() { HeaderText = "Size", Key = "Size", DataType = "string", Width = "10%" });

XData q1 = new XData();  // XData is a class with ID, PID, Name, DateModified, Type and Size members
q1.ID = 1;
q1.PID = -1;
q1.Name = "XName";
q1.DateModified = "XDM";
q1.Type = "XType";
q1.Size = "323";

m_xDataList.Add(q1);

XData q2 = new XData();
q2.ID = 2;
q2.PID = -1;
q2.Name = "XName";
q2.DateModified = "XDM";
q2.Type = "XType";
q2.Size = "323";

m_xDataList.Add(q2);

m_treeGridModel.DataSource = m_quoteDataList.AsQueryable();

If I comment out the binding statement, I'm able to see the empty TreeGrid. But, when I uncomment the above statement, I get a null reference exception.