日期:2014-05-18  浏览次数:20982 次

C#右键,指定listbox某一项右键响应菜单
hi~大家好,这个问题困扰我很长时间了,有大侠知道吗?请教.....

------解决方案--------------------
你可以根据每项选择的列动态生成一个contextMenuStrip让它显示出来就行了
------解决方案--------------------
C#右键,指定listbox某一项右键响应菜单
--
菜单的内容不一样吗?
为什么要每项都加,把属性ContentMenuStrip设置好就可以了.

然后用Listbox的Select属性获得选择的项.
------解决方案--------------------
C# code


 private void lbList_SelectedIndexChanged(object sender, EventArgs e)
        {
            int index = this.lbList.SelectedIndex;
            if (index == 0)
            {
                this.contextMenuStrip1.Items.Clear();
                ToolStripMenuItem item = new ToolStripMenuItem();
                item.Text = "0000000";
                this.contextMenuStrip1.Items.Add(item);
            }
            else if (index == 1)
            {
                this.contextMenuStrip1.Items.Clear();
                ToolStripMenuItem item = new ToolStripMenuItem();
                item.Text = "1111111";
                this.contextMenuStrip1.Items.Add(item);
            }
            else if (index == 2)
            {
                this.contextMenuStrip1.Items.Clear();
                ToolStripMenuItem item = new ToolStripMenuItem();
                item.Text = "2222222";
                this.contextMenuStrip1.Items.Add(item);
            }
            
        }