我用数组作为DataGridView数据源的时候,它只显示数组里每项的长度...怎么不能样才能显示实际的字符串...
...这是代码...
string[] para = new string[] { "one", "two", "three" };
            this.dataGridView1.DataSource = para;...显示结果...
.Length
 3
 3
 5要怎样才能显示出
one
two
three

解决方案 »

  1.   

    因為datasource綁的是對象屬性,所以建一個包含字符串的類,然後用對象數組是可以達到目的
    public   class   TestView 

        private   String   m_Test; 
        public   String   Test 
        { 
                get   {   return   m_Test;   } 
                set   {   m_Test   =   value;   } 
        } 
    }
      

  2.   

     string[] test = new string[] { "one", "tow", "three" };
            this.GridView1.DataSource = test;
            this.GridView1.DataBind();没有问题啊。显示的就是one,tow,three
      

  3.   

    不好意思。我刚没看清楚。
    我换成datatable,不知道你能不能接受
     string[] test = new string[] { "one", "tow", "three" };
                DataTable dt = new DataTable();
                DataColumn col = new DataColumn("test");
                dt.Columns.Add(col);
                foreach (string tt in test)
                {
                    dt.Rows.Add(tt);
                }
                this.dataGridView1.DataSource = dt;