Hierarchical Data Programmatically

3 posts, 0 answers
  1. Shaggy
    Shaggy avatar
    8 posts
    Member since:
    Jul 2013

    Posted 15 Aug 2013 Link to this post

    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. Shaggy
    Shaggy avatar
    8 posts
    Member since:
    Jul 2013

    Posted 16 Aug 2013 Link to this post

    Anyone has a idea? :-/
  3. George
    Admin
    George avatar
    500 posts

    Posted 19 Aug 2013 Link to this post

    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 >>
Back to Top