Binding to self referencing datatable

3 posts, 1 answers
  1. Art
    Art avatar
    54 posts
    Member since:
    Dec 2010

    Posted 25 Feb 2011 Link to this post

    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.Add("out_rs", OracleDbType.RefCursor, DBNull.Value, ParameterDirection.Output)
      End With
      daTemp = New OracleDataAdapter(cmdTemp)

      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


  2. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 28 Feb 2011 Link to this post

    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
  3. DevCraft R3 2016 release webinar banner
  4. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 01 Mar 2011 Link to this post


    Did this help? If so please remember to mark as answer. If you need further help, please let me know
Back to Top