我有一個System.Windows.Forms.Treeview
控制與複選框構建權限樹,節點動態構建從數據庫記錄連同從代碼Allow Add
,Allow Delete
,Allow Update
後面的代碼添加的自定義節點。堆棧溢出異常
問題是當我嘗試從樹中檢索校驗節點時,我得到一個StackOverflowException
。
這裏是我的代碼:
List<tbl_JobPermission> SaveCheckedPermissions(int _JobID, System.Windows.Forms.TreeNodeCollection theNodes)
{
using (WFMDBEntities _DBContext = new WFMDBEntities())
{
tbl_JobPermission _JopPermissionHelperVar;
if (theNodes.Count > 0)
{
foreach (System.Windows.Forms.TreeNode aNode in theNodes.OfType<System.Windows.Forms.TreeNode>().Where(x => x.Checked == true))
{
int _tempJobPermID = int.Parse(aNode.Parent.Name);
if (aNode.Name.Contains('_'))
{
_JopPermissionHelperVar =
new tbl_JobPermission()
{
TblPremition = _tempJobPermID,
Tbljob = _JobID
};
if (aNode.Name.ToLower().Contains("add"))
{
_JopPermissionHelperVar.AllowNew = true;
}
else if (aNode.Name.ToLower().Contains("update"))
{
_JopPermissionHelperVar.AllowUpdate = true;
}
else if (aNode.Name.ToLower().Contains("delete"))
{
_JopPermissionHelperVar.AllowDelete = true;
}
if (!_JobPermissions.Contains(_JopPermissionHelperVar))
{
_JobPermissions.Add(_JopPermissionHelperVar);
}
}
else
{
_JopPermissionHelperVar =
new tbl_JobPermission()
{
TblPremition = int.Parse(aNode.Name),
Tbljob = _JobID
};
if (!_JobPermissions.Contains(_JopPermissionHelperVar))
{
_JobPermissions.Add(_JopPermissionHelperVar);
}
}
if (aNode.Nodes.Count > 0)
{
_JobPermissions.AddRange(SaveCheckedPermissions(_JobID, aNode.Nodes));
}
}
}
}
return _JobPermissions;
}
任何機會對於同一個節點在樹中出現多次?每個節點是否有一些唯一的標識符? – 2013-03-19 15:32:03
看看你是否在做http://msdn.microsoft.com/en-us/library/wwc698z7.aspx – TalentTuner 2013-03-19 15:43:02
@ShadowWizard每個節點都有一個唯一的名字 – user2139774 2013-03-19 16:36:14