listview用BeginEdit()开始编辑后,用Enter完成编辑,内容为空时弹出一次MessageBox,正常,用鼠标点击Listview其他项或者ListView内的其他地方,AfterLabelEdit被调用两次,弹出两次MessageBox??而点击ListView外的地方,只弹出一次,正常。为什么啊代码如下:
private void lviewExecuter_AfterLabelEdit(object sender, LabelEditEventArgs e)
{   //判断编辑的内容合法
   //内容为空
   if (e.Label == null)
   {
       MessageBox.Show("内容不能为空!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
       listview1.Items[e.Item].BeginEdit();
               
       return;
   }
}

解决方案 »

  1.   

    private void listView1_AfterLabelEdit(object sender, LabelEditEventArgs e)
            {
                if (e.Label == "")
                {
                    e.CancelEdit = true;
                    MessageBox.Show("内容不能为空!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    //this.listView1.Items[e.Item].BeginEdit();
                    return;
                }
            }
      

  2.   

    其实我最近也在研究这方面的问题,当我的listview有数据时是可以编辑的,而当它为空时就不可以编辑了,楼上有人知道是什么问题吗?