Link to home
Start Free TrialLog in
Avatar of Todd710
Todd710

asked on

What is the best practice for updating a WinForm from another class?

I have a MainForm with a Listbox on it.  I have another separate class that is doing a process that I want the Listbox to report on.  What would be the best way to do this?  An example would be great.  Sorry to be vague but I am working on the concept and I do not have much more than that.  Feel free to ask me any questions you may think of.  Thanks for any help!
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This example is a little crude, but i think it performs what your asking.

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Create a dataset to receive your data in
            DataSet dsMaster;

            //Call the data function from the class your
            //working with and place it in your master dataset
            dsMaster =  getDataForList.getMyData();

            //update your list box
            listBox1.DataSource = dsMaster.Tables[0];
        }
    }

    public static class getDataForList
    {
        public static DataSet getMyData()
        {
            DataSet ds = new DataSet();
            //Do your SQL lookup ETC and place it into the DataSet called DS
            return ds;
        }
    }
}
Avatar of Todd710
Todd710

ASKER

The custom event model is the right answer for what I need but an example would have been nice.