Note that there are some explanatory texts on larger screens.

plurals
  1. POC# in Visual Studio: How to display a list in a DataGridView? Getting weird stuff
    text
    copied!<p>Been a while and I've volunteered to teach myself Windows programming at my company. Started writing vbs scripts and suddenly realized how incredibly useful this programming thing is ;-)</p> <p>Anyway, I'm a total newbie at C# AND Visual Studio, I kind of get how it works, you drag and drop interface pieces in the design side then wire them together in the back/program side.</p> <p>I'm trying to write a program that will (ultimately) read in a (very specific kind of) csv file and give the user a friendlier way to edit and sort through it than Excel. Should be simple stuff, and I'm excited about it.</p> <p>I started this morning and, with the help of the internet, got as far as reading in and parsing the CSV (which is actually a TSV, since they use tabs not commas but hey).</p> <p>I've been trying to figure out the best way to display the information, and, for now at least, I'm using a DataGridView. But the data isn't displaying. Instead, I'm seeing a long grid of values with column headers of Length, LongLength, Rank, SyncRoot, IsReadOnly, IsFixedSize, and IsSynchronized.</p> <p>I don't know what any of these mean or where they come from, and unfortunately I don't know how change them either. Maybe somebody can help?</p> <p>Here is my code:</p> <pre><code>using System; </code></pre> <p>using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO;</p> <p>namespace readInCSV { public partial class readInCSV : Form { public readInCSV() { InitializeComponent(); }</p> <pre><code> public List&lt;string[]&gt; parseCSV(string path) { List&lt;string[]&gt; parsedData = new List&lt;string[]&gt;(); try { using (StreamReader readfile = new StreamReader(path)) { string line; string[] row; while ((line = readfile.ReadLine()) != null) { row = line.Split('\t'); parsedData.Add(row); } } } catch (Exception e) { MessageBox.Show(e.Message); } return parsedData; } //PRIVATE METHODS FROM HERE ON DOWN private void btnLoadIn_Click(object sender, EventArgs e) { int size = -1; DialogResult csvResult = openCSVDialog.ShowDialog(); if (csvResult == DialogResult.OK) { string file = openCSVDialog.FileName; try { string text = File.ReadAllText(file); size = text.Length; } catch (IOException) { } } dgView.Dock = DockStyle.Top; dgView.EditMode = DataGridViewEditMode.EditOnEnter; dgView.AutoGenerateColumns = true; dgView.DataSource = parseCSV(openCSVDialog.FileName); } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { } private void openCSVDialog_FileOk(object sender, CancelEventArgs e) { } } </code></pre> <p>}</p> <p>Thanks in advance!</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