using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace DataGrid
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
DataSet ds = new DataSet();
DataTable dt = new DataTable();
private int currentRow;
private int num;
private int price;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.dataGrid1 = new System.Windows.Forms.DataGrid();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.AlternatingBackColor = System.Drawing.SystemColors.Window;
this.dataGrid1.BackgroundColor = System.Drawing.SystemColors.AppWorkspace;
this.dataGrid1.CaptionFont = new System.Drawing.Font("Tahoma", 8F,
System.Drawing.FontStyle.Bold);
this.dataGrid1.DataMember = "";
this.dataGrid1.GridLineColor = System.Drawing.SystemColors.Control;
this.dataGrid1.HeaderBackColor = System.Drawing.SystemColors.Control;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.LinkColor = System.Drawing.SystemColors.HotTrack;
this.dataGrid1.Location = new System.Drawing.Point(16, 16);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.SelectionBackColor =
System.Drawing.SystemColors.ActiveCaption;
this.dataGrid1.SelectionForeColor =
System.Drawing.SystemColors.ActiveCaptionText;
this.dataGrid1.Size = new System.Drawing.Size(656, 360);
this.dataGrid1.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(688, 389);
this.Controls.Add(this.dataGrid1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void TextBox_LostFocus(object sender,System.EventArgs e)
{
DataTable dgvv=(DataTable)this.dg1.DataSource;
decimal num2 = Convert.ToDecimal(((DataGridTextBoxColumn)this.dg1.TableStyles[0].GridColumnStyles[5]).TextBox.Text);
decimal num3 = Convert.ToDecimal(((DataGridTextBoxColumn)this.dg1.TableStyles[0].GridColumnStyles[3]).TextBox.Text);
int currentRow = dg1.CurrentCell.RowNumber;
dg1[currentRow,6] = Convert.ToString(num2 * num3);
}
}