Skip to content

Store value from ListView items(column2) to List<string>

QKWS

Asked May 23, 2013, 7:05 PM EDT1 answer
Share
LinkedInX

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:

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

}

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Sunny  Sharma
    0
    Hi QKWS,
    Please share your project or elaborate on the problem.

    Thanks
    0