listBox 怎样点右键选中一行数据
解决方案 »
- vs2010 RDLC 位于“”的子报表Subreport1的数据检索失败
- 有没有代替GridView1_SelectedIndexChanged事件的好办法
- datagridview如何使显示跟填加顺序相反
- C#在主窗体中新建一线程,弹出一窗体,如何不让主窗体激活!
- 急啊,求高手指点下关于C#压缩文件的问题!
- asp.net access数据库更新的问题!!请帮帮忙
- FROM关闭了,可是程序没有退出
- 关于c#程序模块化的问题 请高手指点迷精 谢谢咯
- ★★★★求:oracle插入blob信息出错(内含代码)★★★★
- int byte short等值类型变量的选取问题
- winform下datagridview绑定需处理的数据如何处理为好?
- 如何选中treeview 根节点?
private void lb_planList_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
//lb_planList.SelectedIndex = ........不会哒
}
}
1:模拟一次左键单击;
2:自己计算点击位置的ITEM我给出方案2的代码:private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
int height = 0;
for (int i = 0; i < listBox1.Items.Count; i++)
{
height += listBox1.GetItemHeight(i);
if (e.Y <= height)
{
listBox1.SelectedIndex = i;
return;
}
}
}
注意:上述代码只检测了高度信息,对于多列的listbox需要修改代码。
{
if (e.Button == MouseButtons.Right)
{
for(int i=0;i!=listBox1.Items.Count;i++)
{
Rectangle ItemRectangle=listBox1.GetItemRectangle(i); if (ItemRectangle.Contains(new Point(e.X, e.Y)))
{
listBox1.SelectedIndex = i;
break;
}
}
}
}
private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
int height = 0;
for (int i = 0; i < listBox1.Items.Count; i++)
{
height += listBox1.GetItemHeight(i);
if (e.Y <= height)
{
listBox1.SelectedIndex = i;
return;
}
}
}
}