using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace DateWinForms
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dbgTable;
private DataSet ds;
private DataTable table;
private DataColumn col;
private DataRow row;
private System.Windows.Forms.MonthCalendar monthCalendar1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
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.dbgTable = new System.Windows.Forms.DataGrid();
this.monthCalendar1 = new System.Windows.Forms.MonthCalendar();
((System.ComponentModel.ISupportInitialize)(this.dbgTable)).BeginInit();
this.SuspendLayout();
//
// dbgTable
//
this.dbgTable.DataMember = "";
this.dbgTable.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dbgTable.Location = new System.Drawing.Point(8, 8);
this.dbgTable.Name = "dbgTable";
this.dbgTable.Size = new System.Drawing.Size(328, 224);
this.dbgTable.TabIndex = 0;
//
// monthCalendar1
//
this.monthCalendar1.Location = new System.Drawing.Point(144, 64);
this.monthCalendar1.Name = "monthCalendar1";
this.monthCalendar1.TabIndex = 1;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(424, 240);
this.Controls.Add(this.dbgTable);
this.Name = "Form1";
this.Text = "日期";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dbgTable)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
ds = new DataSet("datedb");
table = new DataTable("date");
ds.Tables.Add(table);
col = new DataColumn("Name",typeof(string));
table.Columns.Add(col);
col = new DataColumn("Date",typeof(string));
table.Columns.Add(col);
row = table.NewRow();
row["Name"] = "Name 1";
row["Date"] = "2001-12-1";
table.Rows.Add(row);
row = table.NewRow();
row["Name"] = "Name 2";
row["Date"] = "2001-12-1";
table.Rows.Add(row);
row = table.NewRow();
row["Name"] = "Name 3";
row["Date"] = "2001-12-1";
table.Rows.Add(row);
row = table.NewRow();
row["Name"] = "Name 4";
row["Date"] = "2001-12-1";
table.Rows.Add(row);
row = table.NewRow();
row["Name"] = "Name 5";
row["Date"] = "2001-12-1";
table.Rows.Add(row);
dbgTable.DataSource = ds.Tables[0].DefaultView;
DataGridTableStyle style = new DataGridTableStyle();
style.MappingName = table.TableName;
dbgTable.TableStyles.Add(style);
dbgTable.TableStyles[0].GridColumnStyles[0].Width = 100;
dbgTable.TableStyles[0].GridColumnStyles[1].Width = 100;
DataGridTextBoxColumn dgCol = (DataGridTextBoxColumn)dbgTable.TableStyles[0].GridColumnStyles[1];
DateTimePicker dateTime = new DateTimePicker();
dateTime.Width = 100;
dgCol.TextBox.Controls.Add(dateTime);
}
}
}
估计读起来相当恼火 没办法 只有慢慢读吧 LZ