//设置构造函数的参数 private void SetMasterControl(DataSet cDataset, controlType eControlType) { //1.控件初始化赋值 this.Controls.Add(childView); InitializeComponent(); _cDataset = cDataset; childView._cDataset = cDataset; CellStyle.applyGridTheme(this); Dock = DockStyle.Fill; EControlType = eControlType; this.AllowUserToAddRows = false; //2.通过读取DataSet里面的Relations得到表的关联关系 if (cDataset.Relations.Count <= 0) { return; } DataRelation oRelates; if (eControlType == controlType.outside) { oRelates = cDataset.Relations[1]; childView.Add(oRelates.ParentTable.TableName, oRelates.ParentColumns[0].ColumnName, oRelates.ChildColumns[0].ColumnName); } else if (eControlType == controlType.middle) { oRelates = cDataset.Relations[cDataset.Relations.Count - 1]; childView.Add2(oRelates.ChildTable.TableName); } //3.设置主外键对应关系 oRelates = cDataset.Relations[0]; //主表里面的值,副表里面的过滤字段 setParentSource(oRelates.ParentTable.TableName, oRelates.ParentColumns[0].ColumnName, oRelates.ChildColumns[0].ColumnName); }
public void Add2(string tableName) { //TabPage tPage = new TabPage() { Text = pageCaption }; //this.Controls.Add(tPage); DataGridView newGrid = new DataGridView() { Dock = DockStyle.Fill, DataSource = new DataView(_cDataset.Tables[tableName]) }; newGrid.AllowUserToAddRows = false; //tPage.Controls.Add(newGrid); this.Controls.Add(newGrid); CellStyle.applyGridTheme(newGrid); CellStyle.setGridRowHeader(newGrid); newGrid.RowPostPaint += CellStyle.rowPostPaint_HeaderCount; childGrid.Add(newGrid); }
public void Add(string tableName, string strPrimaryKey, string strForeignKey) { //TabPage tPage = new TabPage() { Text = pageCaption }; //this.Controls.Add(tPage); var newGrid = new MasterControl(_cDataset, controlType.middle) { Dock = DockStyle.Fill, DataSource = new DataView(_cDataset.Tables[tableName]) }; newGrid.setParentSource(tableName, strPrimaryKey, strForeignKey);//设置主外键 //newGrid.Name = "ChildrenMaster"; //tPage.Controls.Add(newGrid); this.Controls.Add(newGrid); //this.BorderStyle = BorderStyle.FixedSingle; CellStyle.applyGridTheme(newGrid); CellStyle.setGridRowHeader(newGrid); newGrid.RowPostPaint += CellStyle.rowPostPaint_HeaderCount; childGrid.Add(newGrid); }