在双击事件中,treeView1.SelectedNode.BeginEdit();
然后,在AfterLabelEdit事件中
if (e.Label != null)
{
if(e.Label.Length > 0)
{
if (e.Label.IndexOfAny(new char[]{'@', '.', ',', '!'}) == -1)
{
// Stop editing without canceling the label change.
e.Node.EndEdit(false);
}
else
{
/* Cancel the label edit action, inform the user, and
place the node in edit mode again. */
e.CancelEdit = true;
MessageBox.Show("Invalid tree node label.\n" +
"The invalid characters are: '@','.', ',', '!'",
"Node Label Edit");
e.Node.BeginEdit();
}
然后,在AfterLabelEdit事件中
if (e.Label != null)
{
if(e.Label.Length > 0)
{
if (e.Label.IndexOfAny(new char[]{'@', '.', ',', '!'}) == -1)
{
// Stop editing without canceling the label change.
e.Node.EndEdit(false);
}
else
{
/* Cancel the label edit action, inform the user, and
place the node in edit mode again. */
e.CancelEdit = true;
MessageBox.Show("Invalid tree node label.\n" +
"The invalid characters are: '@','.', ',', '!'",
"Node Label Edit");
e.Node.BeginEdit();
}
您可以通过处理TreeView的DoubleClick事件来实现节点双击后可编辑,如下例所示:
private void TreeView1_DoubleClick(object source, EventArgs e)
{
TreeView1.LabelEdit = True;
TreeView1.SelectedNode.BeginEdit();
}
其中关键的步骤是调用TreeNode类的BeginEdit事件,有关该事件的详细信息请参阅MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWindowsFormsTreeNodeClassBeginEditTopic.asp
需要注意的是在调用BeginEdit事件之前,必须确保该TreeView的LabelEdit属性为True,否则将会出现异常。
- 微软全球技术中心 VC技术支持
本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款
(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查
(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
双击是展开树,单击已选定的结点时变得可以编辑?
谢谢
我会另外再加分的.
2.您可以通过处理TreeView的MouseDown事件来实现单击已选定的节点时使该节点变得可编辑的功能。如下例所示:
private void TreeView1_MouseDown(object source, MouseEventArgs e)
{
if( e.Button==MouseButtons.Left && e.Clicks==1 )
{
if(TreeView1.SelectedNode == TreeView1.GetNodeAt(e.X,e.Y))
TreeView1.SelectedNode.BeginEdit();
}
}- 微软全球技术中心 VC技术支持
本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款
(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查
(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。