Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27180

VS 2008 [RESOLVED] Treeview refresh...sorry!!

$
0
0
Code:

    Private Sub LoadTreeView()
        Dim letter_nodes(25) As TreeNode
        Dim letter As Integer
        Dim row_num As Integer
        Dim data_row As DataRow
        Dim record_node As TreeNode
        Dim first_node As TreeNode
        Dim combined_name As String

        ' Make the letter nodes.
        trvContacts.Nodes.Clear()

        For letter = 0 To 25
            letter_nodes(letter) = trvContacts.Nodes.Add(Chr(letter + Asc("A"c)))
        Next letter

        ' Add a TreeNode column to the table.

        ds.Tables("Mydatabase").Columns.Add("TreeNode", GetType(TreeNode))

        ' Add each name entry.
        For row_num = 0 To ds.Tables("Mydatabase").Rows.Count - 1
            data_row = ds.Tables("Mydatabase").Rows(row_num)
            combined_name = data_row.Item("SURNAME") & ", " & data_row.Item("FIRST_NAME")
            letter = Asc(combined_name.Substring(0, 1).ToUpper) - Asc("A"c)
            record_node = letter_nodes(letter).Nodes.Add(combined_name)
            record_node.Tag = data_row
            data_row.Item("TreeNode") = record_node
            If row_num = 0 Then first_node = record_node
        Next row_num

        ' Make a <New> node.
        ' m_NewNode = trvContacts.Nodes.Add("<New>")

        ' Select the first node.
        'trvContacts.SelectedNode = first_node

        ' Accept the changes (setting the TreeNode field)
        ' so we don't think there are changes yet.
        trvContacts.Sort()
        ds.AcceptChanges()
    End Sub

So that's the code which populates my treeview. It's filled from a connection in the code, if that makes sense. It populates a series of textboxes based on the node clicked. I also have buttons coded for updates, deletes and saves. These work well but aren't reflected in treeview. I think every website I've looked at over the past few days mentions that it won't be. So what I'm using is...

Code:

        ds.AcceptChanges()
        ds.Reset()
        main_Load(Me, Nothing)

This obviously works but it collapses all my nodes (not a big deal really). I'm writing this as I don't think this is the best solution and was wondering if there is something better that doesn't require the form to be reloaded but can simply 'refresh/reload'. If I use "loadtreeview()" in the button click I get the error "A column named 'TreeNode' already belongs to this DataTable.".

Any ideas or thoughts?

Viewing all articles
Browse latest Browse all 27180

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>