Master/Detail DataSet and DataBindigs - applying RowFilter

G

Guest

Hi friends!

I've a DataSet with 2 tables inside. The relation and mappings between both
are set and ok.
I need to create a Master/Detail datagrid based on DataBindings.

'DataGrid1 shows the Master view and TextBox1 shows one field's content, as
follow:
DataGrid1.SetDataBinding(DataSet1, "MasterTable")
TextBox1.DataBindings.Add(New Binding("Text", DataSet1, "MasterTable.ID"))

'DataGrid2 show the Details view
DataGrid2.SetDataBinding(DataSet1, "MasterTable.MasterTableToChildTable")

It's working fine. But now I need to set an expression to filter the rows
showed in DataGrid1. If I do that, the rows won't be filtered because de
DataGrid1 is bound to the DataSet directly instead of a DataView.
I'd like to know how can I apply a RowFilter property and have the child
DataGrid working as well.

Thanks
 
G

Guest

Ok guys. I've just solved my issue.

'Bind the DataGrid1 and TextBox1 to DataSet1.Tables("MasterTable")
DataGrid1.SetDataBinding(DataSet1.Tables("MasterTable"), String.Empty)
TextBox1.DataBindings.Add(New Binding("Text", DataSet.Tables("MasterTable"),
"ID"))

'Bind the DataGrid2 to the Relation of DataSet1.Tables("MasterTable")
DataGrid2.SetDataBinding(DataSet1.Tables("MasterTable"),
"MasterTableToChildTable")

'to set the RowFilter, just do the following:
CType(DataSet1.DataSource, System.Data.DataTable).DefaultView.RowFilter =
"(RowFilter String)"

Everything is working like a charm!

Thanks anyway!
 
C

Cor Ligthert [MVP]

Andrew,

I assume that there is a typo in this sample.

A dataset has not datasource.

You probably did mean.
CType(DataSet1.DataSource, System.Data.DataTable).DefaultView.RowFilter =
"(RowFilter String)"
DirectCast(DataGrid1.DataSource,
System.Data.DataTable).DefaultView.RowFilter =
"(RowFilter String)"

Which is the same as I look to your code as

Dataset1.Tables("MasterTable").DefaultView.RowFilter = "<RowFilter String>"

I hope this helps,

Cor
 

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