한 가지 방법이 될 수 사용하십시오 List<data>
:
여기
// requires declaration of : using System.Windows.Forms;
// sample data class
public class data
{
public string Name;
public int ID;
}
public class XTreeNode : TreeNode
{
List<data> theData = new List<data>();
public XTreeNode(string theNodeID)
{
this.Text = theNodeID;
}
public void addData(data newData)
{
theData.Add(newData);
}
}
가의 인스턴스를 구축 무엇을 (우아한되지 않음) 샘플입니다 위의 데이터 구조는 (A의 WinForm에)과 같습니다 당신이 양식에으로 TreeView1 '라는 이름의 트 리뷰,이 가정
XTreeNode currentNode;
data currentData;
for (int i = 0; i < 10; i++)
{
// create the node and add it to the 'treeView1
currentNode = new XTreeNode(i.ToString());
treeView1.Nodes.Add(currentNode);
// add some data entries to the List<data> of the derived TreeNode
currentData = new data {Name = "one", ID = 100};
currentNode.addData(currentData);
currentData = new data { Name = "two", ID = 200 };
currentNode.addData(currentData);
currentData = new data { Name = "three", ID = 300 };
currentNode.addData(currentData);
// sample of adding a child node
currentNode.Nodes.Add(new XTreeNode((i * 100).ToString()));
}
의 질문에 대한 어떻게 요 각 노드와 연결된 List<data>
을 시각적으로 표시합니다. 일반적인 방법은 TreeView를 ListView와 결합하고 위치와 항목 높이를 동기화하는 것입니다. List<data>
을 해당 TreeNode와 동일한 "행"에 표시하십시오.
물론 컨트롤과 완전히 독립적 인 노드 및 NodeCollection 엔티티를 구현할 수 있습니다.이 예제는 .NET 컨트롤을 사용하는 데이터 케이스 및 프리젠 테이션 메커니즘으로 사용되는 혼합 사례를 보여줍니다.
지난 수년간 유지 관리되고 업데이트되고 확장 된 TreePro/ListView 조합의 훌륭한 예가 있습니다 : Phillip Piper 's : "A Much Easier to Use ListView", 처음 게시 된 2006 년, 최종 업데이트 : 2009 년 10 월 : 기능이 풍부하여 if 우호적으로, imho, 상용 구성 요소와 비교.
핵심 질문은 다음과 같습니다. 코드에서 "순수 데이터 구조"를 정의하는 대답을 찾고 있습니까? 기존 WinForms 컨트롤과 독립적으로 또는 세 번째. 파티 제어. 또는 기존 또는 3 번째 질문을 사용하는 답변을 기꺼이 받아 들일 수 있습니까? 파티 제어? Lokey의 대답에 대한 내 의견을 참조하십시오. – BillW