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;
}
}
private void lviewExecuter_AfterLabelEdit(object sender, LabelEditEventArgs e)
{ //判断编辑的内容合法
//内容为空
if (e.Label == null)
{
MessageBox.Show("内容不能为空!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
listview1.Items[e.Item].BeginEdit();
return;
}
}
{
if (e.Label == "")
{
e.CancelEdit = true;
MessageBox.Show("内容不能为空!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
//this.listView1.Items[e.Item].BeginEdit();
return;
}
}