【问题标题】:DatagridView doesn't show any data when I run my project运行项目时 DatagridView 不显示任何数据
【发布时间】:2011-06-26 09:20:08
【问题描述】:

我为我的项目创建了一个 UserControl,并在该控件中放置了一个 DataGridView。我从我的数据库中为这个 DataGridView 选择了一个数据源。

但是当我将此 UserControl 带到我的主窗体并运行项目时,它不会显示我数据库中的任何数据。

当我在主窗体中直接创建 DataGridView 时,它可以工作。

我需要使用 UserControl 来做到这一点。

【问题讨论】:

  • 也许你应该在运行时设置的db路径问题?
  • 贴出你的usercontrol相关代码。

标签: c# winforms data-binding user-controls datagridview


【解决方案1】:

当您使用 IDE 时,您只需提供模板(和其他配置元数据);您仍然必须在运行时提供实际的数据源,例如通过填充对象模型或 DataTable 并将其分配为 DataGridView 或(在使用 IDE 时更常见)设计人员添加的 BindingSource 对象的 DataSource。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-23
    • 1970-01-01
    • 2017-06-13
    • 1970-01-01
    • 1970-01-01
    • 2011-07-31
    • 2016-10-12
    相关资源
    最近更新 更多