专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »DotNet » winformdatagrid:C#winform datagridview中自定义列头 »正文

winformdatagrid:C#winform datagridview中自定义列头

来源: 发布时间:星期六, 2008年11月22日 浏览:218次 评论:0
示例代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DataTable table = new DataTable();
DataColumn c1 = new DataColumn("ID", typeof(int));
table.Columns.Add(c1);
DataColumn c2 = new DataColumn("name", typeof(string));
table.Columns.Add(c2);

DataRow r1 = table.NewRow();
r1["ID"] = 1;
r1["name"] = "abc";
table.Rows.Add(r1);
DataRow r2 = table.NewRow();
r2["ID"] = 2;
r2["name"] = "bcd";
table.Rows.Add(r2);
this.dataGridView1.DataSource = table;
}
//改变HeaderText
private void button2_Click(object sender, EventArgs e)
{
this.dataGridView1.Columns["ID"].HeaderText = "第一列";
this.dataGridView1.Columns["name"].HeaderText = "第而列";
}

}
}
0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: