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
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
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
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?
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
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