C# Help with a basic pedagogic example of a BackGroundWorker process populating a DataGridView
Posted
by Roger
on Stack Overflow
See other posts from Stack Overflow
or by Roger
Published on 2010-03-08T22:21:01Z
Indexed on
2010/03/08
22:36 UTC
Read the original article
Hit count: 388
c#
Scenario:
I have a windows form that holds a DataGridWiew with 3 pre-defined columns. I have 3 variables declared outside the function and assigned to inside the function. I have a function that enumerates stuff and puts it in the 3 columns, line by line:
string VARIABLE1;
string VARIABLE2;
string VARIABLE3;
private void FunctionEnumerateStuff()
{
foreach (StuffObject STUFF in StuffCollection)
{
VARIABLE1 = STUFF.SubStuff1.ToString();
VARIABLE2 = STUFF.SubStuff2.ToString();
VARIABLE3 = STUFF.SubStuff3.ToString();
DatagridWiew1.Rows.Add(VALUE1, VALUE2, VALUE3);
}
}
What I want to do, is to execute this function from a BackGroundWorker process, so that the GUI of the application will be smooth and responsive. I have read up on backgroundworkers but I am having trouble relating, because all examples seems to be of entirely different scenarios and most of them are overwelmingly complex.
San some helpful pedagogic soul help me and others with a very basic example of how to get this to work in the simplest way possible. Thanks.
© Stack Overflow or respective owner