title: Identify visible list in a button
body: <p>I am creating a program that will provide a front end to open files from server locations without having to navigate to server locations. The program has buttons that open lists for certain categories, then a single button to open the file from the currently selected item from the list.</p>
  
  <p>My current issue is being able to identify which ListBox is currently in view, so that the program knows which list to use as a reference to open the right file.</p>
  
  <p>Is there a way to create an "object" called "List", then assign the listbox to it and reference it? It does not seem to like what I have done.</p>
  
  <pre><code> object ListBox;
   int IdCheck =  0;
   string DriveLoc;
  
   private void ButtAirInfo_Click(object sender, EventArgs e)
      {
          GBAirInfo.Visible = true;
          GBAir.Visible = false;
          ListBox = LBAirInfo; //Here is where I load the List on to the screen, then 
                               //assign the list to the object ListBox
      }
   private void button2_Click(object sender, EventArgs e)
      {
          using (connection = new SqlConnection(connectionString))
          using (SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Files", connection))
          {
              DataTable FilesTable = new DataTable();
              adapter.Fill(FilesTable);
  
              if (ListBox.SelectedIndex == -1)
                  MessageBox.Show("No Items selected");
              else
                  IdCheck = ListBox.SelectedIndex;
                  DriveLoc = (FilesTable.Rows[IdCheck]["Location"].ToString());
              if (DriveLoc == "")
                      MessageBox.Show("Item does not have a location");
              else
                  System.Diagnostics.Process.Start(@DriveLoc);
          }
  </code></pre>