有一数组,存放了列的中文名,我想把datagridview 表头绑定这一数组,请问该如何进行,谢谢。

解决方案 »

  1.   

    查数据库的第一列(count(1))。给datagridview。DataSource就行了。
      

  2.   

    数组循环赋值for(int i=0;i<数组.length;i++)
    {
    this.dgv.columns[i].headtext=数组[i];
    }
      

  3.   

    private void Form1_Load(object sender, EventArgs e)
            {
                string[] arrayStr = new string[10];
                for (int count = 0; count < arrayStr.Length; count++)
                {
                    arrayStr[count] = "第" + count.ToString() + "列";
                    this.dataGridView1.Columns.Add(arrayStr[count],arrayStr[count]);
                }
            }
      

  4.   

    在GridView的RowDataBound事件里定义
     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                //在这里将你的数组赋值给Header,下面是示例
                e.Row.Cells[0].Text = "城市";
                e.Row.Cells[1].Text = "国家";
            }
        }