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

Posted on 2008-11-18
Last Modified: 2012-05-05
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..
Question by:vinceTrace
    LVL 26

    Expert Comment

    by:Anurag Thakur
    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

    Author Comment

    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 ?
    LVL 26

    Expert Comment

    by:Anurag Thakur
    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

    Author Comment

    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....
    LVL 26

    Accepted Solution

    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

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    WiX Installer 2 40
    Linq Query Add new object array 10 44
    Contant UI messages in .NET 1 22
    How to catch SQL Errors from ADO.NET 3 82
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now