Question

I have a problem with binding data using BindingSource, typed dataset and DataGridView. My problem is: BindingSource, therefore grid, is empty after binding data (bindingSource.Count is 0). I couldn't figure out what I'm doing wrong and I'd be very happy if anyone could help me with this. My application structure is like this: I have two assemblies, one is Winforms UI and other is database class library.

UI

  • DataGridView, datasource as BindingSource
  • BindingSource, datasource = DBAssembly.typedDataset, datamember = DBAssembly.typedDataset.myTable

Database assembly

  • Sql Server CE database
  • Typed Dataset
  • DB class for database operations

UI Code

OnLoad

this.db = new DB(); 
db.BindData(); 

DB Code

constructor

create typedDataSet object 
create typedDataSetTableAdapters.MyTableTableAdapter object 
create typedDataSetTableAdapters.TableAdapterManager object 

BindData()

this.myTableTableAdapter.Fill(this.typedDataSet.MyTable) 

I'd appreciate any help with this.

Was it helpful?

Solution

Well, the first thing to ask would be: what is this.typedDataSet.MyTable.Rows.Count? i.e. did the adapter do anything? If not, it has nothing to do with the binding.

Assuming it is non-empty, then what exact code are you using to set up DataSource and DataMember? I expect it should be:

bindingSource.DataSource = this.typedDataSet;
bindingSource.DataMember = "MyTable";
dataGridView.DataSource = bindingSource;

Alternatively, you could set the bindingSource's DataSource to this.typedDataSet.MyTable and leave the table blank.

Basically, I expect that you've told it the type of data to anticipate, but so far you haven't actually given it the data-set/data-table you want to use.

OTHER TIPS

Basically, I expect that you've told it the type of data to anticipate, but so far you haven't actually given it the data-set/data-table you want to use.

Marc you were right about this one. I hade to create a public DataSet property in my DB class and use it as DataSource of BindingSource to make this work. Thanks for the help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top