日期:2014-05-18 浏览次数:20925 次
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace testnewdgv { public partial class Form1 : Form { public Form1() { InitializeComponent(); } DataTable dt = new DataTable("useraction"); private void Form1_Load(object sender, EventArgs e) { //DataSet ds = new DataSet(); DataColumn column; column = new DataColumn("url", Type.GetType("System.String")); column.Caption = "url"; dt.Columns.Add(column); column = new DataColumn("totaltime", Type.GetType("System.String")); column.Caption = "totaltime"; dt.Columns.Add(column); column = new DataColumn("efftime", Type.GetType("System.String")); column.Caption = "efftime"; dt.Columns.Add(column); //ds.Tables.Add(dt); //BindingSource bds = new BindingSource(); //bds.DataSource = ds; dgv1.AutoGenerateColumns = true; dgv1.DataMember = "useraction"; dgv1.DataSource = dt; dgv1.AllowUserToAddRows = false; } private void button1_Click(object sender, EventArgs e) { DataRow dr; dr = dt.NewRow(); dr["url"] ="www.baidu.com"; dr["totaltime"] = "01:11:11"; dr["efftime"] = "01:11:13"; dt.Rows.Add(dr); } } }