我现在ds数据集中有一个表格table1,它有三列A B C三列资料。我要用一个datagridview来显示table1种的三列数据,并且要改变在datagridview中显示时的列头名称。比如显示时应该是:第一列  第二列 第三列 
相应的第一列 显示 A列的数据  第二列 显示 B列的数据 第三列 显示 C列的数据。
要怎么写啊?
需要代码 ,谢谢。C#

解决方案 »

  1.   

    datagridview1.DataSource=ds.Tables["table1"];
    datagridview1.Columns[0].HeaderText="第一列";
      

  2.   

    dataGridView1.Columns[0].DataPropertyName = "第一列的字段名"
      

  3.   

    刚跟过差不多的贴,你也可以参考下,应该那样解决
    http://topic.csdn.net/u/20081119/22/f2635dd0-a5c0-40d9-9a31-40b882253ea7.html
      

  4.   

    你给datagridview的datasource赋值后,然后在界面上,选择datagridview右键属性,可以看到一个集合,里面可以绑定每列显示的数据,也可以设置表头显示的文本的
      

  5.   


    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 = "第而列";
            }    }
    }先点击button1,再点击button2.