Here it is.
If you change a value in the child page, it is reflected on the parent.
If you select a child row and hit the delete key, the parent still shows
the same value (still sees the deleted row). If you then change a value
on another row of the child, the parent is now calculating correctly and
no longer sees the deleted row.
Thanks for looking at it.
namespace test
{
using System;
using System.IO;
using System.Data;
using System.Windows. Forms;
using System.Drawing;
public class MyApp : System.Windows. Forms.Form
{
private System.Windows. Forms.TabContro l tabControl;
private System.Windows. Forms.TabPage parentPage, childPage;
private System.Windows. Forms.DataGrid parentDataGrid,
childDataGrid;
private DataSet ds;
private Button acceptButton;
public static void Main()
{
Application.Run (new MyApp());
}
public MyApp()
{
//
// Data Sets
//
this.ds = new DataSet();
CreateDS(ds);
//
// Parent Page
//
this.parentPage = new TabPage("Parent ");
this.parentPage .Size = new System.Drawing. Size(456,256);
this.parentData Grid = new System.Windows. Forms.DataGrid( );
parentDataGrid. BeginInit();
parentDataGrid. CaptionVisible = false;
parentDataGrid. Location = new System.Drawing. Point(2,2);
parentDataGrid. Size = new System.Drawing. Size(452,252);
parentDataGrid. TabIndex = 1;
parentDataGrid. Anchor = AnchorStyles.To p | AnchorStyles.Le ft |
AnchorStyles.Ri ght | AnchorStyles.Bo ttom;
parentDataGrid. DataSource = ds.Tables["Parent"].DefaultView;
((DataView)pare ntDataGrid.Data Source).AllowNe w = false;
((DataView)pare ntDataGrid.Data Source).AllowDe lete = false;
parentDataGrid. AllowNavigation = false;
parentDataGrid. EndInit();
this.parentPage .Controls.Add(t his.parentDataG rid);
//
// Child Page
//
this.childPage = new TabPage("Child" );
this.childPage. Size = new System.Drawing. Size(456,256);
this.childDataG rid = new System.Windows. Forms.DataGrid( );
childDataGrid.B eginInit();
childDataGrid.C aptionVisible = false;
childDataGrid.L ocation = new System.Drawing. Point(2,42);
childDataGrid.S ize = new System.Drawing. Size(452,212);
childDataGrid.T abIndex = 1;
childDataGrid.A nchor = AnchorStyles.To p | AnchorStyles.Le ft |
AnchorStyles.Ri ght | AnchorStyles.Bo ttom;
childDataGrid.D ataSource = ds.Tables["Child"].DefaultView;
((DataView)chil dDataGrid.DataS ource).AllowNew = false;
//((DataView)chil dDataGrid.DataS ource).AllowDel ete = false;
childDataGrid.A llowNavigation= false;
childDataGrid.E ndInit();
this.childPage. Controls.Add(th is.childDataGri d);
//
// Tab Control
//
this.tabControl = new System.Windows. Forms.TabContro l();
this.tabControl .Location = new System.Drawing. Point(2,2);
this.tabControl .Name = "Tab";
this.tabControl .SelectedIndex = 0;
this.tabControl .Size = new System.Drawing. Size(460,260);
this.tabControl .TabIndex = 0;
this.tabControl .Anchor = AnchorStyles.To p| AnchorStyles.Le ft |
AnchorStyles.Bo ttom | AnchorStyles.Ri ght;
tabControl.TabP ages.Add( new TabPage("X") ); // fix for layout
problems on first page - temp page
tabControl.TabP ages.Add(parent Page);
tabControl.TabP ages.Add(childP age);
//
// Accept Button
//
acceptButton = new Button();
acceptButton.Lo cation = new System.Drawing. Point(120,10);
acceptButton.Si ze = new System.Drawing. Size(100,24);
acceptButton.Te xt = "AcceptChanges" ;
acceptButton.Cl ick += new EventHandler( this.Accept_Cli ck );
this.childPage. Controls.Add(th is.acceptButton );
//
// Form
//
this.AutoScaleB aseSize = new System.Drawing. Size(5,13);
this.ClientSize = new System.Drawing. Size(464,264);
this.Text = "test";
this.Controls.A dd(this.tabCont rol);
}
private void Accept_Click(ob ject sender, EventArgs e)
{
ds.AcceptChange s();
}
public static void CreateDS(DataSe t ds)
{
DataTable parent = new DataTable("Pare nt");
parent.Columns. Add(new DataColumn("ID" , typeof(string)) );
parent.Columns. Add(new DataColumn("Ass igned", typeof(decimal) ));
parent.PrimaryK ey = new DataColumn[] { parent.Columns["ID"] };
ds.Tables.Add(p arent);
DataTable child = new DataTable("Chil d");
child.Columns.A dd(new DataColumn("ID" , typeof(string)) );
child.Columns.A dd(new DataColumn("Cat egory", typeof(string)) );
child.Columns.A dd(new DataColumn("Amo unt", typeof(decimal) ));
child.PrimaryKe y = new DataColumn[] { child.Columns["ID"],
child.Columns["Category"]
};
ds.Tables.Add(c hild);
ds.Relations.Ad d("ParentChild" ,
new DataColumn[1]{parent.Columns["ID"]},
new DataColumn[1]{child.Columns["ID"]});
parent.Columns["Assigned"].Expression =
"ISNULL(Sum(Chi ld(ParentChild) .Amount), 0)";
DataRow r = parent.NewRow() ;
r["ID"] = "A";
parent.Rows.Add (r);
for( Decimal d = 1; d< 10; d++ )
{
r = child.NewRow();
r["ID"] = "A";
r["Category"] = "B-" + d.ToString();
r["Amount"] = d;
child.Rows.Add( r);
}
ds.AcceptChange s();
}
}
}
*** Sent via Developersdex
http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!