0
votes

I have a model class which have as a property, the list of details table related to it.

Ex, my master table contains datas about the package (date, cost, number)

And the detail table contains datas about pieces in the package (length, number, qte, width...)

I have already bound my master table to a datagridview with :

dgvAssemblages.DataSource = bsAssemblage
For Each objTmp As Object In lstTmp
    bsAssemblage.Add(objTmp)
Next
bsAssDet.DataSource = bsAssemblage
'bsAssDet.DataMember = "Details"

Here, bsAssemblage is the master bindingSource and bsAssDet is the Details one.

I don't understand the datamember thing, I understood that I've had to put in it the name of the table but it only works if I put in the name of a field...

Also, it bugs if the bindingSource is empty so I have to check if empty before binding it :S

So, I've already had the details grid to fill with an Event (OnEnter) but I've seen it should be possible to have it bind itself automatically...

Anyone can help me with this, maybe explaining a little bit hoe datamember should work :S

Thanks in advance!

1

1 Answers

0
votes

Nice, I've finnaly found how to link the grids!

The thing is, I was doing a couple of things wrong :S

Here's my new Code :

dgvAssemblages.AutoGenerateColumns = True
dgvAssDet.AutoGenerateColumns = True
bsAssemblage.DataSource = reqTable(Of tabAssemblage_Entete)("Assemblage_EntĂȘte", intCurrentProject) 'lstTmp
dgvAssemblages.DataSource = bsAssemblage
reqAssemblageDetails(intCurrentProject, dgvAssemblages.DataSource.List) 'Loads the Details
dgvAssDet.DataSource = bsAssemblage
dgvAssDet.DataMember = "Details"

I'm not sure of what made it work all fine, I guess the AutoDenerateColumns are for something in this.

Also, reqTable is nof Typed with (Of tabAss...), So it now knows what fields are in the dataSource even when empty, it wasn't like that wqhen I first wrote the code,

anyway, much more clean now! :)