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

Binding to self referencing datatable

2 Answers 50 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Art
Top achievements
Rank 1
Art asked on 26 Feb 2011, 02:23 AM

I get a "Object reference not set to an instance of an object." error when I run this simple VB form

Imports Oracle.DataAccess.Client
Imports Telerik.WinControls.UI

Public Class frmTreeView

Private cmdTemp As New OracleCommand
Private dvTemp As DataView
Private dtTemp As New DataTable
Private daTemp As OracleDataAdapter
Private dsTemp As New DataSet
Private Sub frmTreeView_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"
    .Parameters.Clear()
    .Parameters.Add("out_rs", OracleDbType.RefCursor, DBNull.Value, ParameterDirection.Output)
  End With
  daTemp = New OracleDataAdapter(cmdTemp)
  dtTemp.Clear()
  daTemp.Fill(dtTemp)
  dsTemp.Tables.Add(dtTemp)

  tvGroups.DataSource = dsTemp
  tvGroups.DisplayMember = "group_name"
  tvGroups.ValueMember = "object_id"
  tvGroups.ParentIDMember = "PARENT_ID"  ' ERRORS ON THIS LINE
  tvGroups.DataMember = "dtTemp"

End Sub
End Class

It runs if I comment out the offending line, without hierarchical support. There is a field named "parent_id". Any suggestions?
My data source looks like this.  I need the child field to be group_id, but the valuemember to be object_id, if that's possible.

object_id  group_id  parent_id   group_name
100 100 nullFootball
101 101 100 Offense
103 103 101 O-Line
110 110 101 Tight Ends
111 111 101 Recievers
112 112 101 Backs
65234 0 112 Duckworth, Jeff
113 113 112 Tailbacks
114 114 112 Fullbacks
102 102 100 Defense

Later
Art

2 Answers, 1 is accepted

Sort by
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 28 Feb 2011, 12:03 PM
Hello Art,

I'd suggest that this may be because you have the Parent Id specified with incorrect casing (I.e PARENT_ID).

Please have a look at the sample below. It just assumes that there is a RadTreeView on a Form.

Public Class Form1
  
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.RadTreeView1.DataSource = GetDataTable()
        Me.RadTreeView1.DisplayMember = "Name"
        Me.RadTreeView1.ValueMember = "Id"
        Me.RadTreeView1.ParentIDMember = "ParentId"
    End Sub
  
    Private Function GetDataTable() 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", Nothing)
        table.Rows.Add(2, "Child 1", 1)
        table.Rows.Add(3, "Parent 2", Nothing)
        table.Rows.Add(4, "Child 2", 3)
        table.Rows.Add(5, "Child 3", 3)
  
  
        Return table
    End Function
End Class

Hope you find this helpful
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 01 Mar 2011, 04:59 PM
Hello,

Did this help? If so please remember to mark as answer. If you need further help, please let me know
thanks
Richard
Tags
Treeview
Asked by
Art
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Share this question
or