Click here to Skip to main content
15,848,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Peeps,

Good Day!

I have a total of 3 listviews.

ListView1 has 1 column.
ListView2 has 1 column.
ListVIew3 has 2 columns ( ListView1Column and ListView2Column combination).

How can I copy/clone the inputted data from ListView1 and/or ListView2 in ListView3?

This is what I have in the ListView1 code

private void Button_Add_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(TextBox1.Text))
return;

ListViewItem item = new ListViewItem(TextBox1.Text);
ListView1.Items.Add(item);
TextBox1.Clear();
TextBox1.Focus();
}


Hoping for your assistance. Thanks.

What I have tried:

private void Button_Add_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(TextBox1.Text))
return;

ListViewItem item = new ListViewItem(TextBox1.Text);
ListView1.Items.Add(item);
TextBox1.Clear();
TextBox1.Focus();
}
Posted
Updated 21-Dec-21 0:35am
Comments
Richard MacCutchan 21-Dec-21 6:09am    
Read the each row from each of ListView1 and ListView2, combine them however you want, and insert them into ListView3. What exactly is difficult about that?
Mars JPN 23-Dec-21 5:03am    
My question is how? sorry, I am a student and do not know how to do the clone/copy. Thanks.
Richard MacCutchan 23-Dec-21 5:16am    
The ListView contains a number of Items (the Items collection) so you just need to get the count of the items and run a loop to find each one. Use the documentation at ListView.ListViewItemCollection Class (System.Windows.Forms) | Microsoft Docs[^] for more details.

1 solution

0) Instead of having a ListView that has one column, wouldn't it make a lot more sense to use a ComboBox?

1) If you use binding, you don't have to manipulate the control itself when items are added.
 
Share this answer
 
Comments
Mars JPN 23-Dec-21 5:05am    
It's an activity in our school to use ListView. I am a Student.
#realJSOP 23-Dec-21 8:16am    
Just because it's for school doesn't mean you shouldn't use industry best practices. Using a Listview for a single column of data is... well... stupid.

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