English 中文(简体)
只有当用户在一 Tree树口中点燃了根子时,我怎么能展示一个背景吗?
原标题:How can I show a context menu only when the user has clicked the root node in a TreeView?

我有一View树和一环。 我想在我右上点击Rota node,而不是儿童节点时,就显示Lenu ONLY的情况。

这是我迄今为止所做的。 这表明,即使在我右上点击儿童节点时,也见到了门图。 我怎么能够改变这种说法,以便门乌只有在我正确点击根 no的时候才能显示吗? 是否可能?

if(e.Button == MouseButtons.Right)
{
    // Select the clicked node
    treeView1.SelectedNode = treeView1.GetNodeAt(e.X, e.Y);

    if(treeView1.SelectedNode != null)
    {
        myContextMenuStrip.Show(treeView1, e.Location)
    }
}
最佳回答

是的,但是,如果“> 报表核实被点击的用户的 no点是根本的 no点,则你需要添加一些逻辑。

但是,如果它扎根吗? 即便如此,我们也可以把根子定义为没有父母的人。 因此,你可以简单地检查Parent ,Tree node,并确保该编码为>。

• 修改你的法典,研究类似的东西:

if (e.Button == MouseButtons.Right)
{
    // Select the clicked node
    treeView1.SelectedNode = treeView1.GetNodeAt(e.X, e.Y);

    if (treeView1.SelectedNode != null && treeView.SelectedNode.Parent == null)
    {
        myContextMenuStrip.Show(treeView1, e.Location)
    }
}

您希望保留这样的检查,即噪音本身不是null,因为你不想在点子上显示环境变化。 父母的检查,因为检查告诉你它是否扎根。 您指出,从方案角度来说,正在使用一种逻辑的,即<代码>&&的操作者,载于C#。

问题回答

检查你点上点击的点子是底线,而不是检查它为<代码>null<>。





相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.

热门标签