title: C# Duplicating fields in DataGridView after reading data from multiple files
body: <p>I'm making a program that downloads zip files from an SFTP server, unzips the files and reads the text file to display certain data in a DataGridView but for some reason its duplicating the values after 10-15 files</p>
  <p>Result:</p>
  <p><a href="https://i.stack.imgur.com/tMpr5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tMpr5.png" alt="Result" /></a></p>
  <p>Here is the code:</p>
  <pre><code>public partial class Form1 : Form
  {
      private DataGridView dexRead;
  
      public Form1()
      {
          InitializeComponent();
          //this is the Designer.cs code...
          dexRead = new DataGridView();
          ((ISupportInitialize)(this.dexRead)).BeginInit();
          SuspendLayout();
  
          dexRead.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
          dexRead.Location = new Point(12, 12);
          dexRead.Name = &quot;dexRead&quot;;
          dexRead.Size = new Size(606, 400);
          dexRead.TabIndex = 0;
  
          AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
          AutoScaleMode = AutoScaleMode.Font;
          ClientSize = new Size(630, 434);
          Controls.Add(dexRead);
          Name = &quot;Form1&quot;;
          Text = &quot;Form1&quot;;
          ((ISupportInitialize)(this.dexRead)).EndInit();
          ResumeLayout(false);
  
          string zipTemp = (@&quot;C:\Users\mark\Desktop\Project Dex\zipTemp\&quot;);
          string machineCashCount = (&quot;&quot;);
          string hostIP = (&quot;0.0.0.0&quot;);
          string userName = (&quot;un&quot;);
          string passWord = (&quot;pw&quot;);
          string remotePath = (@&quot;/home/dex/RESPONSE/PROCESSED&quot;);
          string localPath = (@&quot;C:\Users\mark\Desktop\Project Dex\Temp\PROCESSED\&quot;);
  
  
          IList&lt;Machine&gt; machines = new BindingList&lt;Machine&gt;();
          dexRead.DataSource = machines;
  
          SessionOptions sessionOptions = new SessionOptions
          {
              Protocol = Protocol.Sftp,
              HostName = hostIP,
              UserName = userName,
              Password = passWord,
              PortNumber = 22,
              SshHostKeyFingerprint = &quot;ssh-rsa 2048 96:48:96:52:8c:e7:de:c6:e1:00:08:7e:db:ad:e4:06&quot;
  
          };
  
          using (Session session = new Session())
          {
              session.Open(sessionOptions);
  
              TransferOptions transferOptions = new TransferOptions();
              transferOptions.TransferMode = TransferMode.Binary;
  
              session.GetFiles(remotePath, @&quot;C:\Users\mark\Desktop\Project Dex\Temp\&quot;).Check();
          }
  
          DirectoryInfo directorySelected = new DirectoryInfo(@&quot;C:\Users\mark\Desktop\Project Dex\Temp\PROCESSED\&quot;);
          List&lt;string&gt; fileNames = new List&lt;string&gt;();
  
          foreach (FileInfo fileInfo in directorySelected.GetFiles(&quot;*.zip&quot;))
          {
              fileNames.Add(fileInfo.Name);
          }
  
          foreach (string fileName in fileNames)
          {
              string zipFilePath = localPath + fileName;
              string[] timeDate = fileName.Split('_');
              string Date = timeDate[1];
              string Time = timeDate[2];
              string[] tme = Time.Split('.');
              string tm = tme[0];
              string dateTime = Date + tm;
  
              DateTime dTime = DateTime.ParseExact(dateTime, &quot;MMddyyyyHHmmss&quot;,
                                      CultureInfo.InvariantCulture);
              string daTime = dTime.ToString();
  
              using (ZipFile zip1 = ZipFile.Read(zipFilePath))
              {
                  var selection = (from e in zip1.Entries
                                   where (e.FileName).StartsWith(&quot;01e&quot;)
                                   select e);
  
                  Directory.CreateDirectory(zipTemp);
  
                  foreach (var e in selection)
                  {
                      e.Extract(zipTemp, ExtractExistingFileAction.OverwriteSilently);
                  }
              }
  
              DirectoryInfo dexDirect = new DirectoryInfo(@&quot;C:\Users\mark\Desktop\Project Dex\zipTemp\&quot;);
              List&lt;string&gt; dexName = new List&lt;string&gt;();
              List&lt;string&gt; dexDate = new List&lt;string&gt;();
  
              foreach (FileInfo dexInfo in dexDirect.GetFiles(&quot;*.dex&quot;))
              {
                  dexName.Add(dexInfo.Name);
              }
  
              foreach (string dexNames in dexName)
              {
                  string dexFilePath = zipTemp + dexNames;
  
                  string[] lines = System.IO.File.ReadAllLines(dexFilePath);
  
                  foreach (string line in lines)
                  {
                      machineCashCount = Array.Find(lines,
                  element =&gt; element.StartsWith(&quot;VA1&quot;, StringComparison.Ordinal));
                  }
  
                  string[] MCC1 = machineCashCount.Split('*');
                  string[] nm = dexNames.Split('.');
                  
  
                  int nam = int.Parse(nm[0], System.Globalization.NumberStyles.HexNumber);
  
                  Console.WriteLine((nam + (&quot;:&quot;) + &quot;Total cash count: &quot;) + MCC1[1]);
                  Console.WriteLine((nam + (&quot;:&quot;) + &quot;Number of paid vends: &quot;) + MCC1[2]);
  
  
                  Machine m = new Machine();
  
                  m.MacNum = nam;
                  m.CashCount = MCC1[1];
                  m.VendCount = MCC1[2];
                  m.Date_and_Time = daTime;
                  machines.Add(m);
              }
          }
      }
  
      protected override void OnClosed(EventArgs e)
      {
          base.OnClosed(e);
          Array.ForEach(Directory.GetFiles(@&quot;C:\Users\mark\Desktop\Project Dex\zipTemp&quot;), File.Delete);
          Array.ForEach(Directory.GetFiles(@&quot;C:\Users\mark\Desktop\Project Dex\Temp\PROCESSED&quot;), File.Delete);
      }
  }
  class Machine
  {
      public int MacNum { get; set; }
      public string CashCount { get; set; }
      public string VendCount { get; set; }
      public string Date_and_Time { get; set; }
  }
  </code></pre>
  <p>}</p>
  <p>I'm kinda new to programming in C# and I would really appreciate any help I can get, Thanks.</p>