Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a ListView on Form1 that I update on different times. My problem is that when I am in function Test() I need to call the function UpdateListView. The only way I can this is to make UpdateListView static, but then I get the error "An object reference is required for the nonstatic field method". How do I solve this problem

 

 

Class Form1

{

X x = new X();

 

TestListView()

{

x.Test()

}

 

UpdateListView()

{

listView1.Items.Add

}

}

 

 

Class X()

{

Test()

{

How do I call UpdateListView

}

}

  • Leaders
Posted

You can't make UpdateListView static because it references an instance member, listView1. Static methods can not access instance members. (How would the compiler know which instance you are referring to?) You need to pass Form1 to Test() so that Test can refer to an instance of Form1.

 

Class Form1
{
X x = new X();

TestListView()
{
x.Test(this)
}

UpdateListView()
{
listView1.Items.Add
}
}


Class X()
{
Test(Form1 form)
{
//How do I call UpdateListView

//Like this:
form.UpdateListView()
}
}

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...