Jedhi Posted December 12, 2005 Posted December 12, 2005 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 } } Quote
Leaders snarfblam Posted December 12, 2005 Leaders Posted December 12, 2005 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() } } Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.