【问题标题】:DataGridView in winforms application && List of structsWinforms应用程序中的DataGridView && 结构列表
【发布时间】:2014-08-15 16:34:33
【问题描述】:

我在我的 winforms 应用程序中使用DataGridView 控件

  private struct Ligne
        {
            public string Jour;
            public string LaDate;
            public int Heures;
            public int Minutes;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openfile = new OpenFileDialog();
            openfile.Filter = "fichier texte (*.txt)|*.txt";
            if (openfile.ShowDialog() == DialogResult.OK)
            {
                textBox2.Text = openfile.FileName;
                List<Ligne> str = ParsingFile(textBox2.Text);
                dataGridView1.DataSource = str;
            }
        }

如您所见,我正在尝试将结构列表绑定为网格的数据源,但即使列表不为空,我也会得到空字段:

我需要知道:

  • 为什么网格是空的?
  • 如何解决此错误?

【问题讨论】:

    标签: c# .net winforms collections datagridview


    【解决方案1】:

    您必须使列表属性的字段如下:

    public string Jour; { get; set; }
    public string LaDate; { get; set; }
    public int Heures; { get; set; }
    public int Minutes; { get; set; }
    

    ..否则无法访问它们的值。

    我假设列创建正常。

    【讨论】:

      猜你喜欢
      • 2011-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-28
      • 2010-12-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多