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

Hierarchical Data Programmatically

2 Answers 116 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Shaggy
Top achievements
Rank 1
Shaggy asked on 15 Aug 2013, 08:08 AM
Hello,

im testing Telerik at the moment and come to an issue. I've searched your whole site for my problem, but i cant find any answer.

I'm trying to bind a hierarchical DataGrid to SQL, but i dont want to use TableAdapters. Instead of it i want to relaize it with a DataReader or something like that.

So my DataGrid loads the data very well, but when i try to make a template/relation nothing happens. There are still just the rows from the Parent, but the child data is missing. I've tried different ways with datasets, to refresh the DataGrid and many more, but nothing works. When i bind it to TableAdapters, it is working well! So here is my code - hope you can help me out...

 
Private Sub FrmKundenliste_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim objconn As New SqlConnection(My.Settings.SQL_V4)
    Dim rs As New SqlCommand("", objconn)
    Dim dr As DbDataReader
 
    rs.CommandText = "Select * from dbo.ApplicationMain"
 
    Try
        objconn.Open()
        dr = rs.ExecuteReader
 
        If dr.Read() Then
            RadGridView1.DataSource = dr
 
            Dim objconn_detail As New SqlConnection(My.Settings.SQL_V4)
            Dim rs_detail As New SqlCommand("", objconn_detail)
            Dim dr_detail As DbDataReader
 
            objconn_detail.Open()
            rs_detail.CommandText = "Select * from dbo.ApplicationDetail"
 
            dr_detail = rs_detail.ExecuteReader
 
            If dr_detail.Read() Then
                Dim template As New GridViewTemplate()
                template.DataSource = dr_detail
                RadGridView1.MasterTemplate.Templates.Add(template)
 
                Dim relation As New GridViewRelation(RadGridView1.MasterTemplate)
                relation.ChildTemplate = template
                relation.RelationName = "ApplicationDetails"
                relation.ParentColumnNames.Add("Id")
                relation.ChildColumnNames.Add("ApplicationId")
                RadGridView1.Relations.Add(relation)
            End If
        End If
     Catch ex As Exception
 
    End Try
End Sub

Greets,
Shaggy

2 Answers, 1 is accepted

Sort by
0
Shaggy
Top achievements
Rank 1
answered on 16 Aug 2013, 12:09 PM
Anyone has a idea? :-/
0
George
Telerik team
answered on 19 Aug 2013, 02:19 PM
Hello Zeljko,

Thank you for contacting Telerik Support.

To extract values from a data source using a SqlDataReader you can use the GridViewTemplate LoadFrom() method. For example:
If dr_detail.Read() Then
Dim template As New GridViewTemplate()
template.LoadFrom(dr_detail)

You can find more information at this documentation article: http://www.telerik.com/help/winforms/gridview-populating-with-data-binding-to-datareader.html.

I hope this information is helpful. If you need any further assistance, please let me know.
 
Regards,
George
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Shaggy
Top achievements
Rank 1
Answers by
Shaggy
Top achievements
Rank 1
George
Telerik team
Share this question
or