110,571
社区成员
发帖
与我相关
我的任务
分享
private void Form2_Load(object sender, EventArgs e)
{
//在dataGridView1中添加Column1和Column2
dataGridView1.AutoGenerateColumns = false;
DataTable tabel = new DataTable();
DataColumn col = new DataColumn("c1", typeof(int));//将数据设置成int
tabel.Columns.Add(col);
col = new DataColumn("c2");//不设置数据类型 它默认为string
tabel.Columns.Add(col);
for (int i = 0; i < 30; i++)
{
DataRow row = tabel.NewRow();
row[0] = i;
row[1] = i;
tabel.Rows.Add(row);
}
dataGridView1.DataSource = tabel;
Column1.DataPropertyName = "c1";
Column2.DataPropertyName = "c2";
//试试点排序 int型和string型的排序自动不一样。
}