LoginSignup
0
1

More than 5 years have passed since last update.

DataGridViewへのテキストファイルの登録

Posted at

メモがき。

WindowsFormでDataGridViewへのテキストファイル追加について
このソースではテキストファイルがUTF-8の場合。SJISなら、Encodingの部分を変更する。

settext2dgv.cs
private void settexttodatagridview( string filename )
{
    StreamReader sr = new StreamReader( filename, Encoding.GetEncoding("UTF-8");
    string line;

    dataGridView1.Rows.Clear();

    while ((line = sr.ReadLine()) != null)
    {
        string[] cols = line.Split(new char[] { '\t', ',' });

        dataGridView1.Rows.Add(cols);
    }
}
0
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1