Simple binding to a self relating datatable

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

    Posted 08 Apr 2011 Link to this post

    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
  2. Sonya L
    Sonya L avatar
    36 posts
    Member since:
    Dec 2009

    Posted 12 Apr 2011 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 12 Apr 2011 Link to this post

    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 

  5. Art
    Art avatar
    54 posts
    Member since:
    Dec 2010

    Posted 12 Apr 2011 Link to this post

    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?
  6. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 12 Apr 2011 Link to this post

    Have you tried the example, Art?
  7. Sonya L
    Sonya L avatar
    36 posts
    Member since:
    Dec 2009

    Posted 12 Apr 2011 Link to this post

    I'm not sure your DataMember assignment is right.  Try not setting that, or try Richard's example (if you are on q1 2011).
  8. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 13 Apr 2011 Link to this post

    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
  9. Art
    Art avatar
    54 posts
    Member since:
    Dec 2010

    Posted 13 Apr 2011 Link to this post

    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.
  10. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 14 Apr 2011 Link to this post

    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
Back to Top
UI for WinForms is Visual Studio 2017 Ready