title: Pushing new Collection item to a GridView in a different class
body: <p>I have a <code>LogOperations</code> class, which is a singleton, and it contains a collection of my <code>Log</code> object and a few methods for adding new <code>Log</code>s to the collection. <code>Log</code> only has 3 properties; <code>Message</code>, <code>Exception</code>, and <code>Time</code>.</p>
  
  <p>On the only form in my application, I get a reference to <code>LogOperations</code>. Then I use its <code>Collection&lt;Log&gt; logs</code> property to build a data table out of each entry and throw that into a <code>GridControl</code> (gdcErrorLogs).</p>
  
  <pre><code>        gdcErrorLog.DataSource = logOps.GetLogsAsDataTable(); //Popualtes dt with each Log in logs
  </code></pre>
  
  <p>I have a bunch of other classes that perform all sorts of functions for the form, and whenever these functions catch an error I write that error to my <code>LogOperations</code>'s collection.</p>
  
  <p>How can I make my form's grid automatically update with this new entry each time a <code>Log</code> gets added? I'm thinking of adding a reference to the form in my <code>LogOperations</code> class, and then at the end of my Add functions I'd just re-set the form's grid to be this new DataTable?</p>
  
  <pre><code>public class AddNewLogEventArgs : EventArgs
  {
      public Log log { get; private set; } // Error on compile see below
      public AddNewLogEventArgs(Log newLog) // Error on compile see below
      {
          log = newLog;
      }
  }
  
  class LogOps
  {
      public delegate void AddNewLogHandler(object sender, AddNewLogEventArgs e);
      public event AddNewLogHandler OnAddNewLog;
  
      private Collection&lt;Log&gt; _logs;
      private static LogOps _singleton;
  
      private LogOps() 
      {
          _logs = new Collection&lt;Log&gt;();
      }
  
      public static LogOps Instance
      {
          get 
          {
              if (_singleton == null)
                  _singleton = new LogOps();
              return _singleton;
          }
      }
  
      public void AddLog(string text)
      {
          Log newLog = new Log(text);
          _singleton._logs.Add(newLog);
          OnAddNewLog(new AddNewLogEventArgs(newLog), null);
      }
  
      public void AddLog(Log log)
      {
          Log newLog = log;
          _singleton._logs.Add(newLog);
          OnAddNewLog(new AddNewLogEventArgs(newLog), null);
      }
  
      public void AddLog(Exception ex)
      {
          Log newLog = new Log(ex.Message, ex.InnerException);
          _singleton._logs.Add(newLog);
          OnAddNewLog(new AddNewLogEventArgs(newLog), null);
      }
  
      public DataTable GetLogsAsDataTable()
      {
          DataTable dt = new DataTable();
          dt.Columns.Add("Time");
          dt.Columns.Add("Error");
          dt.Columns.Add("Exception");
  
          int i = 0;
          foreach (Log log in _logs)
          {
              dt.Rows.Add();
  
              dt.Rows[i].SetField("Time", log.Time);
              dt.Rows[i].SetField("Error", log.Err);
              dt.Rows[i].SetField("Exception", log.Ex.Message);
              i++;
          }
          return dt;
      }
  }
  </code></pre>
  
  <p><strong>Edit</strong> Code sample was heavily modified since trying out King King's solution</p>
  
  <p>The two flagged lines in the AddNewLogEventArgs give me these two errors:</p>
  
  <ul>
  <li>Error 1   Inconsistent accessibility: property type 'PrepareDeployment.Models.Log' is less accessible than property 'PrepareDeployment.Processes.AddNewLogEventArgs.log'</li>
  <li>Error 2 Inconsistent accessibility: parameter type 'PrepareDeployment.Models.Log' is less accessible than method 'PrepareDeployment.Processes.AddNewLogEventArgs.AddNewLogEventArgs(PrepareDeployment.Models.Log)'</li>
  </ul>