How to add items in ListView

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Janice Hui
    New Member
    • Feb 2010
    • 16

    How to add items in ListView

    I have 2 Forms which named Form1 and Form2. In Form1, a ListView is created which has three column name CusName, CusIC and CusAddress.

    When user clicks on the Add Button, a Form2 is pop-up to request the user to fill up the information which consists of Name1, IC1 and Address1.

    Code:
    private void SaveButton_Click(object sender, EventArgs e)
    {
        string Name = Name1.Text;
        string IC = IC1.Text;
        string Address = Address1.Text;
        Close();
        Form1 add = new Form1();
        add.addData(Name, IC, Address);
    }
    After user press Save Button in Form2, the values are passing back to Form1 and assign to the ListView. The problem is how to assign value to the ListView, the three values are successfully passed back to Form1 but is unable to assign in ListView.

    Code:
    public void addData(string name2, string ic2, string address2)
    {
        ListViewItem iv = listView1.Items.Add(name2);
        iv.SubItems.Add(ic2);
        iv.SubItems.Add(address2); 
    
        listView1.Items.Add(iv); 
    }
    Thank you!
    Last edited by tlhintoq; Mar 7 '10, 04:37 PM. Reason: [CODE] ...Your code goes between code tags [/CODE]
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3

      Comment

      Working...