I am trying to create a master - detail type form where the datagrid is populated based on the forms current transaction number (it''s in a bound TextBox). Whenever the value changes in the TextBox, the Grid is reloaded with that data for the transaction number. The Trancation number is part of the Package Table. The Details table contains the related transaction number. I have a relation already set up in the schema called Tranno. The .net dataGrid uses the SetDataBindings method to perform this action. I cannot get this to work with the BoundDataGrid. SetDataBindings is not an option. I''ve tried many ways to set the datasource and datamember, but I''m drowning miserably. Can someone direct me to a solution, or a new way to bind the data to the TextBox?
Thanks
AD
Administrator
Syncfusion Team
February 10, 2004 06:42 PM UTC
Below is a sample showing a couple of ways to do this.
If you use TextBox.DataBinding.Add to bind to a textbox, then when you type into the textbox, you are actually changing the particular value in the datatable. I think what you want to do, is to type into the textbox, then use that to display something in the grid, not change any value in the datatable.
So, in the sample, textbox.Validated event is used to get the value and then filter the grid''s display to get this behavior.
If you want to use databinding to get this behavior, then I think you will need to switch your textbox to a combobox which can handle the complex binding. The sample also has this option implemented.
10711_1384.zip
WG
Wes Goad
February 11, 2004 09:25 AM UTC
I can''t open the project that was attached.
>Below is a sample showing a couple of ways to do this.
>
>If you use TextBox.DataBinding.Add to bind to a textbox, then when you type into the textbox, you are actually changing the particular value in the datatable. I think what you want to do, is to type into the textbox, then use that to display something in the grid, not change any value in the datatable.
>
>So, in the sample, textbox.Validated event is used to get the value and then filter the grid''s display to get this behavior.
>
>If you want to use databinding to get this behavior, then I think you will need to switch your textbox to a combobox which can handle the complex binding. The sample also has this option implemented.
>
>
10711_1384.zip
>
>
AD
Administrator
Syncfusion Team
February 11, 2004 10:06 AM UTC
It is a C# project done in VS 2002. I can download it and run it in both VS 2002 and VS 2003.
Exactly where are things failing? In downloading the zip file, unzipping the file, or trying to load the sln file into Visual Studio?
Below is the code for the form. You can just create a sample project with a a form1 on it, and replace the code with code below.
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;
}
}
}
WG
Wes Goad
February 11, 2004 10:19 AM UTC
Hi Clay,
I think I figured out what the problem is.I don''t have c# installed. I''m creating the project in VB using Visual Studio 2003.
I guess I''ll install it and start over.
Thanks for all your help!
AD
Administrator
Syncfusion Team
February 11, 2004 10:53 AM UTC
Here is a VB project.
9172_VB_9001.zip
WG
Wes Goad
February 11, 2004 11:15 AM UTC
Bless You!
AD
Administrator
Syncfusion Team
February 11, 2004 11:44 AM UTC
I sent you the wrong project. I will post the correct one in a few minutes.
AD
Administrator
Syncfusion Team
February 11, 2004 11:52 AM UTC
Sorry about that. Try this one.
10711_VB_6124.zip
WG
Wes Goad
February 11, 2004 12:50 PM UTC
I appreciate all the info you''ve provided. I just wish I had your knowledge.
WG
Wes Goad
February 12, 2004 06:22 PM UTC
I figured it out using the Properties of the DataGrid. I set up a relationship in the schema for the DataSet and used that relation value in the data member properies of the DataGrid.
Thanks!