首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#新建cs中为什么datagridview没数据的

2013-02-19 
C#新建cs中为啥datagridview没数据的? public class lineIP{public string[] line1_name { a, B, C

C#新建cs中为啥datagridview没数据的?

 public class lineIP
        {
            public string[] line1_name = { "a", "B", "C", "D", "X" };
            public string[] line1_ip = new string[5];


            public string[] line2_name = { "1", "2", "3", "4" };
            public string[] line2_ip = new string[4];


            public string[] ceshi_name = { "百度", "新浪", "本机", "腾讯" };
            public string[] ceshi_ip = { "202.108.22.5", "202.108.33.74", "192.168.0.1", "182.254.0.217" };


            public lineIP()
            {
                for (int a = 0; a < 5; a++)
                {
                    line1_ip[a] = "10.121.111." + a;
                }

                for (int b = 0; b < 4; b++)
                {
                    line2_ip[b] = "10.132.222." + b;
                }
            }


        }


 public void chezhan_name_select()
        {
            if (chezhan_ip == null)
            chezhan_ip = new System.Windows.Forms.DataGridView();
            lineIP lineip = new lineIP();

            MessageBox.Show(lineip.line1_name.Count().ToString() + "11111");
            //这句话能显示

            switch (x)
            {
                case 1:
                    for (int i = 0; i < lineip.line1_name.Count(); i++)
                    {


                        chezhan_ip.Rows.Add();
                        chezhan_ip.Rows[i].Cells[0].Value = lineip.line1_name[i];
                        chezhan_ip.Rows[i].Cells[1].Value = lineip.line1_ip[i];
                        
                    }
                    MessageBox.Show(lineip.line1_name.Count().ToString()+"ffffffff"); ///这句话就不能显示~~~
                    break;

                case 2:
                    for (int i = 0; i < lineip.line2_name.Count(); i++)
                    {
                        chezhan_ip.Rows.Add();
                        chezhan_ip.Rows[i].Cells[0].Value = lineip.line2_name[i];
                        chezhan_ip.Rows[i].Cells[1].Value = lineip.line2_ip[i];
                    }
                    break;

                case 3:
                    for (int i = 0; i < lineip.ceshi_name.Count(); i++)
                    {
                        chezhan_ip.Rows.Add();
                        chezhan_ip.Rows[i].Cells[0].Value = lineip.ceshi_name[i];
                        chezhan_ip.Rows[i].Cells[1].Value = lineip.ceshi_ip[i];
                    }
                    break;
            }

        }



求指导,,,在新建的cs中调用form1的datagridview1,然后给datagridview进行赋值操作。。。但是datagridview木有数据显示。。。。。


[解决办法]
chezhan_ip = new System.Windows.Forms.DataGridView();是你新建的,而不是窗口上的那个。当然没有显示。
[解决办法]
这个问题和你那个定时器的问题一模一样。你先把语法学会,再来写程序。
[解决办法]
为什么不做个参数,把窗体上的Datagridview传过去赋值?
[解决办法]
把数组转为数据表后绑定控件显示如

热点排行