fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11.  
  12. namespace DataGridView_SortTest2
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. }
  20.  
  21. private void Form1_Load(object sender, EventArgs e)
  22. {
  23. // テーブルにデータを追加
  24. //タスクテーブルBindingSource.Add("要望", "レベル", "低", "進行中");
  25. studyDataSet.studyTable.Rows.Add("数学", 80, "鈴木");
  26. studyDataSet.studyTable.Rows.Add("国語", 40, "田中");
  27. studyDataSet.studyTable.Rows.Add("社会", 60, "田中");
  28. studyDataSet.studyTable.Rows.Add("英語", 70, "鈴木");
  29. studyDataSet.studyTable.Rows.Add("数学", 80, "田中");
  30. studyDataSet.studyTable.Rows.Add("英語", 90, "田中");
  31. studyDataSet.studyTable.Rows.Add("国語", 80, "鈴木");
  32. studyDataSet.studyTable.Rows.Add("社会", 60, "鈴木");
  33. }
  34.  
  35. // ボタン「Sort」を押す
  36. private void button1_Click(object sender, EventArgs e)
  37. {
  38. DataView dv = new DataView(studyDataSet.studyTable);
  39. dv.Sort = "教科 ASC";
  40. this.dgv.DataSource = dv.ToTable();
  41. }
  42.  
  43. // ボタン「Save Text」を押す
  44. private void button3_Click(object sender, EventArgs e)
  45. {
  46. SaveTaskData();
  47. }
  48.  
  49. // 関数:表データを出力する
  50. private void SaveTaskData()
  51. {
  52. // 出力ファイル名
  53. string path = "data.txt";
  54. // 1行分のデータ
  55. string strData = "";
  56.  
  57. // 出力設定
  58. StreamWriter sw = new StreamWriter(
  59. path,
  60. false, // 追記ではなく上書き
  61. Encoding.Default);
  62.  
  63. // 表の一行の値をカンマ区切りで一行の文字列にしていく
  64. foreach (studyDataSet.studyTableRow drTask
  65. in studyDataSet.studyTable)
  66. {
  67. strData = drTask.教科 + ","
  68. + drTask.点数 + ","
  69. + drTask.名前 + ",";
  70.  
  71. // 一行書き込み
  72. sw.WriteLine(strData);
  73. }
  74. sw.Close();
  75. }
  76. }
  77. }
  78.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(4,14): error CS0234: The type or namespace name `Data' does not exist in the namespace `System'. Are you missing `System.Data' assembly reference?
prog.cs(10,22): error CS0234: The type or namespace name `Forms' does not exist in the namespace `System.Windows'. Are you missing `System.Windows.Forms' assembly reference?
prog.cs(14,31): error CS0246: The type or namespace name `Form' could not be found. Are you missing an assembly reference?
Compilation failed: 3 error(s), 0 warnings
stdout
Standard output is empty