Groups | Blog | Home
all groups > dotnet windows forms controls > november 2006 >

dotnet windows forms controls : DataGridView doesn't change with new parent record


JD
11/29/2006 3:31:20 PM
I converted my VS2003 app to 2005 and replaced the old dataGrids with the
DataGridView. Now the data in the new grid does not change when I move to
the next parent record. I find the 'HELP' less than helpful. How do I get
them coordinated again?
Is there a good VS2005 VB Programming book out yet?

Thank you for your help.
jd

RobinS
11/29/2006 10:25:41 PM
Please be more specific. What is in your grid, and what
are you moving to the next parent record? I don't understand.
Do you have some kind of parent data, and it has children
displayed in a grid, and when you move the parent you want
the right children displayed?

Try Tim Patrick's "Start to Finish VB2005" book to learn VB2005.

For databinding, read Brian Noyes' databinding book. (It's
in C#, but he has the code available in VB too).

Robin S.
------------------------------------
[quoted text, click to view]

JD
11/30/2006 8:22:23 AM
Thanks Robin for the references.
Ok I will be more specific.
I have a windows form and datagrid created using the VS2003 Data Form
Wizard. The form displays data on streams and the grid displays fish data
from the stream. I converted this app to VS2005 and changed the data grid to
the new DataGridView (because of the new features in this control) and now
when I change the parent record (using the next and previous record buttons)
the child records are not in sync. You're right in that it is a databinding
problem. The help is not very clear to me on what to do, there's something
about binding the DataGridview to the relation between the parent and the
child. Will the book you referenced deal with this?

thanks,


[quoted text, click to view]

RobinS
11/30/2006 8:57:14 AM
You have to bind the grid with the children to the
data relation between the parent and the children.

Here's an example against Northwind. I have a
CustomersDataSet that has Customers and Orders in it.

I have a CustomersBindingSource and a Customers_OrdersBindingSource.

The CustomersBindingSource binds to controls on the form.
My MoveNext/MovePrevious, etc., buttons move through the
CustomersBindingSource.

The Customers_OrdersBindingSource binds to the grid with the
children (orders) in it.

When you select a customer, it shows the associated orders.

Here's how to do the binding:

Dim nwData as CustomersDataSet = CustomersDataSet.GetCustomers()

CustomersBindingSource.DataSource = nwData
CustomersBindingSource.DataMember = "Customers"
CustomersDataGridView.DataSource = CustomersBindingSource

Customers_OrdersBindingSource.DataSource = CustomersBindingSource
Customers_OrdersBindingSource.DataMember = "FK_Orders_Customers"
OrdersDataGridView.DataSource = Customers_OrdersBindingSource

And yes, this is all in Brian's book, along with a lot
more info about data binding.

Robin S.
-----------------------------------------------

[quoted text, click to view]

RobinS
12/5/2006 11:36:58 AM
It has some really cool stuff in it. It was worth the
price just for the info on how to use the Formatting
and Parsing events on that DataGridView. Glad you
like it.

Robin S.
-----------------------------------
[quoted text, click to view]

JD
12/5/2006 12:31:31 PM
Thanks Robin,
I bought Brian's book and I would highly recommend it as well.


[quoted text, click to view]

AddThis Social Bookmark Button