winformsdata-bindingdatagridviewstrongly-typed-datasetbindingsource

Empty BindingSource problem


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

Database assembly

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.


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.