public void SessionPropertyChanged(SessionData Session, String PropertyName) { if (Session == null) { return; } if (PropertyName == "SessionName" || PropertyName == "ImageKey") { TreeNode Node = FindSessionNode(Session.SessionId); if (Node == null) { // It is possible that the session id was changed before the // session name. In this case, we check to see if we // can find a node with the old session id that is also associated // to the session data. Node = FindSessionNode(Session.OldSessionId); if (Node == null || Node.Tag != Session) { return; } } Node.Text = Session.SessionName; Node.Name = Session.SessionName; Node.ImageKey = Session.ImageKey; Node.SelectedImageKey = Session.ImageKey; bool IsSelectedSession = treeView1.SelectedNode == Node; ResortNodes(); if (IsSelectedSession) { // Re-selecting the node since it will be unselected when sorting. treeView1.SelectedNode = Node; } } else if (PropertyName == "SessionId") { TreeNode Node = FindSessionNode(Session.OldSessionId); if (Node == null) { // It is possible that the session name was changed before the // session id. In this case, we check to see if we // can find a node with the current session id that is also associated // to the session data. Node = FindSessionNode(Session.SessionId); if (Node == null || Node.Tag != Session) { return; } } try { isRenamingNode = true; SuperPuTTY.RemoveSession(Session.OldSessionId); SuperPuTTY.AddSession(Session); } finally { isRenamingNode = false; } } }