나는 모든 부모의 TreeNode에 같은 ContextMenuStrip을 추가 다른 수준의 TreeNode
와 트 리뷰를하고 난 돈을 그 ContextMenuStrip을을 열고ToolStripMenuItem 클릭 핸들러에서 ContextMenuStrip을 연 TreeNode를 가져 오는 방법이 있습니까?
private void btn_delete_all_objects_Click(object sender, EventArgs e)
{
ToolStripMenuItem tsmi = (ToolStripMenuItem)sender; //that way i receive button "Delete all"
ContextMenuStrip cms = (ContextMenuStrip)tsmi.Owner; //this is ContextMenuStrip where this button...
TreeView tw = (TreeView)cms.SourceControl; //i can get TreeView :(BUT I NEED TreeNode!
TreeNode tn = tw.SelectedNode; //bah... if i select some of child nodes, then right click to open menu on parent, selected node is still that child
}
그리고 난 "을 모두 삭제"를 눌러 모든 자식의 TreeNode를 삭제 가능성을 얻으려면 사용자가 해당 메뉴를 열기 위해 클릭 한 TreeNode를 가져 오는 방법을 알 수 없음
아이디어가 있으십니까?
당신은 노드를 가져옵니다. 이 노드를 변수에 저장하면 이벤트 핸들러에서이를 읽습니다. – Tomtom
어느쪽으로? contextMenuStrip1_Opening 및 contextMenuStrip1_Opened ** 보낸 사람 **은 여전히 ContextMenuStrip이지만 TreeNode가 아닙니다. – Kosmos
treenode를 마우스로 클릭하면 treenode가 생깁니다. 이 유는 변수에 저장할 수 있습니다. 컨텍스트 메뉴에서 항목을 클릭하면 u가 노드를 포함하는 저장된 변수를 읽을 수 있습니다. – Tomtom