Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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)
        Next
 
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 Smile | :)
 
heres a more detailed tree
[^]
Posted 6-Sep-12 7:08am
raaif410
Edited 7-Sep-12 2:21am
v2
Comments
Sergey Alexandrovich Kryukov at 6-Sep-12 13:40pm
   
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... :-)
--SA
osmanjan at 11-Nov-12 13:55pm
   
how i can to create database for the family tree project
Rate this: bad
good
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.
  Permalink  
Comments
raaif at 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
good
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.
  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 354
1 Richard MacCutchan 320
2 OriginalGriff 255
3 Vinay Mistry 168
4 Jared Sanow 145
0 Sergey Alexandrovich Kryukov 5,939
1 OriginalGriff 4,885
2 CPallini 2,473
3 Abhinav S 1,507
4 Richard MacCutchan 1,437


Advertise | Privacy | Mobile
Web02 | 2.8.140814.1 | Last Updated 7 Sep 2012
Copyright © CodeProject, 1999-2014
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