Newbie question about DataGrid

M

Mika M

Hello!

If I add new row into databinded DataGrid by selecting for example certain
product code from columns drop down list, is it possible to automatically
show for example description in the next cell to the right for this selected
product cell, but when saving content of the grid just save product codes
column data using DataAdapter.Update-method?

I mean it's like INNER JOIN query to the 'products' -tables
'description'-field in DB. Hopefully you understand my question, I'm
finnish.
 
K

Kathleen Dollard

Mika,

I assume this is Winforms.

You could do this a couple of ways, but why? Is there a compelling reason to
force your users to select the ID rather than the description? If so my
suggestion would be to use the ColumnChanging event of the underlying
datatable, then just don't save the description. The ColumnChanging event
will need access to the product list - either through a database call if
your pipe is near and fast and the product list is large, or by caching that
information if the pipe is far/narrow or the list is small.

Kathleen
 
M

Mika M

Thank you Kathleen of your reply, and yes it's Winforms. Maybe it's better
tell my problem more simple by this way:

I have DataBase with...

'Products' -table with (in this case needed) colums/fields: ProductID,
Description
'Customers' -table with (in this case needed) colums/fields: CustomerID,
CustomerName, CustomerLocation
'ProductCustomers' -table with (in this case needed): CustomerID, ProductID

I want to show product in the upper/master -grid, and lower/detail -grid
contains customers for this product.

Problem is when I show/add/update customer into the lower grid using
combobox, this selected customer may have many locations or plants with same
customer name - so next cell should contain location to specify which
location or plant is it question about. When I save this customer then it
should save only (in this case needed) ProductID and CustomerID into
'ProductCustomers' -table.

So I use DataMap to change CustomerID to show CustomerName, but how to show
Location in the next cell too? Maybe I'm doing something wrong? Maybe I
should split customers and customer locations into two tables into DB - or
should I ?

--
Thanks in advance of any reply!

Mika

Kathleen Dollard said:
Mika,

I assume this is Winforms.

You could do this a couple of ways, but why? Is there a compelling reason to
force your users to select the ID rather than the description? If so my
suggestion would be to use the ColumnChanging event of the underlying
datatable, then just don't save the description. The ColumnChanging event
will need access to the product list - either through a database call if
your pipe is near and fast and the product list is large, or by caching that
information if the pipe is far/narrow or the list is small.

Kathleen
 
K

Kathleen Dollard

Mika,

Are the combo boxes in a DataGrid? If so, is it a normal DataGrid, or have
you derived a special combo box column type?

Assuming the combo box is outside a DataGrid, you'll want to bind the
Company combo box to one DataView and the Location to another. Probably it
will be simplest if these are separate DataSets, but that does not mean you
need to change your database, just your stored procedures. This provides the
drop down information for the combo box. The datavalues themselves can be
bound or unbound. In the DropDown event of the Location combo box, you need
to filter the Locations DataView to only those valid for that customer.

Hopefully that gives you a little help, but I don't think I understand how
this relates to the DataGrid in the title, so I may have missed the mark.

Kathleen


Mika M said:
Thank you Kathleen of your reply, and yes it's Winforms. Maybe it's better
tell my problem more simple by this way:

I have DataBase with...

'Products' -table with (in this case needed) colums/fields: ProductID,
Description
'Customers' -table with (in this case needed) colums/fields: CustomerID,
CustomerName, CustomerLocation
'ProductCustomers' -table with (in this case needed): CustomerID, ProductID

I want to show product in the upper/master -grid, and lower/detail -grid
contains customers for this product.

Problem is when I show/add/update customer into the lower grid using
combobox, this selected customer may have many locations or plants with same
customer name - so next cell should contain location to specify which
location or plant is it question about. When I save this customer then it
should save only (in this case needed) ProductID and CustomerID into
'ProductCustomers' -table.

So I use DataMap to change CustomerID to show CustomerName, but how to show
Location in the next cell too? Maybe I'm doing something wrong? Maybe I
should split customers and customer locations into two tables into DB - or
should I ?

--
Thanks in advance of any reply!

Mika

Kathleen Dollard said:
Mika,

I assume this is Winforms.

You could do this a couple of ways, but why? Is there a compelling
reason
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top