title: trying to display a list of data in a datagrid
body: <p>I'm trying to display a list of data in a WPF data grid because a textblock just threw the data together without any type of formatting (this is me hoping that formatting of this data is done for me).</p>
  
  <p>This is the code behind</p>
  
  <pre><code>public void OnMessageReceived(object sender, MessageReceivedEventArgs e)
  {
      try
      {
          if (e == null)
              return;
  
          if (e.CmsData != null)
          {
              List&lt;string&gt; mylist = new List&lt;string&gt;();
              foreach (var item in e.CmsData.Agents)
              {
                  mylist.Add(item.AgName);
                  mylist.Add(item.AuxReasonDescription);
              }
              Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =&gt;
              {
                  this.datagrid.ItemsSource = mylist;
              }));
          }
      }
  }
  </code></pre>
  
  <p>The XAML I'm using to populate the data grid</p>
  
  <pre><code>&lt;Grid Height="100" Width="178.201"&gt;
      &lt;DataGrid AutoGenerateColumns="True" ItemsSource="{Binding Path=mylist, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"   x:Name="datagrid" Background="{x:Null}" Loaded="textBlock_Loaded"/&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>this is the agents.cs file that has variables i'm trying to pull into my data grid just incase it is needed.</p>
  
  <pre><code>public class Agent : IEquatable&lt;Agent&gt;
  {
      public int Extension { get; set; }
      public int WorkModeDirection { get; set; }
      public string WorkModeDirectionDescription { get; set; }
      public TimeSpan AgTime { get; set; }
      public int AuxReason { get; set; }
      public string AuxReasonDescription { get; set; }
      public int DaInQueue { get; set; }
      public int WorkSkill { get; set; }
      public int OnHold { get; set; }
      public int Acd { get; set; }
      public String LoginId { get; set; }
      public string AgName { get; set; }
      public int EId { get; set; }
      public int Preference { get; set; }
      public DateTime DateTimeCreated { get; set; }
      public DateTime DateTimeUpdated { get; set; }
      public int CmId { get; set; }
      #region Implementation of IEquatable&lt;Agent&gt;
  
      public bool Equals(Agent other)
      {
          if (ReferenceEquals(null, other))
              return false;
  
          if (ReferenceEquals(this, other))
              return true;
  
          return (other.LoginId == LoginId &amp; other.CmId == CmId);
      }
  
      #endregion
  
      public override bool Equals(object obj)
      {
          if (ReferenceEquals(null, obj))
              return false;
  
          if (ReferenceEquals(this, obj))
              return true;
  
          if (obj.GetType() != typeof(Agent))
              return false;
  
          return Equals((Agent)obj);
      }
  
      //public override int GetHashCode()
      //{
      //    return LoginId;
      //}
      public override int GetHashCode()
      {
          string combinedNumber = "" + CmId + LoginId;
          int hash = Convert.ToInt32(combinedNumber);
          return hash;
      }
  
      public static bool operator ==(Agent left, Agent right)
      {
          return Equals(left, right);
      }
  
      public static bool operator !=(Agent left, Agent right)
      {
          return !Equals(left, right);
      }
  
      public override string ToString()
      {
          return " Ag: [Ext:" + Extension + " login:" + LoginId + " AgName:" + AgName + " CmId:" + CmId + "]";
      }
      public bool IsValid()
      {
          return LoginId != null;
      }
  }
  </code></pre>
  
  <p>This is what is currently being displayed...of which contains no information that I am telling it to print out and I have no idea where the numbers are coming from.
  <a href="https://i.stack.imgur.com/AKrnK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AKrnK.png" alt="enter image description here"></a></p>