1
Reply

Store value from ListView items(column2) to List

QKWS

QKWS

May 23 2013 11:05 PM
1k

I have a WinForm, with ListView(2 columns), TextBox, and 3 Buttons(Add, OK, Cancel) In my code a have a List, where I can store my ListView Items. When I click Add Button, the value from TextBox will be added on the ListView and when I click OK button, items from the ListView will be added on the List. But all I need to add is the items from the second column.

When I click the OK Button, items from first columns are being added from the List..

Can somebody help me on how to add items from second column only to my list ?? Thanks.

My first time to post here..Please be kind. :))

Here's my code:

public partial class LotTrace_01 : Form
{
    public List<string> lotList = new List<string>();

    public int i = 0;

    public LotTrace_01()
    {
        InitializeComponent();   
    }

    private void btnAdd_Click(object sender, EventArgs e)
    {   
        i += 1;
        listView1.Items.Add(i.ToString()).SubItems.Add(txt_Add.Text);

    }

    private void btnOk_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < listView1.Items.Count; i++)
        {
            if (lotList.Contains(listView1.Items[i].Text) == false)
            {
                lotList.Add(listView1.Items[i].Text);
            }
        }
        this.Close();
    }

}


Answers (1)