What you do is bind the sub-grid to the relation, and then just set the CurrencyManager.Position to the current index of the list. For example (based on Northwind), assume you have a DataSet (_ds) with two tables (Orders and OrderDetails), and a relationship (CustOrders). The ListBox is bound to Orders, showing the OrderID only (not hugely useful, but it suffices for this example). The set the grid (dgOrderDetails) bindings like so:
You just set the Position of the CurrencyManager for the parent table, and since there is a table relation (which is tracked by the binding), the sub grid changes, reflecting only the sub-rows for the selected parent row.
Mail me (contact details on daveandal dot net) if you want a full sample.
Dave
Thanks for the great answer. It does simplify work a lot when working with a listbox.
however, what about when I want to use a TreeView as the Parent Data Source?
I have no way to data bind a treeview, so I use the Tag property of each node to hold a DataRow object. Now, once I have a clicked node, How do i find the correct Index to set the position to?
Can you write an article about how to bind a dataset to a datagrid with lookup tables? It is impossible to find this on the internet.
For example: I have a customer table that has a 2 digit code that represents the country they live in. That 2 digit code coorespondes to another table that has a list of all the countries.
This is a really good example. But I just have one other question. I know that I can delete rows of the datagrid by using the delete button on my keyboard, but I would like to also place a delete button on the datagrid form itself.
Could you please tell me how to determine which dataview i.e. (tables 1, 2 or 3 ) that the user is currently in on a drill-down datagrid with 3 relations so that I can delete the correct rows from the correct datatables when the user clicks my ‘delete button’.
In other words, how can I determine which row is clicked on which table?
I'm afraid I don't know the answer to that one.
And I really don't have time to check right now.
perhaps over the weekend..
Ok Roy,
Any help would be greatly appreciated...this has really been a headache for me :)
Thanks again,
Madyooper
About that delete button....
I have a problem i am trying to solve which is close to this one.
The question is : Can i programatically invoke the delete row operation caused by pressing the delete key when using a button to do the delete?
My problem is this - I cannot update the DataTable until the user presses a Save Button. When i press the delete button I have no problem deleting the selected row, However after the first time the SelectedRowIndex cannot be used as an index for the rows in the DataTable (Again - i cannot do accept changes until the user presses Save) cause the number of rows in the grid now does not correspond to the number of rows in the DataTable.
Any ideas on how i do this??
Thanks in advance
Arik
About that delete button....
How can I catch the event when the user presses the delete button on any ro in Datagrid so that I can write a code where the data can be deleted from the database also . As visible the row is deleted but not from database .
Any ideas.....
Thanks
Atul
how can i prevent changes when go next or prev record without pressing save button?