开发者

What format does the TreeView control need in order to create a Tree?

I have a simple table in my database called Department. In it there's a column called ParentDepartmentID that is a self referential foreign key ID. Here's an example of the data I have for testing purposes:

What format does the TreeView control need in order to create a Tree?

As you can see, Departments: Diagnostics and XRay are children to Office of Chancellor. And Laboratories is child to Diagnostics.

This is how I retrive an IQueryable<Department> collection to my application using Entity Framework:

private DocumentsEntities db = new DocumentsEntities();

public IQueryable<Department> FindAllDepartments()
{
   retu开发者_运维知识库rn db.Departments;
}

What format does the TreeView control require in order to parse and display the tree hierarchy correctly? Thank you.


I'm afraid that the winforms treeview is not designed so that you can send in parent/child relationship as many, more modern tree views do. You'll have to parse it yourself, creating and adding TreeNode objects (see for example here). In practice, I wouldn't recommend using this, companies have better things to do than implementing this kind of stuff again and again. Rather, consider buying a control library, e.g. from DevExpress or Telerik.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜