title: C# Windows forms Listview selected item
body: <p>I have a listview in Windows forms populated by a SQL database. i have a button to delete records when selected and it's working fine. but if there is no selected item and i click the delete button i get and error. so i add a messagebox and a condition but a always get - <strong><em>Object reference not set to an instance of an object.</em></strong> </p>
  
  <p>so how do i check if there is a selected item in the listview so it enter the If? </p>
  
  <p>thanks</p>
  
  <pre><code>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(); 
  
          }    
  </code></pre>