none
Treeview in UserControl not updating RRS feed

  • Question

  •  

    I have a treeview usercontrol which is used in conjuction with a listbox

     

    Code Block

    public class appviewercontrol

    Inherits System.Windows.Forms.usercontrol

     

    list() as string

    treeview1 as treeview

    sub appviewercontrol_load

    treeview1 = new treeview

    end sub

    sub addToListForNextRepaint(list() as string)

    me.list = list

    end sub

    sub AppTreeViewer_Paint(sender As Object, e As PaintEventArgs) Handles MyBase.Paint

    for each item as string in list

    treeview1.add(new TreeNode(item))

    next item

    end sub

     

    end class

    Public class form1

    Inherits System.Windows.Forms.Form

    DIm appviewercontrol1 as appviewercontrol

     

    sub form1_load

    'Added controls at design view

    me.controls.add(listbox1)

    me.controls.add(appviewercontrol)

    end sub

    sub listbox1_click(sender, event) handles listbox1.click

    'Once the user clicks a item on the listbox

    dim list= getItemfromDB(Listbox1.SelectedItem)

     

    appviewercontrol1.addToListForNextRepaint(list)

    appviewercontrol1.update

    end sub

     

    end class

     

     

     

    my problem is when the appviewercontrol1 updates the nodes in it's paint method. Nothing happens on UPDATE. so when the user clicks another value in the listbox, nothing happens. It goes through the code but there is no update to the control to show the results from the DB.

     

     

    Tuesday, November 13, 2007 7:49 PM

Answers

  • Okay, I found the issue. 

    Code Block

    public class appviewercontrol

    Inherits System.Windows.Forms.usercontrol

     

    list() as string

    treeview1 as treeview

    sub appviewercontrol_load

    treeview1 = new treeview

    end sub

    sub addToListForNextRepaint(list() as string)

    me.list = list

    end sub

    sub AppTreeViewer_Paint(sender As Object, e As PaintEventArgs) Handles MyBase.Paint

    treeview1.beginupdate()

    trvApps.Nodes.Clear()

    for each item as string in list

    treeview1.add(new TreeNode(item))

    next item

    treeview1.endupdate()

    end sub

     

    end class

    Public class form1

    Inherits System.Windows.Forms.Form

    DIm appviewercontrol1 as appviewercontrol

     

    sub form1_load

    'Added controls at design view

    me.controls.add(listbox1)

    me.controls.add(appviewercontrol)

    end sub

    sub listbox1_click(sender, event) handles listbox1.click

    'Once the user clicks a item on the listbox

    dim list= getItemfromDB(Listbox1.SelectedItem)

     

    appviewercontrol1.addToListForNextRepaint(list)

    appviewercontrol1.update

    end sub

     

    end class

     

     

    Now the treeview will not clear the previously added nodes???? Even with the trvApps.Nodes.Clear() code.
    • Marked as answer by eBlackman Friday, December 12, 2008 7:27 PM
    Wednesday, November 14, 2007 2:30 PM