3

i need some help. I'm working on application in C# which has 2 ListViews, 2 Buttons and 4 TextBoxes. First button is adding text from textbox1 and textbox2 to listview1 as item and its subitem. It's also adding that in listview2. Button 2 should add more subitems (from textbox3 and textbox4) in listview2, but i don't know how to do that. This is my code for button1:

private void button1_Click(object sender, EventArgs e)
{
    string s1, s2;
    s1 = textBox1.Text;
    s2 = textBox2.Text;
    if(textBox1.Text!="" && textBox2.Text!="")
    {
        string[] items = { s1, s2 };
        ListViewItem row = new ListViewItem(items);
        listView1.Items.Add(row);
        string[] items2 = { s1, s2 };
        ListViewItem row2 = new ListViewItem(items2);
        listView2.Items.Add(row2);
        textBox1.Text = textBox2.Text = "";
    }
    else
    {
        MessageBox.Show("Enter all data!", "Error");
    }
}

private void button2_Click(object sender, EventArgs e)
{
   //I need code here.
}

The question is: How to add more subitems in listview2 with button2 after subitems that are already added with button1? (I have created all needed columns.)

Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
Nikola
  • 55
  • 1
  • 6

1 Answers1

2

You're almost there. All what you have to do is select your item from the listview and add a subitem to it.

listView1.Items[i].SubItems.Add(YourTextHere);

Here are some posts that may help you Link1 Link2

Community
  • 1
  • 1