旋风的专栏

DotNet技术

操作ListView

 //使用例子
  private void button1_Click(object sender, EventArgs e)
        {
          
          
            TmpList.Add(comboBox1.SelectedItem.ToString() + "|" + comboBox2.SelectedItem.ToString());
         
            SetListQC(TmpList);
           
        }
 //填充ListView列表
        ListViewItem[] listViewItemList;
        ArrayList TmpList = new ArrayList();
        public void SetListQC(ArrayList TmpList)
        {
            if (TmpList != null)
            {
                listViewItemList = new ListViewItem[TmpList.Count];

                listView1.Items.Clear();
                for (int i = 0; i < TmpList.Count; i++)
                {
                    listViewItemList[i] = new ListViewItem(TmpList[i].ToString().Split('|'));


                    listView1.Items.Add(listViewItemList[i]);
                }
            }
        }
        //删除选中项
        private void button2_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count != 0)
            {

                listView1.Items.Remove(listView1.SelectedItems[0]);
            }
        }
        //组合选中项字符串,"|"分隔
         public string  SetLvStr()
         {
             string tmp="";
             if (listView1.SelectedItems.Count != 0)
             {
                 tmp = listView1.SelectedItems[0].SubItems[0].Text + "|" + listView1.SelectedItems[0].SubItems[1].Text;
             }
             return tmp;
         } 

阅读更多
个人分类: C#
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

操作ListView

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭