Click here to Skip to main content
15,898,538 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Comments
AC_Redz 13-Mar-14 1:50am    
Hope that could help you.. More power

 
Share this answer
 
Comments
Luiey Ichigo 12-Mar-14 22:36pm    
Nice..test it and got it perfectly..thanks man
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;
 
Share this answer
 
Here's the content of the class:

C#
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;}

        }
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900