• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1125
  • Last Modified:

Get access to a Windows.Form.ListBox in a static method

Hi everybody,

For some reasons I need to update a ListBox from a static function.
As this listbox is a non-static field I get a compilation error.
Could you help me fixing it ?

Thanks very much..
0
vinceTrace
Asked:
vinceTrace
  • 3
  • 2
1 Solution
 
Anurag ThakurCommented:
dont access and update the list box from the satatic function
instead return the value to be updated from the static function and then update it in a non-static function
else you will have to make the list box static as well
0
 
vinceTraceAuthor Commented:
Thanks.
The trouble is, I only have access to static method of the class that has the listBox..
Is there any way to use a static listBox ?
0
 
Anurag ThakurCommented:
i dont understand what do you mean by the following line
-->  I only have access to static method of the class that has the listBox
can you please put more light on the issue so that we can help you better
0
 
vinceTraceAuthor Commented:
Let's say ClassA is the class where the listBox is declared.
I want to update this listBox from ClassB, and ClassB (for some reasons) cannot access to classA current instance. So it can only access ClassA static method (if I am not wrong...)
Hope it is a bit more clear....
0
 
Anurag ThakurCommented:
no you cannot do this with a static listbox because what will happen to the methods in classA which are also accessing the list box - you are not going to make them static just because the list box is not accessible through ClassB

you might want to imporve your design or something because making the listbox accessible from a static method is not a solution which i wil purpose
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now