码迷,mamicode.com
首页 > 其他好文 > 详细

listview点击checkbox,修改值

时间:2014-10-17 15:10:26      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:ar   for   sp   on   ad   bs   line   new   text   

1.初始化控件


            listView1.Items.Clear();
            listView1.Columns.Clear();
            ColumnHeader ch = new ColumnHeader();
            ch.Width = 100;
            ch.Text = "终端";
            listView1.Columns.Add(ch);

            ColumnHeader ch2 = new ColumnHeader();
            ch2.Width = 100;
            ch2.Text = "开关状态";
            listView1.Columns.Add(ch2);

            listView1.View = View.Details;
            listView1.GridLines = true;
            listView1.FullRowSelect = true;

            string[] strs = txtConCode.Text.Split(‘,‘);
            for (int i = 0; i < strs.Length; i++)
            {
                ListViewItem lvi = new ListViewItem();
                lvi.Text = strs[i];
                lvi.SubItems.Add("合闸");
                listView1.Items.Add(lvi);
            }

 

2.点击checkbox值,修改对应的值

 private void listView1_ItemChecked(object sender, ItemCheckedEventArgs e)
        {
            for (int i = 0; i < listView1.Items.Count; i++)
            {
                if (listView1.Items[i].Checked == true)
                {
                    listView1.Items[i].SubItems[1].Text = "分闸";
                }
                else
                {
                    listView1.Items[i].SubItems[1].Text = "合闸";
                }
            }
        }

listview点击checkbox,修改值

标签:ar   for   sp   on   ad   bs   line   new   text   

原文地址:http://www.cnblogs.com/Anders888/p/4030956.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!