2010-07-29 29 views
0

我创建了一个带有树视图的usercontrol。如果我在usercontrol的onload处理程序中添加节点,树视图将被填充。但在此之后(例如,我单击其父窗体中的按钮),树视图将不会刷新。我可以看到节点已在内存中更新,但它无法显示在屏幕上。我在添加节点后调用刷新/更新。任何建议表示赞赏。无法更新usercontrol内的树形视图

+0

我在添加节点后刷新或更新。 – leon 2010-07-29 13:04:19

回答

0

我根据你的描述一起进行了一个快速测试,它似乎画得很好。

的UserControl1

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ 
Partial Class UserControl1 
    Inherits System.Windows.Forms.UserControl 

    'UserControl overrides dispose to clean up the component list. 
    <System.Diagnostics.DebuggerNonUserCode()> _ 
    Protected Overrides Sub Dispose(ByVal disposing As Boolean) 
     Try 
      If disposing AndAlso components IsNot Nothing Then 
       components.Dispose() 
      End If 
     Finally 
      MyBase.Dispose(disposing) 
     End Try 
    End Sub 

    'Required by the Windows Form Designer 
    Private components As System.ComponentModel.IContainer 

    'NOTE: The following procedure is required by the Windows Form Designer 
    'It can be modified using the Windows Form Designer. 
    'Do not modify it using the code editor. 
    <System.Diagnostics.DebuggerStepThrough()> _ 
    Private Sub InitializeComponent() 
    Me.TreeView1 = New System.Windows.Forms.TreeView 
    Me.SuspendLayout() 
    ' 
    'TreeView1 
    ' 
    Me.TreeView1.Dock = System.Windows.Forms.DockStyle.Fill 
    Me.TreeView1.Location = New System.Drawing.Point(0, 0) 
    Me.TreeView1.Name = "TreeView1" 
    Me.TreeView1.Size = New System.Drawing.Size(150, 150) 
    Me.TreeView1.TabIndex = 0 
    ' 
    'UserControl1 
    ' 
    Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) 
    Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font 
    Me.Controls.Add(Me.TreeView1) 
    Me.Name = "UserControl1" 
    Me.ResumeLayout(False) 

    End Sub 
    Friend WithEvents TreeView1 As System.Windows.Forms.TreeView 

End Class 

Public Class UserControl1 

    Public Sub AddNewNode(ByVal text As System.String) 
    TreeView1.Nodes.Add(text) 
    End Sub 

End Class 

把用户控件的窗体上有一个按钮

Public Class Form1 

     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
     UserControl11.AddNewNode(Now.ToString) 
     End Sub 
    End Class 

如果看到合适的绘画以及再看看任何图形的父窗体处理然后在用户控件,然后用户控件内的控件。我们真的需要更多信息。

+0

谢谢你的帮助。我所做的是在父窗体中有一个用于加载文件的菜单项。树视图是基于文件构建的。每当加载新文件时,usercontrol的文件路径属性都将被更新。然后树视图将被重新创建。 ---------------------------------- mTreeView.Nodes.Clear(); mTreeView.BeginUpdate(); //根据文件内容逐个添加节点mTreeView.EndUPdate(); mTreeView.Refresh。 -------------------------------- – leon 2010-07-30 01:40:52

0

谢谢戴夫。我想到了。我把usercontrol两次误认为是我的表单(我不记得我是怎么做的)。我操作的那个在另一个之下。这就是为什么我看不到它。对不起,浪费你的时间。

+0

你没有浪费时间。很多时候只是通过讨论这个问题来解决问题。 – DaveWilliamson 2010-07-30 11:53:28