C# DataGridView显示数组

           private void Form1_Load(object sender, EventArgs e)

        {

            //第一种做法(不如人意,没有达到要求,只显示字符串的长度)

            //string[] intarray =new string[] {"one","two","three"};
            //dataGridView1.DataSource = intarray;//使用字符串数组,结果显示字符串的第一个公共属性Length


            //第二种做法
            Item[] items = new Item[]                                               
            { 
                new Item("one"),
                new Item("two"), 

                new Item("three")

            };

            this.dataGridView1.DataSource = items;
        }


        class Item

        {

            private string txt;

            public string Text
            {
                get { return txt; }
            }


            public Item(string text)
            {
                this.txt = text;
            }

        }

         //另附以下程序
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {

            if (e.RowIndex < 0)    //当表头选中时
            {
                return;
            }

            if (dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString() == "two")           //当选中“two”时,checkBox1被选中
            {
                checkBox1.Checked = true;
            }
            else
            {

                checkBox1.Checked = false;

            }

        }

//第一种做法运行结果如下:

//第二种做法行结果如下:

//当选中“two”时,checkBox1被选中



DataGridView 控件使用方法可参考:

http://blog.csdn.net/weishuchan/article/details/7981726

http://blog.sina.com.cn/s/blog_4935bf700100mtv7.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值