title: Write a Text File to specific rows of a Datagridview
body: <p>I have a Datagridview (dgvMaster) and a comma separated text file that i am using as a database (each line starts with an ID number and these are unique).  A button (btnLoadSeries) loads the file shown in a textbox (txtseriestoload).
  The Text File looks like:</p>
  
  <pre><code>1,joe,smith
  2,john,doe
  30,charlie,brown
  </code></pre>
  
  <p>What I would like is to be able to write the row with "1,joe,smith" to row #1, and "30,charlie,brown" to row 30, and so on.  I have tried a few different ideas but I am a self taught VB user. Here is my current code and it fills the dgvmaster with the number of rows from the file and shows the row number but then adds the data after that.  I have tried to simply add 5000 rows even though my file will never contain an id greater than 5000 still with no luck.  This is a first time post for me so please be kind!</p>
  
  <pre><code>   Private Sub btnLoadSeries_Click(sender As Object, e As EventArgs) Handles btnLoadSeries.Click
      dgvMaster.Rows.Clear()
      Dim TextLine As String = ""
      Dim SplitLine() As String
      Dim fname As String = txtSeriestoLoad.Text
  
      'Count the lines of the file.  May change to a fixed number.
      Dim lineCount = System.IO.File.ReadAllLines(fname).Length
  
      'Set the number of rows
      dgvMaster.RowCount = lineCount + 1
  
      'Show row number
      Dim rownumber As Integer
      For rownumber = 0 To lineCount
          dgvMaster.Rows(rownumber).HeaderCell.Value = (rownumber).ToString
      Next rownumber
  
      'write file to dgvmaster
      If System.IO.File.Exists(fname) = True Then
          Dim objReader As New System.IO.StreamReader(fname)
          Do While objReader.Peek() &lt;&gt; -1
              TextLine = objReader.ReadLine()
              SplitLine = Split(TextLine, ",")
              Me.dgvMaster.Rows.Add(SplitLine)
          Loop
      Else
          MsgBox("File Does Not Exist")
      End If
  
  
  
  End Sub
  </code></pre>