using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Test
{
public partial class Form4 : Form
{
ComboBox combo = new ComboBox();
DateTimePicker date = new DateTimePicker();
DataSet ds = new DataSet();
public Form4()
{
InitializeComponent();
}
private void Form4_Load(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\Users.mdb");
OleDbDataAdapter da = new OleDbDataAdapter("select * from [User]", con);
try
{
da.Fill(ds, "User"); //填充数据集
}
catch (Exception er)
{
MessageBox.Show(er.Message);
}
// combo = new ComboBox(); //实例化combox
combo.Items.Add("男"); //加入内容
combo.Items.Add("女");
combo.Visible = false; //设为不可见
//combo.SelectedIndexChanged += new System.EventHandler(combo_SelectedIndexChanged);//注册委托
//combo.SelectedIndex=0;
this.dataGridView1.Controls.Add(combo); //将combox加入dataGridView控件
//date = new DateTimePicker(); //实例化DataTimePicker控件
date.Value = DateTime.Now; //初始化
//date.ValueChanged += new System.EventHandler(date_ValueChanged); //注册委托
date.Visible = false; //设为不可见
this.dataGridView1.Controls.Add(date); //加入dataGridView控件
this.dataGridView1.DataSource = ds.Tables[0]; //数据绑定
}
private void combo_SelectedIndexChanged(object sender,EventArgs e)
{
dataGridView1[dataGridView1.CurrentCell.RowNumber,dataGridView1.CurrentCell.ColumnNumber]=combo.SelectedItem;
}
private void date_ValueChanged(object sender, EventArgs e)
{
dataGridView1llData[dataGridView1.CurrentCell.RowNumber,dataGridView1.CurrentCell.ColumnNumber]=date.Value.ToShortDateString();
}
}
}
2005的dataGridView无RowNumber和ColumnNumber.