title: Listening for a custom event fired from different winform
body: <p>I am working on a librarian application (in Visual Studio 2013, C#) which allows employers to loan, return and reserve books for customers. There is a small problem with creating, firing and listening for custom events.</p>
  
  <p>There is one form which adds data to a so-called Reservartion table, in my database. It adds a record with current date, itemID and other data.</p>
  
  <p>When the adding of this done, I want to fire a custom event, which will be listened to from a different form. When this event is fired, I need the total data in the Reservation Table to be shown when the event is fired. </p>
  
  <p>I use an onclick method in my main form, which opens a new form where data will be entered and afterwards, as described above, added into database. When the data has been added, the form closes and the main form receives focus again.</p>
  
  <p>The only problem now is, when all this is done, I need the entire data in the Reservartion Table to be shown onscreen (it needs to refresh itself). Which is where I need an event to be raised.</p>
  
  <p>How do I create a custom event in one form, which will be listen for INSIDE an onclick method?</p>
  
  <p>I included some of the code for reference.</p>
  
  <p>This is the code from the main form buttonclick:</p>
  
    
  
  <pre class="lang-cs prettyprint-override"><code>private void btnToevoegR_Click(object sender, EventArgs e)
  {
      Forms.HandAddReserveer HAR = new Forms.HandAddReserveer();
      HAR.Show();
      // listen for event raised
      // When event is raised do this
  
      DataTable DT = DBReserveer.getAllReserveerItems();
      gvUitleen.DataSource = DT;
  
  }
  </code></pre>
  
  <p>And in the other form, where the event should be raised</p>
  
  <pre class="lang-cs prettyprint-override"><code>private void button1_Click(object sender, EventArgs e)
  {
      int pasID;
          int itemID;
  
          if (int.TryParse(tbItemID.Text, out itemID))
          {
              if (int.TryParse(tbPasID.Text, out pasID))
              {
                  if ((DBReserveer.ReserveerPasCheck(itemID, pasID)) != 0)
                  {
                      MessageBox.Show("Je hebt dit item al gereserveerd!");
                  }
                  if ((DBReserveer.ReserveerPasCheck(itemID, pasID)) == 0)
                  {
                      if (MessageBox.Show("Weet je zeker dat je dit item wilt reserveren?", "Reserveren?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                      {
                          DBReserveer.ReserveerItem(itemID, pasID);
                          if (DBReserveer.QueryStatus == true)
                          {
                              MessageBox.Show("Het item is gereserveerd!");
                              // Event should be raised from here
                          }
                      }
                  }
              }
          }
  
  }
  </code></pre>