title: C# read from serial port arduino
body: <p>I have done a simple project that reads from serial port (arduino) and I receive the data and I can put those data in textbox, richtex but I cant put them in data grid in fact I need to put those data in MSSQL table but also display in data grid. here is the code that I have tried:</p>
  
  <pre><code>void _spManager_NewSerialDataRecieved(object sender, SerialDataEventArgs e)
          {
              if (this.InvokeRequired)
              {
                  // Using this.Invoke causes deadlock when closing serial port, and BeginInvoke is good practice anyway.
                  this.BeginInvoke(new EventHandler&lt;SerialDataEventArgs&gt;(_spManager_NewSerialDataRecieved), new object[] { sender, e });
                  return;
              }
  
              int maxTextLength = 1000; // maximum text length in text box
              if (tbData.TextLength &gt; maxTextLength)
                  tbData.Text = tbData.Text.Remove(0, tbData.TextLength - maxTextLength);
  
              // This application is connected to a GPS sending ASCCI characters, so data is converted to text
              string str = Encoding.ASCII.GetString(e.Data);
              tbData.AppendText(str);
              tbData.ScrollToCaret();
  
               richD.AppendText(str);
                  richD.ScrollToCaret();
  
               dataGridView1.DataSource = str;
  
              }
  </code></pre>
  
  <p>Can you help me fill the datagridbiew?</p>
  
  <p>This is where I get the e.Data:</p>
  
  <pre><code>public class SerialDataEventArgs : EventArgs
  {
      public SerialDataEventArgs(byte[] dataInByteArray)
      {
          Data = dataInByteArray;
      }
  
      /// &lt;summary&gt;
      /// Byte array containing data from serial port
      /// &lt;/summary&gt;
      public byte[] Data;
  }
  </code></pre>