我在Windows窗体中填充了一个SQL数据库的列表视图。我有一个按钮来选择删除记录,它工作正常。但如果没有选定的项目,我点击删除按钮,我得到和错误。所以我添加一个消息框和一个条件,但总是得到 - 对象引用未设置为对象的实例。C#Windows窗体列表查看选定项目
那么我如何检查列表视图中是否有选定的项目,以便它进入If?
感谢
private void btnDelete_Click(object sender, EventArgs e)
{
bool b = this.lvBrands.FocusedItem.Checked;
if (b == false)
{
MessageBox.Show("You must select a brand .", "Brand Select Error",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
string sID = this.lvBrands.FocusedItem.Text;
deleteBrand(sID);
clearBrand();
}
谢谢... :)这个作品! – n3bi0s 2013-03-22 18:15:33