扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
Private Sub dbTreeView_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles MyBase.AfterSelect If e.Node Is Nothing Then Exit Sub '定位到position cm.Position = GetPosition(CType(e.Node, myTreeNode).Value) If AllowEdit Then oldNode = e.Node oldPos = cm.Position End If End Sub |
2、在其它绑定控件改变了数据源后,更新树结点,这个工作在触发CurrencyManager的PositionChanged事件时进行。
Public Sub cm_PositionChanged(ByVal sender As Object, ByVal e As System.EventArgs) If CType(Me.SelectedNode, myTreeNode).Value <> GetValue(cm.Position) Then Debug.WriteLine("Current node isn't correct point to currencymanager.position!") Me.SelectedNode = FindNodeByValue(GetValue(cm.Position), Me.Nodes) End If If AllowEdit Then If Me.SelectedNode Is Nothing AndAlso cm.Position = cm.Count - 1 Then '当新增记录时,新增树结点 If CType(cm.Current, DataRowView).IsNew Then Me.SelectedNode = AddNode(cm.Position) Exit Sub End If End If If Not oldNode Is Nothing Then If CType(oldNode, myTreeNode).Value = GetValue(oldPos) Then '更新老结点 oldNode.Text = GetDisplay(oldPos) Else End If End If End If End Sub |
使用dbTreeView
程序运行后界面如下:
相关代码请参见源程序,这里不做详述,需要注意的是删除操作并没有删除子结点,只是删除当前结点而已,删除子结点的工作应该在存储过程中递归实现,而不应放在前端。