获取listview检查项目[循环] [英] Get listview checked item [Loop]

查看:56
本文介绍了获取listview检查项目[循环]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



任何人都知道教程或示例的链接在哪里可以循环列表视图中的所有项目并选中以获取列的值并将其放入在数组上?



主要关注的是如何将循环编码到listview中并验证是否检查了每一行,这样我就可以获得项目列的值了步骤代码..



Tq

Hi all,

Anyone know the link of tutorial or sample where can I loop all item in listview with checked to get the value of the column and put it on array?

The main concern is how to code for loop into listview and verify whether the each row is checked, so I can get the item column's value for my next step code..

Tq

推荐答案

参考: ListView.CheckedItems属性 [ ^ ]


嗨tq ,,



i只是想帮忙..

试试这个:

Hi tq,,

i just want to help..
try this:
listView1.Bounds = new Rectangle(new Point(10, 10), new Size(300, 200));


            listView1.View = View.Details;
            // Allow the user to edit item text.
            listView1.LabelEdit = true;
            // Allow the user to rearrange columns.
            listView1.AllowColumnReorder = true;
            // Display check boxes.
            listView1.CheckBoxes = true;
            // Select the item and subitems when selection is made.
            listView1.FullRowSelect = true;
            // Display grid lines.
            listView1.GridLines = true;
            // Sort the items in the list in ascending order.
            listView1.Sorting = SortOrder.Ascending;

            // Create three items and three sets of subitems for each item.
            ListViewItem item1 = new ListViewItem("item1", 0);
            // Place a check mark next to the item.
            item1.Checked = true;

            ListViewItem item2 = new ListViewItem("item2", 1);

            ListViewItem item3 = new ListViewItem("item3", 0);
            //// Place a check mark next to the item.
            item3.Checked = true;



       //HERES the CLAsS

           Class1 cl = new Class1();
            List<Class1> getcl = new List<Class1>();
            getcl.Clear();
            //Add the items to the ListView.

            listView1.Items.AddRange(new ListViewItem[] { item1, item2, item3 });
            for (int i = 0; i < listView1.Items.Count; i++)
            {
                switch (i)
                {
                    case 0:
                        if (listView1.Items[i].Checked)
                        {
                            MessageBox.Show("Listview items " + listView1.Items[i] + " is checked");
                        }
                        else
                        {
                            MessageBox.Show("Listview items " + listView1.Items[i] + " is unchecked");
                        }

                           cl.getItem1 = this.listView1.Items[i].SubItems[0].ToString();
                           break;

                    case 1:
                           if (listView1.Items[i].Checked)
                           {
                               MessageBox.Show("Listview items " + listView1.Items[i] + " is checked");
                           }
                           else
                           {
                               MessageBox.Show("Listview items " + listView1.Items[i] + " is unchecked");
                           }
                           cl.getItem2 = this.listView1.Items[i].SubItems[0].ToString();
                           break;

                    case 2:
                           if (listView1.Items[i].Checked)
                           {
                               MessageBox.Show("Listview items " + listView1.Items[i] + " is checked");
                           }
                           else
                           {
                               MessageBox.Show("Listview items " + listView1.Items[i] + " is unchecked");
                           }
                           cl.getItem3 = this.listView1.Items[i].SubItems[0].ToString();
                           break;
                }
                getcl.Add(cl);

            }
           //here's the code on how to get the content of a class
            String l = getcl.ElementAt(0).getItem1;


以下是该课程的内容:



Here's the content of the class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication1
{


    class Class1
    {
        private  string item1;
        private  string item2;
        private string item3;
        public String getItem1
        {
            get{ return this.item1;}
            set { this.item1 = value; }
        }

        public String getItem2
        {
            get{return this.item2;}
            set{this.item2=value;}
        }

        public String getItem3
        {
            get { return this.item3;}
            set { this.item3=value;}

        }
    }
}


这篇关于获取listview检查项目[循环]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆