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

Create treeview with sqlCommand

9 Answers 147 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Amnad Lueaipang
Top achievements
Rank 1
Amnad Lueaipang asked on 09 Dec 2009, 10:36 AM
Hi Telerik support team
I have table and data as 

Table1

Field1 Field2
0001 100
0001 200
0001 300
0002 001
0002 002
0003 003

How I can create treeview with vb 2008 sqlcommand by datareader as

Treeview

-0001
  --100
  --200
  --300
-0002
  --001
  --002
  --003
Thanks,

Teddy

9 Answers, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 11 Dec 2009, 09:30 AM
Hi Amnad Lueaipang,

Thank you for writing. Please take a look at our online documentation. RadTreeView provides binding to related data with the aid of data relations. 

Also you can take a look at our Demo application. There you can see sample code for a RadTreeView bound to related data.

Please write again if you have other questions.

Regards,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Amnad Lueaipang
Top achievements
Rank 1
answered on 12 Dec 2009, 04:28 AM

Hi Victor ,
Thank you for your kind support but Could you please recommend on my code as below?
Sb =
New StringBuilder()
Sb.Remove(0, Sb.Length)
Sb.Append(
"SELECT * FROM TABLE")
Dim sqlShowData As String =Sb.ToString
With Command
.CommandType = CommandType.Text
.CommandText = sqlShowData
.Connection = Connnection
Dr = .ExecuteReader
If Dr.HasRows Then
Dt = New DataTable
Dt.Load(Dr)
rGrid.DataSource = Dt
Dr.Close()
End If
End With

Thanks

 

 

0
Victor
Telerik team
answered on 14 Dec 2009, 12:30 PM
Hi Amnad Lueaipang,

Thank you for writing. The code you provided binds RadGridView to a single data table. Please clarify whether you need to use RadGridView or RadTreeView with hierarchical data. If you need to use RadTreeView, you need to bind to a DataSet directly. The DataSet needs to have the proper relations set up for its tables and you need to instruct RadTreeView to use these relations as described in our online documentation.

I am looking forward to your reply.

Regards,

Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Amnad Lueaipang
Top achievements
Rank 1
answered on 15 Dec 2009, 09:07 AM

Hi victor,
There are difference way coding between online document and my could you please recommend on my code as below
sqlShowData="Select Field1,Field2 FROM TABLE"
Da =

New SqlDataAdapter(sqlShowData, Conn)
Ds =
New DataSet()
Da.Fill(Ds)
Waiting for you help.

amnad

 

 

 

 

 

 

0
Amnad Lueaipang
Top achievements
Rank 1
answered on 22 Dec 2009, 08:31 AM
Hi..Telerik team,
I have try to this way but still cannot.Any one can help me?Or telerik can use only datasource?
sqlShowData="SELECT F  FROM TABLE1;SELECT  C FROM TABLE2;"

Da =

New SqlDataAdapter(sqlShowData, Conn)
Ds =
New DataSet()
Da.Fill(Ds)
Ds.Tables(0).TableName =
"A"
Ds.Tables(1).TableName = "B"
Me.rtvDesc.RelationBindings.Add(New RelationBinding("F", Ds.Tables(0)))
Me.rtvDesc.RelationBindings.Add(New RelationBinding("C", Ds.Tables(1)))
Me.rtvDesc.RootRelationDisplayName = "File Name"
Me.rtvDesc.DataSource = Me.Ds

 

 

 

 

 

 

Thanks

 

0
Victor
Telerik team
answered on 28 Dec 2009, 08:24 AM
Hello Amnad Lueaipang,

In the code below you are adding relations to RelationBindings collection, however, does the DataSet have its the "F" and "the C" relations set up correctly? I am referring to these relations. I am looking forward to your reply.

Greetings,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Amnad Lueaipang
Top achievements
Rank 1
answered on 05 Jan 2010, 06:36 AM
Hi Victor,

Thanks for your help.I can solved this problem with code as below;
sqlShowData="SELECT F  FROM TABLE1;SELECT  C ,CC FROM TABLE2"
Me.rtvDesc.RelationBindings.Add(New RelationBinding("F", Ds.Tables(0)))
Me.rtvDesc.RelationBindings.Add(New RelationBinding("C", Ds.Tables(1))) 
Dim dc1 As DataColumn = Ds.Tables(0).Columns("F")
Dim dc2 As DataColumn = Ds.Tables(1).Columns("C")

Dataset.Relations.Add("Relation",dc1 ,dc2)

The binding to treeview like

Dim FileName As RelationBinding = New RelationBinding("C", Ds)

FileName.DisplayMember =

"CC"
Me.rtvDesc.RelationBindings.Add(FileName)
Me.rtvDesc.DisplayMember = "F"
Me.rtvDesc.RootRelationDisplayName = "File Name"
Me.rtvDesc.DataSource = Ds

My next question is Can telerik treeview display multi child node like.

-F
    --CC
        ----DD
        ----DD
        ----DD
    --CC
        ----DD
        ----DD
        ----DD
    --CC
        ----DD
        ----DD
        ----DD
-F
    --CC
        ----DD
        ----DD
    --CC
How ?

Waiting for your answer.

Thanks

amnad


 

 

 

 

 

 

0
Victor
Telerik team
answered on 07 Jan 2010, 04:17 PM
Hi Amnad Lueaipang,

I have attached a sample application which demonstrates the functionality that you described.

Please write again if you have further questions.

Best wishes,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Amnad Lueaipang
Top achievements
Rank 1
answered on 08 Jan 2010, 02:17 AM
Good sample.Thank you for your help.
Regard,
amnad 
Tags
Treeview
Asked by
Amnad Lueaipang
Top achievements
Rank 1
Answers by
Victor
Telerik team
Amnad Lueaipang
Top achievements
Rank 1
Share this question
or