نقل قول نوشته شده توسط tooraj_azizi_1035 مشاهده تاپیک
اگر قرار است خروجی رو در TreeView نشون بدید در این لینک گفته شده فقط فایل سورس رو دانلود کنید:
http://www.codeproject.com/Articles/...ng-HierarchyID
با سلام

دوست عزیز

یک مقدار کار سخت شد.

حالا بزارید به حساب اینکه ما لقمه حاضر و آماده می خواهیم.

من روی کدها مشکل دارم:


private void LoadTreeSQLHierarchy(TreeView oTV, DataTable oTable, string sKeyField, string sTextField)
{
oTV.Nodes.Clear();


TreeNode oNode;


//get an empty id to get the top node
SqlHierarchyId iID = new SqlHierarchyId();


//filter the table using linq. See blog for equals()/== issue
EnumerableRowCollection<DataRow> query = from TNodes in oTable.AsEnumerable()
where TNodes.Field<SqlHierarchyId>(sKeyField).GetAncesto r(1).Equals(iID)
select TNodes;


//convert to a dataview because I am comfortable with a dataview.
DataView oDV = query.AsDataView();
if (oDV.Count == 1)
{
//load up a node
oNode = new TreeNode(oDV[0][sTextField].ToString());


//put the datarow into the tag property
oNode.Tag = oDV[0].Row;


//load up the children
LoadNodeSQLHierarchy(oNode, oTable);


//add the node hierarchy to the tree
oTV.Nodes.Add(oNode);
}
}


/// <summary>
/// Load up the children
/// </summary>
/// <param name="oParent">parent node</param>
/// <param name="oTable">datatable with the nodekey</param>
private void LoadNodeSQLHierarchy(TreeNode oParent, DataTable oTable)
{


// make sure there are no existing nodes in case this is a reload of the node
oParent.Nodes.Clear();


//get the nodekey from the tag property of the parent node
SqlHierarchyId iID = new SqlHierarchyId();
DataRow oRow = (DataRow)oParent.Tag;
iID = (SqlHierarchyId)oRow["NodeKey"];


//filter the datatable on for the children
EnumerableRowCollection<DataRow> query = from order in oTable.AsEnumerable()
where order.Field<SqlHierarchyId>("NodeKey").GetAncestor (1).Equals(iID)
select order;


//add the nodes to the tree
DataView oDV = query.AsDataView();
foreach (DataRowView oDR in oDV)
{
TreeNode oNode = new TreeNode(oDR["Element"].ToString());
oNode.Tag = oDR.Row;


LoadNodeSQLHierarchy(oNode, oTable);
oParent.Nodes.Add(oNode);
}


}


نمی توانم در کشان کنم.

اگر باید این قسمت از تاپیک را در تالار سی شارپ مطرح کنم، به من بگید.

================================================== ============

این جوری کار سخت شد.

یعنی نمی توانم درکش که چطوری این کار را انجام دهد کنم.

همین که پایگاه داده هاش XML هست

و

چند تا ستون داره که کار هر ستون چه چیزی هست.

خلاصه نمی توانم روند کارش را متوجه بشم.


اما

آن روشی را که خودم پیدا کردم راحتر متوجه شد.

با تشکر