This is a migrated thread and some comments may be shown as answers.

Simple binding to a self relating datatable

8 Answers 126 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Art
Top achievements
Rank 1
Art asked on 08 Apr 2011, 11:29 PM
This is crazy.

A simple form, with one control, a radtreeview, opens a data table and attempts to bind it to the control. 

Public Class frmTree2
    Private cmdTemp As New OracleCommand
    Private dvTemp As DataView
    Private dtTemp As New DataTable
    Private daTemp As OracleDataAdapter

    Private Sub frmTree2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        With cmdTemp
            .CommandType = CommandType.StoredProcedure
            .Connection = db.oraCn
            .CommandText = "badgernet.web_read_util.group_tree_dept"
            .Parameters.Clear()
            .Parameters.Add("out_rs", OracleDbType.RefCursor, DBNull.Value, ParameterDirection.Output)
        End With
        daTemp = New OracleDataAdapter(cmdTemp)
        dtTemp.Clear()
        daTemp.Fill(dtTemp)
        Me.RadTreeView1.DataSource = dtTemp
        Me.RadTreeView1.DisplayMember = "group_name"
        Me.RadTreeView1.ParentIDMember = "p_id"
        Me.RadTreeView1.DataMember = "g_id"
        Me.RadTreeView1.ValueMember = "id"
    End Sub
End Class


That's the whole form.

Table contents
id     g_id  p_id   group_name

500    10    -1     Athletic Dept
780    780    10    May, Keith
141    141    10    Chelesvig, Bart
142    142    10    Clark, Christopher

It will display the name field, but no hierarchy - if I comment out the valuemember line. If I leave that in there I get an "InvalidCastException" - Unable to cast object of type 'System.Windows.Forms.RelatedPropertyManager' to type 'System.Windows.Forms.CurrencyManager'.

I took this code right out of your (so-called) documentation, but it doesn't even come close to working. Any help would be greatly appreciated.

Later
Art

8 Answers, 1 is accepted

Sort by
0
Sonya L
Top achievements
Rank 1
answered on 12 Apr 2011, 04:09 PM
Art, 
Try changing the order that you are setting these properties.  I had a similar problem, but I don't remember the error.  I ended up setting them in this order:

ParentIDMember
DisplayMember
ValueMember
DataSource
DataMember

Sonya
0
Richard Slade
Top achievements
Rank 2
answered on 12 Apr 2011, 04:25 PM
Hello Art, 

Here is a sample using the latest version. 

Public Class Form1
  
    Public Sub New()
        InitializeComponent()
  
        Me.RadTreeView1.ShowLines = True
  
        Me.RadTreeView1.DataSource = GetTable()
        Me.RadTreeView1.DisplayMember = "Name"
        Me.RadTreeView1.ParentMember = "ParentId"
        Me.RadTreeView1.ChildMember = "Id"
        Me.RadTreeView1.ValueMember = "Id"
  
        Me.RadTreeView1.ExpandAll()
    End Sub
  
    Function GetTable() As DataTable
        Dim table As New DataTable
        table.Columns.Add("Id", GetType(Integer))
        table.Columns.Add("Name", GetType(String))
        table.Columns.Add("ParentId", GetType(Integer))
  
        table.Rows.Add(1, "Parent 1", 0)
        table.Rows.Add(2, "Parent 2", 0)
        table.Rows.Add(3, "Parent 3", 0)
        table.Rows.Add(4, "Parent 4", 0)
  
        table.Rows.Add(5, "Child 1", 1)
        table.Rows.Add(6, "Child 2", 1)
        table.Rows.Add(7, "Child 3", 3)
        table.Rows.Add(8, "Child 4", 4)
        Return table
    End Function
  
  
  
End Class

Please let me know if this works for you, and indeed if you need further help
thanks
Richard 

0
Art
Top achievements
Rank 1
answered on 12 Apr 2011, 06:08 PM
Sonya
Nope - now I get A first chance exception of type 'System.NullReferenceException' occurred in Telerik.WinControls.UI.dll at the datasource line.

Any other suggestions?
0
Richard Slade
Top achievements
Rank 2
answered on 12 Apr 2011, 07:19 PM
Have you tried the example, Art?
0
Sonya L
Top achievements
Rank 1
answered on 12 Apr 2011, 07:22 PM
I'm not sure your DataMember assignment is right.  Try not setting that, or try Richard's example (if you are on q1 2011).
0
Jack
Telerik team
answered on 13 Apr 2011, 04:43 PM
Hello Art,

It seems that you are using an old version of RadControls for WinForms. I recommend that you try our latest release - Q1 2011. It contains many improvements and addresses lot of issues. Please, check also the solution suggested by Richard. If the issue continues to appear, send us your application and we will investigate it in detail.

Should you have any questions, do not hesitate to ask.

Regards,
Jack
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Art
Top achievements
Rank 1
answered on 13 Apr 2011, 04:46 PM
I haven't tried that example because I'm still on 2010Q3.  Our apps guy is going to downlaod 2011Q1 in a day or so and I'll get back to it then and let you know.  Thanks.
0
Jack
Telerik team
answered on 14 Apr 2011, 08:43 AM
Hello Art,

Thank you for this update. Please contact us if the issue continues to appear. We will be glad to help if you have any other questions.
 
Greetings,
Jack
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Treeview
Asked by
Art
Top achievements
Rank 1
Answers by
Sonya L
Top achievements
Rank 1
Richard Slade
Top achievements
Rank 2
Art
Top achievements
Rank 1
Jack
Telerik team
Share this question
or