黄生
|
C# code
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 WindowsFormsApp8
{
public partial class Form1 : Form
{
DataTable dt = new DataTable();
int count = 100000;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
initTable();
DataBinds();
timer1.Start();
}
private void initTable()
{
DataColumn dc = new DataColumn("序号", typeof(string));
dt.Columns.Add(dc);
dc = new DataColumn("呼叫别名", typeof(string));
dt.Columns.Add(dc);
dc = new DataColumn("呼叫人ID号", typeof(string));
dt.Columns.Add(dc);
dc = new DataColumn("呼叫类型", typeof(string));
dt.Columns.Add(dc);
for (int i = 1; i < 99999; i++)
{
dt.Rows.Add(i.ToString(), "张三" + i.ToString(),i.ToString(),"电话");
}
}
private void DataBinds()
{
this.dataGridView1.DataSource = dt;
dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.RowCount - 1;
}
private void btnInsert_Click(object sender, EventArgs e)
{
//在10000条后插入
DataRow dr = dt.NewRow();
dr["序号"] = 10001;
dr["呼叫别名"] = "插入列";
dr["呼叫人ID号"] = 10001;
dr["呼叫类型"] = "电话";
dt.Rows.InsertAt(dr,10000);
DataBinds();
MessageBox.Show("成功");
}
private void timer1_Tick(object sender, EventArgs e)
{
dt.Rows.Add(count.ToString(), "张三" + count.ToString(), count.ToString(), "电话");
count++;
DataBinds();
}
}
} |
|