advice needed on how to construct form/table

johncassell

Well-known member
Joined
Jun 10, 2007
Messages
120
Location
Redcar, England
Programming Experience
Beginner
Hi there,

I am looking for some advice on how best to construct the following:

My users need a datagrid where they can update the products to be produced for a particular job number. Example: In the image below, they would type '1' in the empty text box and it would bring up all the products for that job number. All they need to see in the datagrid is the product name and the quantity.

I can get the tableadapter to fill based on what is in the textbox but at the moment the users would have to type the job number in next to the new product and quantity which is what I am trying to avoid.

Can someone show me the best way to get this please?

Thanks

John
 

Attachments

  • formexample.JPG
    formexample.JPG
    24.9 KB · Views: 45
When you create the form, you add the bindingsource to your parent data, and to your child data.

As an example I'm going to use my Recipe and Recipe Ingredients.
Recipe = parent table
RecipeIngredient = child table

I can add a new Recipe, it gets given an ID number, and then when I add a new ingredient, it pulls across that ID number into the child without me doing anything.

ParentBindingSource = the recipe table from the dataSources pane.
ChildBindingSource = the relationship recipeingredients table that expands from the recipe table in the datasources


Then on the form, the properties of the ChildBindingSource are set so that the DataMember is set to the relationship name.
 

Attachments

  • Image2.jpg
    Image2.jpg
    16.8 KB · Views: 39
Hi Arg,

appreciate the detailed reply. Thanks a lot for that.

The thing is that I only have one table at the moment "JobsTable" with the four columns so I don't need to go into relationships (I don't think :)).

Would I need to add a second table for this to work?

Thanks

John
 
Would I need to add a second table for this to work?

You see to be describing a standard master/detail relationship

1 job has many products. A job also has info about itself - who is it for, when was it started, when is it due?

So you would have a jobs table with JobID (1) as the primary key
And a Products table with Job Id as a foreign key


Read the DW2 link in my sig, section on creating a simple data app. It features a Customer (job) Orders (products) scenario
 
Hi Again,

sorry for late reply but been busy. I have just got round to looking at this again but for the life of me I cannot figure out what is going wrong.

cjard, I took your advice and looked at the data walkthrough. I did everything it said and it worked perfect (As i wish my app would). I modified my app to be as close a match as possible including relationships but here is my problem.

In the walkthrough, the CustomerID column on the OrdersDataGrid auto-populates with the name when you attempt to add a new line. This is what I need but it is just not happening.

Tearing my hair out now. Can anyone advise where I may be going wrong at all?

Thanks a lot

John
 
When a DataRelation exists between two DataTables (and it can be any type of datarelation: relation or foreignkey with or without cascading updates/deletes)
And the child bindingsource is bound to the relation on the parent binding source
Then any call to AddNew() on the child binding source will automatically retrieve the current values of the parent binding source, for all related fields, and set them to be the default values for the new record.
Note that unless you call EndEdit on the parent BEFORE you(or a datagrid implicitly) call AddNew() on the child you will encounter problems; the relationship will function correctly, but the child data will be destroyed when EndEdit on the parent is called. It's a nuisance.

Check that you have:
A DataRelation
The relation is enabled
A parent controls, group of controls or datagridview
The parent controls are bound to a parent binding source
The parent bindingsource is bound to the parent datatable
A child control, group of controls or a datagridview
The child controls are bound to the child bindingsource
The child bindingsource is bound to the relation of the parent binding source
The parent datatable contains at least one row of data (note that calling addnew adds the item to the bindingsource list only, not the table. Commit to table occurs upon EndEdit())
The parent binding source .Current is pointing to a valid row
Call AddNew on the child bindingsource
 
Sorted it, played around a bit and your message really helped.

My datagrid was bound to the child bindingsource instead of parent.

Thank ck for that, been doing my head in!!

Thanks a lot mate, really appreciate your time and help. That goes to Arg81 also.

Regards

John
 
Sorted it, played around a bit and your message really helped.

My datagrid was bound to the child bindingsource instead of parent.
Er.. it should be ;)

See my notes:
The child controls* are bound to the child bindingsource
The child bindingsource is bound to the relation of the parent binding source
* i.e. your datagrid

You get more flexiblitiy if your bind :

grid -> child bs -> relation on parent bs


Rather than:

grid -> relation on parent bs


But both work similarly
 
Hi again,

i was going to raise this in a new post but thought the history would help on my situation...

I thought that I was forcing the rows on my datagrid to have the same jobID as specified in my tableadapter.fillby code by default but it turns out that it is just picking a seemingly random jobID from that table

I have read all your notes above and unless I have missed something then I don't think the problem is there.

Is there any advice you could give please?

Thanks again

John
 
Back
Top