Sure. Following (I couldn't send it as an attachment, for some reason) is a
simple Form1.cs file which demonstrates the stuff in my last post. (Let me
know if you need more files than that.) Thanks for your help.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace DatagridVerification
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.Label label1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.label1 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.d ataGrid1)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.Anchor =
((System.Windows.Forms.AnchorStyles)((((System.Win dows.Forms.AnchorStyles.To
p | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(40, 24);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(360, 224);
this.dataGrid1.TabIndex = 0;
//
// label1
//
this.label1.Anchor =
((System.Windows.Forms.AnchorStyles)(((System.Wind ows.Forms.AnchorStyles.Bot
tom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.label1.Location = new System.Drawing.Point(192, 256);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 23);
this.label1.TabIndex = 1;
this.label1.Text = "label1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(440, 294);
this.Controls.Add(this.label1);
this.Controls.Add(this.dataGrid1);
this.Name = "Form1";
this.Text = "Form1";
this.Closing += new
System.ComponentModel.CancelEventHandler(this.Form 1_Closing);
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.d ataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
DataGridTableStyle dgts = new DataGridTableStyle();
dgts.MappingName = "MyTable";
dataGrid1.TableStyles.Add(dgts);
DataTable dt = GetTheTable();
dataGrid1.DataSource = dt;
for (int i = 0; i < dt.Columns.Count; ++i)
{
DataGridTextBoxColumn dgtbc = dgts.GridColumnStyles[i] as
DataGridTextBoxColumn;
if (dgtbc != null)
{
dgtbc.TextBox.Validating += new System.ComponentModel.
CancelEventHandler(dataGrid_Validating);
}
}
}
int test = 0;
private void dataGrid_Validating(object sender, CancelEventArgs e)
{
test += 1;
label1.Text = test.ToString();
e.Cancel = true;
}
private DataTable GetTheTable()
{
DataTable dt = new DataTable("MyTable");
int nCols = 4;
int nRows = 10;
for(int i = 0; i < nCols; i++)
dt.Columns.Add(new DataColumn(string.Format("Col{0}", i)));
for(int i = 0; i < nRows; ++i)
{
DataRow dr = dt.NewRow();
for(int j = 0; j < nCols; j++)
dr[j] = string.Format("row{0} col{1}", i, j);
dt.Rows.Add(dr);
}
return dt;
}
private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
e.Cancel = false;
}
}
}
"Tian Min Huang" <ti******@online.microsoft.com> wrote in message
news:1b**************@cpmsftngxa06.phx.gbl...
Hello Jack,
Thanks for your update. I reviewed your description carefully, and I think
more information is needed before moving forward:
Could you post a simple project which is able to reproduce the problem? I
believe that will be most helpful for me to pinpoint the problem and
resolution.
I look forward to your response.
Have a nice day!
Regards,
HuangTM
Microsoft Online Partner Support
MCSE/MCSD
Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.