日期:2014-05-19  浏览次数:20759 次

關于DataTable中,有設置Expression屬性的列不會激發ColumnChanging事件
using   System;
using   System.Drawing;
using   System.Collections;
using   System.ComponentModel;
using   System.Windows.Forms;
using   System.Data;
using   System.Data.SqlClient;

namespace   test
{
///   <summary>
///   Form4   的摘要描述。
///   </summary>
public   class   Form4   :   System.Windows.Forms.Form
{
private   System.Windows.Forms.DataGrid   dataGrid1;
private   DataSet   myDataSet=new   DataSet();
///   <summary>
///   設計工具所需的變數。
///   </summary>
private   System.ComponentModel.Container   components   =   null;

public   Form4()
{
InitializeComponent();
}

///   <summary>
///   清除任何使用中的資源。
///   </summary>
protected   override   void   Dispose(   bool   disposing   )
{
if(   disposing   )
{
if(components   !=   null)
{
components.Dispose();
}
}
base.Dispose(   disposing   );
}

#region   Windows   Form   設計工具產生的程式碼
///   <summary>
///   此為設計工具支援所必須的方法   -   請勿使用程式碼編輯器修改
///   這個方法的內容。
///   </summary>
private   void   InitializeComponent()
{
this.dataGrid1   =   new   System.Windows.Forms.DataGrid();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//  
//   dataGrid1
//  
this.dataGrid1.DataMember   =   " ";
this.dataGrid1.Dock   =   System.Windows.Forms.DockStyle.Fill;
this.dataGrid1.HeaderForeColor   =   System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location   =   new   System.Drawing.Point(0,   0);
this.dataGrid1.Name   =   "dataGrid1 ";
this.dataGrid1.Size   =   new   System.Drawing.Size(568,   357);
this.dataGrid1.TabIndex   =   0;
//  
//   Form4
//  
this.AutoScaleBaseSize   =   new   System.Drawing.Size(5,   15);
this.ClientSize   =   new   System.Drawing.Size(568,   357);
this.Controls.Add(this.dataGrid1);
this.Name   =   "Form4 ";
this.Text   =   "Form4 ";
this.Load   +=   new   System.EventHandler(this.Form4_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);

}
#endregion

private   void   Form4_Load(object   sender,   System.EventArgs   e)
{
using(SqlDataAdapter   ada=new   SqlDataAdapter( "   SELECT   *, ' '   as   tmp   FROM   Categories ", "data   Source=.;database=Northwind;user   id=sa;pwd=; "))
{
ada.Fill(this.myDataSet, "tt ");
this.myDataSet.Tables[0].Columns[ "tmp "].Expression= "iif(CategoryID> 3, 'small ', 'big ') ";
this.myDataSet.Tables[0]