getting 'real' table datasource from grandchild datagrid that is based on dataview

A

astro

I have a datagrid that is two levels down from the dataview (i.e.
grandchild). I have spent 3 hours trying to get the syntax of determining
it's real datasource (i.e. not it's source based on it's relationship with
the dataview).

argh!

company
---> person
--->contact


-contact is the 'real' datasource for the grid
-company is a dataview used to populate several text controls on the form
and is the binder that the navigation ctrls use.
-the datagrid binds to the dataview with the datamember set to
"companyPerson.PersonContact" which of course is the relationship name
between the dv and the grandchild table.

Of course - if is do the following:
mydatatable = ctype(me.mydatagrid, dataview).table.tablename I get the
Company table! which is NOT what I need.

Is there a simple way of determing that the underlying table my datagrid is
hitting is 'contact' ?

Thank you.
 
B

Bart Mermuys

Hi,

astro said:
I have a datagrid that is two levels down from the dataview (i.e.
grandchild). I have spent 3 hours trying to get the syntax of determining
it's real datasource (i.e. not it's source based on it's relationship with
the dataview).

Why say "real" datasource ? When you bind the DataGrid to a DataView and set
DataMember to "relation1.relation2" then it's still using the original
grandchild DataTable (got from da.Fill). There is a DataView inbetween used
to filter the child rows depending on the current parent row.

You can get the DataView for the visible DataTable in the DataGrid
(grandchild in this case) using the CurrencyManager:

Dim cm as CurrencyManager = DirectCast( _
BindingContext( mygrid.DataSource, _
mygrid.DataMember ), CurrencyManager )

Dim currentDataView As DataView = _
DirectCast( cm.List, DataView )

Dim currentDataTable As DataTable = _
currentDataView.Table


Now, currentDataTable is the same DataTable as the one you can get from the
DataView DataSource and the Relations.


hth,
greetings
 
A

astro

Thanks Cor and Bart - I decided to just avoid this problem by adding the
tablename to the tag property of each datagrid on this form.

I have saved your comments and will tackle this issue on project #2.

)
 

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