I have a TreeView with a bunch of nodes. I have some code that is supposed to modify t开发者_如何转开发he label, however it has no effect. When i step through it in the debugger, I see that the the .Text property has the correct value, but it is not reflected in the GUI. I'm not sure what I'm doing wrong. Here's the code:
Public Class MyClass
Inherits TreeNode
Public Property Record As SomeTypeThatDefinesADataField
Get ...
Set ...
End Property
Public Sub ChangeLabel()
If Me.TreeView IsNot Nothing Then
Me.TreeView.LabelEdit = True
If Not Me.IsEditing Then
Me.BeginEdit()
End If
Me.Text = Me.Record.Data("Name")
Me.EndEdit(False)
Me.TreeView.LabelEdit = False
End If
End Sub
End Class
Public Class MyClassThatContainsTheTreeView
Private Sub trvRecords_AfterLabelEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.NodeLabelEditEventArgs) Handles trvRecords.AfterLabelEdit
Me.treeView.Refresh()
End Sub
End Class
It doesn't make sense to jump through the LabelEdit hoops, just change the Text property. The typical diagnostic of seeing the property change in the debugger but not on the screen is that you got the wrong object reference. Changing a copy that's not visible instead of the one that the user is looking at. It is not at all clear how you got the TreeView or Form reference in this code snippet, review your code for this.
精彩评论