Question

I have a List View element listViewMedia in one class and want to update it with data from another file (Strings, basically) so, i have created a public method

 public void addToListViewMedia()
 {  
     listViewMedia.Items.Add(new ListViewItem("datafromotherfile"));
 }

in the first class to add data, but I cannot access it from the other class. What am I doing wrong? I already tried accessing the element directly by setting it to public itself, but that didn't work out either, not to mention the crappy style that would bring to my code. Updating it from the same class is working, btw...

Was it helpful?

Solution

Problem : you can not access members of other class, even if they are declared as public.

Solution : you should access other class memebers with the help of instance variable.

Note: if you can provide more details/code we could help you in much better way.

Try This: Sample

Class A
{

   public void addToListViewMedia()
    {    
        listViewMedia.Items.Add(new ListViewItem("datafromotherfile"));
    }

}

Class B
{

     private void ausführenButton_Click(object sender, EventArgs e)
     { 
        A obj=new A();  //create instance variable.
        obj.addToListViewMedia();//access methods of A using instance variable
     } 

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top