setting default values in datagridview

alander

Well-known member
Joined
Jun 26, 2007
Messages
120
Location
Singapore
Programming Experience
5-10
Hi,
i am use MS Access database btw..

i got a problem here,

i got a datagrid, showing a normalize order details table containing product id (product table key), order id (order table key), they are composite keys.. linking order and products together with other order details such as price etc.

I tried to use a non-data binded column and bind it to my product id, via a combo box for users to select the product id on edit/add data.. the product id dun show and i do not know how to save it into the order details table

Another problem here..

I wanna set default value for my order id in the datagrid, i got a field in the form to show the order id, however, i need to pass this order id into the datagridview

how can i achieve that?

any help will be appreciated..

To show what i want to achieve, i have attached some screenshots.
 

Attachments

  • vb.JPG
    vb.JPG
    55.7 KB · Views: 52
I wanna set default value for my order id in the datagrid, i got a field in the form to show the order id, however, i need to pass this order id into the datagridview

how can i achieve that?

OK, I know you are trained in VS2003, assuming you are doing this with VS2005?

You need to make sure that you have set your grid datasource up correctly. Within your dataset you will have your relationship between your Work Order and your Order tables.

Within VS2005 you have your "Data Sources" panel over to the righthand side of the GUI.

What you need to do is click the + symbol next to WorkOrder table, and within there, at the bottom of the expanded list will be any related tables. You should see your relation to your Orders table.

I would delete your current OrdersBindingSource, and drag this relation onto your form and into your grid. This will now bind the grid to this relationship.

By having the relations set right, the PK and FK match, and adding new rows to the child table will set the correct FK, in your case the OrderID number.

Screenshot is of my works order table. you can see the related table, and all you do is drag this onto your form to automatically create the grid, or you drop it onto an existing grid to change that grid's dataSource.
 

Attachments

  • Image2.jpg
    Image2.jpg
    8.6 KB · Views: 42
ic.. thanks.. i did but its not showing..I will try ur solution
 
i need to pass this order id into the datagridview
Not quite.. you dont pass data into a datagridview because DGV doesnt contain any data, it jsut shows you data from the model underneath.

As an analogy, suppose your window looks out on a tree, and you dont want to see that tree.. do you go outside and cut it down, or do you have the window cleaner come round and clean the image of a tree off the glass?

The window shows you the outside world. You dont manipualte the window, you manipulate the world and the window shows the updated version
 
Not quite.. you dont pass data into a datagridview because DGV doesnt contain any data, it jsut shows you data from the model underneath.

As an analogy, suppose your window looks out on a tree, and you dont want to see that tree.. do you go outside and cut it down, or do you have the window cleaner come round and clean the image of a tree off the glass?

The window shows you the outside world. You dont manipualte the window, you manipulate the world and the window shows the updated version


ok i supposed i got wat u mean now.. ty
 
OK, I know you are trained in VS2003, assuming you are doing this with VS2005?

You need to make sure that you have set your grid datasource up correctly. Within your dataset you will have your relationship between your Work Order and your Order tables.

Within VS2005 you have your "Data Sources" panel over to the righthand side of the GUI.

What you need to do is click the + symbol next to WorkOrder table, and within there, at the bottom of the expanded list will be any related tables. You should see your relation to your Orders table.

I would delete your current OrdersBindingSource, and drag this relation onto your form and into your grid. This will now bind the grid to this relationship.

By having the relations set right, the PK and FK match, and adding new rows to the child table will set the correct FK, in your case the OrderID number.

Screenshot is of my works order table. you can see the related table, and all you do is drag this onto your form to automatically create the grid, or you drop it onto an existing grid to change that grid's dataSource.

my PK in my parent table matches FK in my child table

i have followed what u have done, however whenever i do a

VB.NET:
Me.OrderDetail_Binding_Source.AddNew()

OR

Me.OrderDetail_Binding_Source.CurrencyManager.AddNew()

the thing still dun show.. any ideas?
 
Last edited:
Back
Top