Accessing a component on the main form from a class.

Posted on 2011-05-03
Last Modified: 2013-12-16

I have a main form called MainForm and a class called ProductDatabase.

In the class i have the following methode:

                 public GetDisplayText(DataRow row)
                switch (row.Table.TableName)
                    case Tables.Product:
                        MainForm.txtFoodName.text  = "" + row[ProductField.Name]; <======

And the methode in the MainForm that calls the methode of the class looks like this:

        private void lstvFoodDB_AfterSelect(object sender, TreeViewEventArgs e)

But the methode that i have marked with the arrow doesn't work, because i can't get
access to the component txtFoodName on the MainForm.

Who knows the answer and is willing to help me...

Question by:peterkiers
    LVL 16

    Accepted Solution

    Just make a public property in MainForm for Textbox and then you will be able to access that with form object
    LVL 1

    Author Comment

    oke thanks

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    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

    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    758 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

    11 Experts available now in Live!

    Get 1:1 Help Now