BoldSignEasily embed eSignatures in your .NET applications. Free sandbox with native SDK available.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace _10711
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private Syncfusion.Windows.Forms.Grid.GridDataBoundGrid gridDataBoundGrid1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
private Syncfusion.Windows.Forms.Grid.GridDataBoundGrid gridDataBoundGrid2;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.gridDataBoundGrid1 = new Syncfusion.Windows.Forms.Grid.GridDataBoundGrid();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.gridDataBoundGrid2 = new Syncfusion.Windows.Forms.Grid.GridDataBoundGrid();
((System.ComponentModel.ISupportInitialize)(this.gridDataBoundGrid1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.gridDataBoundGrid2)).BeginInit();
this.SuspendLayout();
//
// gridDataBoundGrid1
//
this.gridDataBoundGrid1.AllowDragSelectedCols = true;
this.gridDataBoundGrid1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.gridDataBoundGrid1.GridControlBaseEventsTarget = null;
this.gridDataBoundGrid1.Location = new System.Drawing.Point(24, 64);
this.gridDataBoundGrid1.Name = "gridDataBoundGrid1";
this.gridDataBoundGrid1.ShowCurrentCellBorderBehavior = Syncfusion.Windows.Forms.Grid.GridShowCurrentCellBorder.GrayWhenLostFocus;
this.gridDataBoundGrid1.Size = new System.Drawing.Size(344, 128);
this.gridDataBoundGrid1.SortBehavior = Syncfusion.Windows.Forms.Grid.GridSortBehavior.DoubleClick;
this.gridDataBoundGrid1.TabIndex = 0;
this.gridDataBoundGrid1.Text = "gridDataBoundGrid1";
//
// comboBox1
//
this.comboBox1.Location = new System.Drawing.Point(120, 24);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(104, 21);
this.comboBox1.TabIndex = 4;
this.comboBox1.Text = "comboBox1";
//
// button1
//
this.button1.Location = new System.Drawing.Point(184, 216);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(40, 23);
this.button1.TabIndex = 2;
this.button1.Text = "Load";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(120, 216);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(56, 20);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "1";
this.textBox1.Validated += new System.EventHandler(this.textBox1_Validated);
//
// gridDataBoundGrid2
//
this.gridDataBoundGrid2.AllowDragSelectedCols = true;
this.gridDataBoundGrid2.GridControlBaseEventsTarget = null;
this.gridDataBoundGrid2.Location = new System.Drawing.Point(32, 264);
this.gridDataBoundGrid2.Name = "gridDataBoundGrid2";
this.gridDataBoundGrid2.ShowCurrentCellBorderBehavior = Syncfusion.Windows.Forms.Grid.GridShowCurrentCellBorder.GrayWhenLostFocus;
this.gridDataBoundGrid2.Size = new System.Drawing.Size(352, 128);
this.gridDataBoundGrid2.SortBehavior = Syncfusion.Windows.Forms.Grid.GridSortBehavior.DoubleClick;
this.gridDataBoundGrid2.TabIndex = 5;
this.gridDataBoundGrid2.Text = "gridDataBoundGrid2";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(400, 422);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.gridDataBoundGrid2,
this.comboBox1,
this.button1,
this.textBox1,
this.gridDataBoundGrid1});
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.gridDataBoundGrid1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.gridDataBoundGrid2)).EndInit();
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
DataTable parentTable;
DataTable childTable;
private void Form1_Load(object sender, System.EventArgs e)
{
parentTable = GetParentTable();
childTable = GetChildTable();
DataSet ds = new DataSet();
ds.Tables.AddRange(new DataTable[]{parentTable, childTable});
DataRelation parentToChild = new DataRelation("ParentToChild", parentTable.Columns["parentID"], childTable.Columns["ParentID"]);
ds.Relations.AddRange(new DataRelation[]{parentToChild});
//=============== combobox code
this.comboBox1.BindingContext = this.BindingContext;
this.gridDataBoundGrid1.BindingContext = this.BindingContext;
this.comboBox1.DataSource = parentTable;
this.comboBox1.DisplayMember = "ParentName";
this.comboBox1.ValueMember = "parentID";
this.gridDataBoundGrid1.DataSource = parentTable;
this.gridDataBoundGrid1.DataMember = "ParentToChild";
//===============textbox code
this.gridDataBoundGrid2.BindingContext = new BindingContext(); //must be different from other bindingcontext
this.gridDataBoundGrid2.DataSource = childTable;
this.textBox1.Text = "0";
textBox1_Validated(this.textBox1, EventArgs.Empty);
}
private void textBox1_Validated(object sender, System.EventArgs e)
{
string filter = string.Format("[ParentID] = {0}", this.textBox1.Text);
this.childTable.DefaultView.RowFilter = filter;
}
private int numberParentRows = 5;
private int numberChildRows = 20;
private DataTable GetParentTable()
{
DataTable dt = new DataTable("ParentTable");
dt.Columns.Add(new DataColumn("parentID")); //lower case p
dt.Columns.Add(new DataColumn("ParentName"));
dt.Columns.Add(new DataColumn("ParentDec"));
for(int i = 0; i < numberParentRows; ++i)
{
DataRow dr = dt.NewRow();
dr[0] = i;//.ToString();
dr[1] = string.Format("parentName{0}", i);
dr[2] = string.Format("parentDesc{0}", i);
dt.Rows.Add(dr);
}
return dt;
}
private DataTable GetChildTable()
{
DataTable dt = new DataTable("ChildTable");
dt.Columns.Add(new DataColumn("childID")); //lower case c
dt.Columns.Add(new DataColumn("Name"));
dt.Columns.Add(new DataColumn("ParentID")); //upper case P
for(int i = 0; i < numberChildRows; ++i)
{
DataRow dr = dt.NewRow();
dr[0] = i.ToString();
dr[1] = string.Format("ChildName{0}",i);
dr[2] = (i % numberParentRows).ToString();
dt.Rows.Add(dr);
}
return dt;
}
}
}