Winforms 空绑定源问题
我在使用BindingSource、类型化数据集和DataGridView绑定数据时遇到问题。我的问题是:绑定数据后,BindingSource(因此网格)为空(BindingSource.Count为0)。我不知道我做错了什么,如果有人能帮我,我会非常高兴。我的应用程序结构如下:我有两个程序集,一个是Winforms UI,另一个是数据库类库 UIWinforms 空绑定源问题,winforms,data-binding,datagridview,strongly-typed-dataset,bindingsource,Winforms,Data Binding,Datagridview,Strongly Typed Dataset,Bindingsource,我在使用BindingSource、类型化数据集和DataGridView绑定数据时遇到问题。我的问题是:绑定数据后,BindingSource(因此网格)为空(BindingSource.Count为0)。我不知道我做错了什么,如果有人能帮我,我会非常高兴。我的应用程序结构如下:我有两个程序集,一个是Winforms UI,另一个是数据库类库 UI DataGridView,数据源作为BindingSource BindingSource,datasource=DBAssembly.type
- DataGridView,数据源作为BindingSource
- BindingSource,datasource=DBAssembly.typedDataset,datamember=DBAssembly.typedDataset.myTable
- Sql Server CE数据库
- 类型化数据集
- 数据库操作的DB类
如果您能帮我,我将不胜感激。首先要问的是:this.typedDataSet.MyTable.Rows.Count是什么?i、 适配器做了什么吗?如果不是,则与绑定无关 假设它是非空的,那么您使用什么精确的代码来设置
数据源
和数据成员
?我认为应该是:
bindingSource.DataSource = this.typedDataSet;
bindingSource.DataMember = "MyTable";
dataGridView.DataSource = bindingSource;
或者,您可以将bindingSource
的数据源设置为this.typedDataSet.MyTable
,并将表留空
基本上,我希望您已经告诉它要预测的数据类型,但到目前为止,您还没有给它您想要使用的数据集/数据表。基本上,我希望您已经告诉它要预测的数据类型,但到目前为止,您还没有给它您想要使用的数据集/数据表
马克,你说得对。我需要在我的DB类中创建一个公共数据集属性,并将其用作BindingSource的数据源来实现这一点。谢谢你的帮助
create typedDataSet object
create typedDataSetTableAdapters.MyTableTableAdapter object
create typedDataSetTableAdapters.TableAdapterManager object
this.myTableTableAdapter.Fill(this.typedDataSet.MyTable)
bindingSource.DataSource = this.typedDataSet;
bindingSource.DataMember = "MyTable";
dataGridView.DataSource = bindingSource;