日期:2014-05-18  浏览次数:21167 次

winform DataGridView绑定二维数组,怎么做?
我是这样写的
C# code

                BindingSource moniterBindSource = new BindingSource();                
                moniterBindSource.DataSource = robj.readlog();
                dataGridView1.DataSource = moniterBindSource;

但是什么都没显示出来,该怎么弄?
robj.readlog()返回的是一个二维数组,在窗口设计的时候要不要进行设置?
求指点!

------解决方案--------------------
好像绑定不了吧,
自己写个循环加载吧
------解决方案--------------------
C# code

 string[,] array = new string[4, 2];
            array[0, 0] = "001";
            array[0, 1] = "张三";

            array[1, 0] = "002";
            array[1, 1] = "老李";

            array[2, 0] = "003";
            array[2, 1] = "小王";

            array[3, 0] = "004";
            array[3, 1] = "衰哥";

            dataGridView1.Rows.Clear();
            for (int m = 0; m < 4; m++)
            {
                dataGridView1.Rows.Add(1);
                for (int n = 0; n < 2; n++)
                {
                    dataGridView1.Rows[m].Cells[n].Value = array[m, n].ToString();
                }
            }