ListView的鼠标单击事件里处理,如果是单击的是右键,则将提前创建好的菜单显示出来即可!
解决方案 »
- 树形结构的部门信息,以递归的方式存在数据库里。程序界面怎么管理?
- C# winform中treeview 的checkbox勾选
- 求助:怎样把ZedGraph控件生成的图像导出到EXcel中
- DataGridView中哪个事件来触发我点中不同行
- 新人白痴问题,请问怎么搭建C语言学习环境
- 哪位大侠能解释一下C#中的回调函数或给个例子
- 公益帖子:建一个粪池(csdn mark pool)。为了那些初学者,高手们,捐献一点可用分如何?
- 简单的ErrorProvider控件问题!送分而已
- asp里C#怎样调用自己C#写的DLL类库
- 简单问题,高分求救! 关于动态创建Button问题.(答对马上给分)
- C#生成word如何设置整篇文档的字体
- 数字组合问题
private void listView1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
contextMenuStrip1.Show(Cursor.Position.X,Cursor.Position.Y);
}
}
{
if (e.Button == MouseButtons.Right)
{
contextMenuStrip1.Show();
}
}
{
int currentIndex = e.Y / 12;
if (listBox1.SelectedItem != null && currentIndex != listBox1.SelectedIndex)
{
this.listBox1.SetSelected(listBox1.SelectedIndex, false);
}
this.listBox1.SetSelected(currentIndex, true);
}
这段代码是右键选中楼上的说的对,在listBox1的contextMenuStrip属性设置,就可以出来了
{
if (e.Button == MouseButtons.Right)
{
int currentIndex = e.Y / 12;
if (listBox1.SelectedItem != null && currentIndex != listBox1.SelectedIndex)
{
this.listBox1.SetSelected(listBox1.SelectedIndex, false);
}
this.listBox1.SetSelected(currentIndex, true);
}
}