I have a DataSet with two tables and a DataRelation established between them. I want to have two UltraGrids with ultraGrid1 bound to dataTable1 and ultraGrid2 bound to dataTable2, but I want dataTable2 to show only filtered data based on the row selected in ultaGrid1 where the data matches the critera from the DataRelation.
My attempts to do this end up with ultaGrid1 being a hierarchical grid, with the data in the data relation actually being under the "+" sign. Is it possible to do this? I can do it manually with DataViews, but I was wondering if there was an automatic solution through Data Binding. If there is an example you can point me to, I would appreciate it.
Thanks.
Bill
Hi Bill,
whheine said:My attempts to do this end up with ultaGrid1 being a hierarchical grid, with the data in the data relation actually being under the "+" sign. Is it possible to do this?
You can set the grid.DisplayLayout.ViewStyle to SingleBand on the first grid so it only shows the root band.
Then all you have to do is bind the second grid to the Relationship (not the child table), and it should all work automatically as long as both grids are on the same container or have the same BindingContext.
Thank Mike. Here is a code sample as to how I got it to work, if anyone else is interested:
SqlConnection connection = new SqlConnection(connectionString);
DataSet dataSet = new DataSet("Orders");
SqlDataAdapter da1 = new SqlDataAdapter("SELECT * FROM Orders", connection);
da1.TableMappings.Add("Table", "Orders");
da1.Fill(dataSet);
SqlDataAdapter da2 = new SqlDataAdapter("SELECT * FROM [Order Details]", connection);
da2.TableMappings.Add("Table", "OrderDetails");
da2.Fill(dataSet);
System.Data.DataRelation relation;
System.Data.DataColumn parentColumn;
System.Data.DataColumn childColumn;
parentColumn = dataSet.Tables["Orders"].Columns["OrderID"];
childColumn = dataSet.Tables["OrderDetails"].Columns["OrderID"];
relation = new System.Data.DataRelation("OrderDetailRelation", parentColumn, childColumn);
dataSet.Relations.Add(relation);
this.ultraGrid1.DataSource = dataSet.DefaultViewManager;
this.ultraGrid1.DisplayLayout.ViewStyle = Infragistics.Win.UltraWinGrid.ViewStyle.SingleBand;
this.ultraGrid2.DataSource = dataSet.DefaultViewManager;
this.ultraGrid2.DataMember = "Orders.OrderDetailRelation";