Databind using relationships

  • Thread starter Thread starter priyanka
  • Start date Start date
P

priyanka

Hi All,

I am trying to display parent child records in two separate datagrids.
The 2 tables have the relationship set in the dataset. I bind the
datagrid using the relationship names, so that when a parent record is
selected in the first grid, the corresponding child records are
displayed in the second grid automatically.

I set the relationship in the dataset in a separate class and the
binding in another class. I am not able to get the second grid to
display child records automatically corresponding to the parent. I hav
pasted my code below. Any help would be great!

Thanks

Public Class GenreData
......
......
Public Function GetGenreFromSql()
'Add relationships between tables
genreDS.Relations.Add("genre2Stations",
GenreData.genreDS.Tables(GENRE_TBL).Columns("genre_no"),
_
GenreData.genreDS.Tables(STATION_TBL).Columns("genre_no"))

End function
end class

public class DataGridPopulator

public function BindGrid(byref tmpGrid as datagrid)
tmpGrid.SetDataBinding(GenreData.genreDS,
"genre_tbl.genre2Stations")
end function

end class
 
Hi,

The Master - child grid doesnt work if the first grid is a view as in
my case. I hav the parent grid as a view since there are too many
records to be displayed.

Is there a way to make the parent child relationship work with the
view.

Priyanka
 
In the case of binding to a DataView, you are binding to a Table, not a
DataSet. Therefore, there is no relationship in the DataObject being bound
to your Master Table. No relationship = no Master-Detail form. In this case,
you'll want to bind to a DataViewManager, which is basically a DataView for
a DataSet. Here's the proper way to bind:

dataGrid1.SetDataBinding( dataSet1.DefaultViewManager, "Table1" );
dataGrid2.SetDataBinding( dataSet1.DefaultViewManager, "Table1.Relation1" );

I would read http://www.oreilly.com/catalog/adonetian/chapter/ch12.pdf for
further information about Binding and DataViewManagers. Also, consult MSDN
to find out how to use the DataViewManager to access the DataView for the
Master Table.

~Greg Persson
MCP
 
Back
Top