C#DataGridView绑定到表INOP

发布于 2025-01-30 05:17:03 字数 616 浏览 4 评论 0原文

尝试在数据网格视图中显示表数据。遵循了许多没有解决方案的博客建议。将代码减少到下面的简单测试案例,但网格视图仍然空白。上一次检查网格视图行= 0。(未再次验证此确切的代码,但仍然空白)。

    private void ImportTable(string fileName)
    {
        DataTable table = new DataTable();
        table.Columns.Add("Column 1", typeof(int));
        table.Columns.Add("Column 2", typeof(int));
        table.Rows.Add(1, 2);

        dataGridView1 = new DataGridView();
        dataGridView1.AutoGenerateColumns = true;

        BindingSource SBind = new BindingSource();
        SBind.DataSource = table;
        dataGridView1.DataSource = SBind;
        dataGridView1.Refresh();
    }

Trying to display table data in a data grid view. Have followed many blog suggestions with no resolution. Have reduced the code down to the simple test case below but grid view remains blank. Last check grid view Rows = 0. (not verified again for this exact code but still blank).

    private void ImportTable(string fileName)
    {
        DataTable table = new DataTable();
        table.Columns.Add("Column 1", typeof(int));
        table.Columns.Add("Column 2", typeof(int));
        table.Rows.Add(1, 2);

        dataGridView1 = new DataGridView();
        dataGridView1.AutoGenerateColumns = true;

        BindingSource SBind = new BindingSource();
        SBind.DataSource = table;
        dataGridView1.DataSource = SBind;
        dataGridView1.Refresh();
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文