Iterate listview on another form

Beginner23

New member
Joined
Oct 27, 2018
Messages
3
Programming Experience
Beginner
Hello all,

I need you help! I have a listview on form1. How can I itterate this listview from form2?

Please help!

/B
 
You're not really asking the right question. Accessing the items of a ListView is the same no matter where it is. If you know how to do it on the form it's part of then you know how to do it on any form. The issue is accessing a control on a different form in the first place and, importantly, whether you should be doing that at all. If you can and do access the ListView then anything you do with it is exactly the same no matter where it is.

I would suggest that you should not be accessing a control on a different form at all. When you add a control to a form, the designer automatically generates a field to access that control and that field is declared 'private', i.e. not accessible outside the form. That's for good reason. What you should almost certainly be doing is writing a method in Form1 that accesses the its own ListView and then invoking that method from Form2. Exactly how you invoke the method depends on the specific relationship between the forms. Please provide a FULL and CLEAR explanation of the problem and we can describe the best solution.

In the interests of completeness, to do as you ask and access the ListView directly, Form2 would need a reference to it. I'm guessing that Form1 creates Form2 so that means that Form1 needs to pass a reference to the ListView into Form2 or else pass a reference to itself into Form2 and you must declare the ListView 'public'. I strongly recommend not doing that though.
 

Latest posts

Back
Top Bottom