在一个WINFORM程序中,无需数据库操作,就在一个窗体上放一个dataGridView,在后台代码处写一个数组,且给这个数组赋初值,接着运行程序,结果就是要在前台的dataGridView中的第一列把刚才那个数组的值显示出来!请高手了

解决方案 »

  1.   

    直接绑定不行的,我用循环的方法做的,lz参考下,应该有更好的办法的!
    -----------------------------------------------------------------
                BindingSource bs = new BindingSource();
                int[] arr = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 };
                bs.DataSource = arr;
                dataGridView1.Columns.Add("aaa", "bbb");
                dataGridView1.Rows.Add(arr.Length);
                for (int i = 0; i < arr.Length; i++)
                {
                    dataGridView1.Rows[i].Cells[0].Value = arr[i];
                }
      

  2.   

    去掉下面两句代码:
    BindingSource bs = new BindingSource();
    bs.DataSource = arr;
      

  3.   

    ... 怎么不能直接绑呢... 只要支持IList接口就可以了吧 for (int i = 0; i < arr.Length; i++)
                {
                    dataGridView1.Rows[i].Cells[0].Value = arr[i];
                }
    ...这个干吗阿?