Click here to Skip to main content
14,920,935 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi All,
I have a List View control with two columns in windows Form and two text box and a button control if I click the button every time it should add the value of text boxes in the new row of List view.
so how to make that in loop please help

Thanks & Regards
Indrajit Dasgupta
Posted
Comments
lukeer 26-Jul-13 4:14am
   
No need for a loop in here. User decides how many rows are added, one by one. So you don't have to care. Just respond to every single "User wants to add row" event.

Hi,
In form load you can add a Column to a ListView
C#
private void Form1_Load(object sender, EventArgs e)
    {
        listView1.View = View.Details;

        listView1.Columns.Add("Col1");
        listView1.Columns.Add("Col2");
    }


And in Button Click you can add items to the listview

C#
private void button1_Click(object sender, EventArgs e)
  {
      ListViewItem lvi1 = new ListViewItem();

      lvi1.Text = textBox1.Text.Trim();
      lvi1.SubItems.Add(textBox2.Text.Trim());
      listView1.Items.Add(lvi1);
  }
   
i give you a demo :

C#
ListViewItem item = new ListViewItem();
  item.Text =studentNo;
  item.SubItems.Add(textbox1.Text);
  item.SubItems.Add(textbox2.Text);
  lvResult.Items.Add(item);
   

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