Click here to Skip to main content
12,688,907 members (31,012 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB GDI+ tree VB.NET
Hi, im trying to draw a family tree. i will try to tell the concept
heres the main data table
|ID  | Name | ....| Spouse ID| Mother | Father |
|p01 | Jhon | ....| p02      |        |        |
|p02 | Mary | ....| P01      |        |        |
|p03 |rachel| ....|          |  ps02  |  ps01  |
|p04 | paul | ....|  p06     |  ps02  |  ps01
|p05 |jenny | ....|          |  ps02  |  ps01  |
|p06 |sarah | ....| P04      |  ps02  |  ps01  |

and i want my end result to be like
jhon ----- Mary
     |               |                      |
    Rachel           Paul --- Sarah         Jenny

get the image?

so the logic im trying to use here is that first draw a box which has the text "jhon" then another box with the name "Mary" then connect the two boxes with a line in between and continue such....

Dim x As Integer = 30
        Dim y As Integer = 30
        Dim wid As Integer = 165
        Dim hgt As Integer = 30
        Dim cus As String = Nothing
        e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias

        For i = 0 To Me.FamilyDataSet1.Persons.Rows.Count - 1
            e.Graphics.DrawRectangle(Pens.Black, x, y, wid, hgt)
            Dim big_font As New Font("Comic Sans MS", 20, FontStyle.Bold, GraphicsUnit.Pixel)
            e.Graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit
            e.Graphics.DrawString(FamilyDataSet1.Persons.Rows(i).Item(1), big_font, Brushes.Black, x, y)
            If cus = Nothing Then
                Continue For
            ElseIf cus = FamilyDataSet1.Persons.Rows(i).Item(8) Then
                x += 60
                Continue For
            End If
            cus = FamilyDataSet1.Persons.Rows(i).Item(8)

Familydataset1 is the dataset used
Persons is the data table
'item(1) and item(8) refers to Name feild and the spouse id feild respectively

what i am trying to do here is after drawing the box check who is the spouse of jhon then draw the box for jhons spouse "mary" by increasing the x cordinate of the jhons rectangle
im stuck from there, rather its all a bit tangled and infact im stuck from the begining itself, please help me.
tanqsss in advance :)

heres a more detailed tree
Posted 6-Sep-12 8:08am
Updated 7-Sep-12 3:21am
Not really clear what's the problem. Perhaps you need to explain more.
It's important to understand that what you call a "family tree" is a graph which is not a tree. The term "family tree" reflects historical paternalistic approach where the female role was majorly ignored... :-)
osmanjan 11-Nov-12 13:55pm
how i can to create database for the family tree project
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I actually did this years ago as a project for my father, but I don't have the source anymore. Basically what you have to do is this:
The key is to break down the solution into smaller bits that are manageable.

1) Decide how to draw a single node on the tree and build that object.
2) Decide how different nodes can be attached to each other and build that object.
3) Decide how the nodes are to be placed on the image based on their relationships.
4) Draw the image.
raaif 8-Sep-12 0:30am
That seems to be the exact logic im aiming for but how do i space the nodes in the form? and if possible give some code to start with
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I would recommend you take a different look at how your database is structured. I would recommend you go with Nested Set Model[^] structure. In combination with a PostreSQL DB (which supports recursive queries) it can be a very powerful solution.

I've implemented this once (actually it was BS degree, but it was a web app) using JavaEE, MySQL (had no idea about Postgres at the time) and JIT (Javascript library for trees / graphs / etc, operating on JSON-based data. You can find it here[^]).

Also, if you really want to try this with desktop and don't wanna go along with web, I'd recommend you take a look at the family tree WPF showcase app[^], the GUI and exec concepts are explained pretty well.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170113.4 | Last Updated 7 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100