关闭

操作ListView

标签: listviewbuttonobjectstringnull
486人阅读 评论(0) 收藏 举报
分类:

 //使用例子
  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;
         } 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:138676次
    • 积分:1802
    • 等级:
    • 排名:千里之外
    • 原创:22篇
    • 转载:65篇
    • 译文:1篇
    • 评论:37条
    文章分类
    源码网站