关于Winform ListBox的双击事件处理

 在ListBox中,是没有选中项的双击事件的,所以为了实现双击事件绑定的就是ListBox的MouseDoubleClick事件,如和做到点击空项时不执行操作,其实是可以做判断的

private void lbCommand_MouseDoubleClick(object sender, MouseEventArgs e)
{
int index = this.lbCommand.IndexFromPoint(e.Location);
if (index != System.Windows.Forms.ListBox.NoMatches)
{

     Messbox.show(this.lbCommand.SelectItem.tostring()); //执行双击事件

}
else
{
      lbCommand.SelectedIndex = -1;//不做任何操作,将ListBox的选中项取消
}
}