contextmenustrip 控件,我只想让它在有内容的情况下,右键菜单才会显示,否则不显示
if(listView1.SelectedItems.Count==0){}else{DialogResultdresult=MessageBox.Show("是否删除"...
if (listView1.SelectedItems.Count == 0)
{
}
else
{
DialogResult dresult = MessageBox.Show("是否删除","提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
if (dresult == DialogResult.Yes)
{
int num = 0;
try
{
DBHelper.con.Open();
string sql = string.Format("delete from stuinfo where stuid = {0}",listView1.SelectedItems[0].Tag);
SqlCommand cmd = new SqlCommand(sql,DBHelper.con);
num = cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
DBHelper.con.Close();
}
if (num > 0)
{
MessageBox.Show("删除成功");
listView1.Items.Clear();
xianshi();
}
else
{
MessageBox.Show("删除失败");
}
}
else
{
}
}
这是我的代码,,效果是不论是否有值,都会显示右键菜单,,
我想要的是只有右键有值的情况下,才显示右键菜单属性,右键单机没值时,就不显示值 展开
{
}
else
{
DialogResult dresult = MessageBox.Show("是否删除","提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
if (dresult == DialogResult.Yes)
{
int num = 0;
try
{
DBHelper.con.Open();
string sql = string.Format("delete from stuinfo where stuid = {0}",listView1.SelectedItems[0].Tag);
SqlCommand cmd = new SqlCommand(sql,DBHelper.con);
num = cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
DBHelper.con.Close();
}
if (num > 0)
{
MessageBox.Show("删除成功");
listView1.Items.Clear();
xianshi();
}
else
{
MessageBox.Show("删除失败");
}
}
else
{
}
}
这是我的代码,,效果是不论是否有值,都会显示右键菜单,,
我想要的是只有右键有值的情况下,才显示右键菜单属性,右键单机没值时,就不显示值 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询