Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What's happening here is that the DataGridView is trying to display all the information for each of the string arrays in your <code>parsedData</code> List.</p> <p>When you set a DataGridView's DataSource as a List of objects, it attempts to interpret each of the objects as a row to display. <code>parsedData</code> is a List of string array objects, so the grid is showing you all the displayable properties for an array object.</p> <p>What we can do is parse each TSV row into a custom class (call it TsvRow) which has all the relevant data exposed. The TsvRow objects are then placed in a List and passed to the DataGridView. An example of this approach is explained in <a href="http://www.switchonthecode.com/tutorials/csharp-tutorial-binding-a-datagridview-to-a-collection" rel="nofollow noreferrer">this article</a>.</p> <p>For example:</p> <pre><code>public class TsvRow { // Properties to hold column data public string Column1 { get; set; } public string Column2 { get; set; } } </code></pre> <p>...</p> <pre><code>public List&lt;TsvRow&gt; parseCSV(string path) { List&lt;TsvRow&gt; parsedData = new List&lt;TsvRow&gt;(); try { using (StreamReader readfile = new StreamReader(path)) { string line; string[] row; while ((line = readfile.ReadLine()) != null) { row = line.Split('\t'); // Here we assume we know the order of the columns in the TSV // And we populate the object TsvRow tsvRow = new TsvRow(); tsvRow.Column1 = row[0]; tsvRow.Column2 = row[1]; parsedData.Add(myObject); } } } catch (Exception e) { MessageBox.Show(e.Message); } return parsedData; } </code></pre> <p>Since all your column data is exposed as properties (i.e. "Column1" and "Column2"), they should be reflected in the DataGridView automatically.</p> <p>Hope that helps! Please let me know if this needs clarification.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload