Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Good Day ,
I have 2 windows forms (form_source and form_target) with listviews (lstviewSource and lstviewTarget) respectively. When the items from the "listviewSource" is selected it needs to be displayed on "lstviewTarget".I am cloning the items from the listview in "form_source" but it is not displaying on the listview on "form_target".

below is the code.... thanks in advance. :confused:

*****************************************************

method on form_target
MIDL
public void CopySelectedItems(ListView _lstviewSource)
       {
           foreach (ListViewItem item in _lstviewSource.Items)
           {
               if (item.Checked)
               {
                 lstviewTarget.Items.Add((ListViewItem)item.Clone());
               }
           }
       }




******************************************************


method on form_source

C#
private void btnAddImages_Click(object sender, EventArgs e)
        {
            form_target myform = new form_target();
            myform.CopySelectedItems(lstviewSource);
            this.Close();
        }


******************************************************
Posted
Updated 8-Sep-10 5:06am
v2

1 solution

I would be willing to bet that you're passing the wrong listview object to the 2nd form. It's curious that they're named the same thing in both forms.

A second thought is that your clone method is not functioning correctly.

Using the debugger would answer your question.
 
Share this answer
 
Comments
Rico_ 8-Sep-10 11:03am    
i have double checked the code , i have no errors . i have de-bugged about 10 times ... still no grace.
Rico_ 8-Sep-10 11:08am    
sorry...i noticed that "myform.CopySelectedItems(lstviewTarget);" is typed wrong. it is "myform.CopySelectedItems(lstviewSource);" in my actual code.
Dalek Dave 8-Sep-10 11:09am    
Well Spotted John.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900