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

Save TreeView

3 Answers 91 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 11 Apr 2020, 10:04 AM

Hi.

How to save TreeView. I have no problem read data from database, like this:

 

   Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Me.TblSkydeHoldTableAdapter.Fill(Me.SkyttecenteretDataSet.tblSkydeHold)

        Me.RadTreeView1.DisplayMember = "name"
        Me.RadTreeView1.ParentMember = "pid"
        Me.RadTreeView1.ChildMember = "id"
        Me.RadTreeView1.ValueMember = "id"

        Me.RadTreeView1.DataSource = Me.GetSampleData()

    End Sub

    Private Function GetSampleData() As DataTable

        Dim dt As New DataTable()
        Dim dc As New DataColumn()
        dc.ColumnName = "id"
        dc.DataType = GetType(Integer)
        dt.Columns.Add(dc)
        Dim dc1 As New DataColumn()
        dc1.ColumnName = "name"
        dc1.DataType = GetType(String)
        dt.Columns.Add(dc1)
        Dim dc2 As New DataColumn()
        dc2.ColumnName = "pid"
        dc2.DataType = GetType(Integer)
        dt.Columns.Add(dc2)


        Me.TblSkydeHoldTableAdapter.Fill(Me.SkyttecenteretDataSet.tblSkydeHold)

        For Each dRow As DataRow In Me.TblSkydeHoldTableAdapter.GetData
            Dim dr As DataRow = dt.NewRow()
            dr(0) = dRow.Item("dr0")
            dr(1) = dRow.Item("dr1")
            dr(2) = dRow.Item("dr2")
            dt.Rows.Add(dr)
        Next

        Return dt

    End Function

 

But my problem starts when i want to save back to database. When i add a new node, the node have no parentmember value or valuemeber value. Is it possible to add those values automaticly when a new node is created?

Kindly Peter

 

 

3 Answers, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 15 Apr 2020, 08:20 AM

Hello Peter,

The provided code snippet is greatly appreciated. If your RadTreeView is bind to a DataTable, then all the changes that you are doing are automatically saved to the DataTable and they are "stacked" there until you push them to the database. You can do this by calling the Update method of the TableAdapter. More information is available at the following MSDN documentation:

I hope this information is useful. Do not hesitate to contact me if you have other questions.

Regards,
Nadya
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Peter
Top achievements
Rank 1
answered on 21 Apr 2020, 12:22 PM

Hi Nadya

I finnaly got it to work. I dont know why, but i did not used the id i the datatable as childmeber (stupid) ;-)

Thanx

Peter

0
Nadya | Tech Support Engineer
Telerik team
answered on 21 Apr 2020, 02:13 PM

Hello Peter,

I am glad that you managed to get it works. Should you have any other questions do not hesitate to ask.

Regards,
Nadya
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
Treeview
Asked by
Peter
Top achievements
Rank 1
Answers by
Nadya | Tech Support Engineer
Telerik team
Peter
Top achievements
Rank 1
Share this question
or