我想在双击列表框中的某个项目时执行某些操作。我发现这样做的代码在C#中的ListBox项目上处理双击事件
void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
int index = this.listBox1.IndexFromPoint(e.Location);
if (index != System.Windows.Forms.ListBox.NoMatches)
{
MessageBox.Show(index.ToString());
//do your stuff here
}
}
但是,当我点击一个项目,事件不会被解雇。如果我点击所有项目下方的列表框,该事件将被解雇。
我将ListBox
的DataSource属性设置为IList<MyObject>
。
任何想法?
有关检查e.Clicks == 1的想法已经在此线程中提及。但这里有另一个关于这种方法的写法:http://cf-bill.blogspot.com/2007/04/c-dragdrop-and-doubleclick.html – 2011-09-03 01:18:44