Tim Earl

Tim Earl

  • NA
  • 7
  • 12.7k

Displaying a recursive binary tree

Aug 16 2010 11:20 PM

Hi Guys,

I'm hoping someone out there can point me in the right direction with a task I need to do. I've spent the last few hours googling for solutions, I've learned a lot, but I'm missing a big piece of the picture still. I wouldn't say I'm a beginner, the bulk of my experience in programming has been with c# web applications, but I'm now building my first windows app using c# .Net 2 (2005).

I need to build a view which is basically a family tree. Each node could have 0, 1 or 2 child nodes. Individual nodes need to be able to have their text formatted independently from other nodes, for instance if I click a button only one particular node should have its text changed to red.  Individual nodes need to be able to handle click events. And nodes need to be connected with a plain black line, one line pointing to each child node, except for the last generation where the nodes are a one to one relationship and the nodes are in line with each other with just a single straight line in between them.

I know this can be done, I've seen it done before. I have a basic idea on how to build the data structure, but getting it to display on the screen has stumped me. I can't think of any existing controls that I could adapt for this except for the treeview control. But the way it shows the relationships won't suit the job. Unless that aspect of it can be customised? I've been told it's a recursive binary tree, there are plenty of sample classes on the web but they only handle the storing and searching of the data. I'm more concerned with displaying it in the family tree structure. I've included an example attached to this thread.

 

Thanks heaps in advance.

Tim

 
tree.JPG


Answers (6)