Datagrid crashes program, when input data is too large

  • Thread starter Thread starter polarz
  • Start date Start date
P

polarz

I've written a program that pulls data from the internet and puts it
into a datagrid. When the number of rows reaches a certain point my
program freezes.

Is there a limit to the number of rows you can add? If so, is there a
way to get around this?

Any suggestions are much appreciated. Thanks.
 
Hi Miha, thanks for the reply. Yes I am using threading. I've tried to
base my code off of this

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms06112002.asp

This is my first attempt at using threading so I may be doing
something wrong. Everything seems to work perfect until I get a lot of
data. The most rows I've added is several hundred, I'm not sure of an
exact number. I haven't done anything with the a Cancel button, but
some of that code is left in. My threading code is posted below. Any
suggestions are much appreciated. Thanks


Progress p = new Progress();
p.popData(shownVals, numArticles);

public class Progress : System.Windows.Forms.Form
{
public Progress()
{}
enum CalcState
{
Pending,
Calculating,
Canceled,
}

Form1 f=(Form1)UpdateMyWay.Form1.ActiveForm;
CalcState state = CalcState.Pending;

class ShowProgressArgs : EventArgs
{
public string[] progressArr;
public bool Cancel;
public string numArticles;

public ShowProgressArgs(string[] progressArr,
string numArticles)
{
this.numArticles = numArticles;
this.progressArr = progressArr;
}

}

delegate void ShowProgressHandler(object sender, ShowProgressArgs e);

void ShowProgress(object sender, ShowProgressArgs e)
{
// Make sure we're on the right thread
if( this.InvokeRequired == false )
{
// Check for Cancel
e.Cancel = (state == CalcState.Canceled);
Convert.ToBoolean(e.progressArr[0]);
f.textBox1.Text= e.numArticles;
f.textBox1.Update();
f.data.Rows.Add(e.progressArr);
f.myDataGrid.Update();

// Check for completion
if( e.Cancel)
{
state = CalcState.Pending;
}
}
// Transfer control to correct thread
else
{
ShowProgressHandler
showProgress = new ShowProgressHandler(ShowProgress);
Invoke(showProgress, new object[] { sender, e});
}
}

public void popData(string[] sData, string nArticles)
{
object sender = System.Threading.Thread.CurrentThread;
ShowProgressArgs e = new ShowProgressArgs(sData, nArticles);

// Show progress (ignoring Cancel so soon)
ShowProgress(sender, e);
}
}

//Thanks Miha ;)
 
Hi,

There is virtually no limit to the amount of data that can be shown by the datagrid - it's only limited by the amount of memory the client system has. So your issue might be something else...

Regards,
fbhcah
 
Hi,

The code seems ok at the first glance.
Do you touch (in worker thread) sData after you assign it to grid?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

polarz said:
Hi Miha, thanks for the reply. Yes I am using threading. I've tried to
base my code off of this

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms06112002.asp

This is my first attempt at using threading so I may be doing
something wrong. Everything seems to work perfect until I get a lot of
data. The most rows I've added is several hundred, I'm not sure of an
exact number. I haven't done anything with the a Cancel button, but
some of that code is left in. My threading code is posted below. Any
suggestions are much appreciated. Thanks


Progress p = new Progress();
p.popData(shownVals, numArticles);

public class Progress : System.Windows.Forms.Form
{
public Progress()
{}
enum CalcState
{
Pending,
Calculating,
Canceled,
}

Form1 f=(Form1)UpdateMyWay.Form1.ActiveForm;
CalcState state = CalcState.Pending;

class ShowProgressArgs : EventArgs
{
public string[] progressArr;
public bool Cancel;
public string numArticles;

public ShowProgressArgs(string[] progressArr,
string numArticles)
{
this.numArticles = numArticles;
this.progressArr = progressArr;
}

}

delegate void ShowProgressHandler(object sender, ShowProgressArgs e);

void ShowProgress(object sender, ShowProgressArgs e)
{
// Make sure we're on the right thread
if( this.InvokeRequired == false )
{
// Check for Cancel
e.Cancel = (state == CalcState.Canceled);
Convert.ToBoolean(e.progressArr[0]);
f.textBox1.Text= e.numArticles;
f.textBox1.Update();
f.data.Rows.Add(e.progressArr);
f.myDataGrid.Update();

// Check for completion
if( e.Cancel)
{
state = CalcState.Pending;
}
}
// Transfer control to correct thread
else
{
ShowProgressHandler
showProgress = new ShowProgressHandler(ShowProgress);
Invoke(showProgress, new object[] { sender, e});
}
}

public void popData(string[] sData, string nArticles)
{
object sender = System.Threading.Thread.CurrentThread;
ShowProgressArgs e = new ShowProgressArgs(sData, nArticles);

// Show progress (ignoring Cancel so soon)
ShowProgress(sender, e);
}
}

//Thanks Miha ;)


Hi,

Are you using threading by any chance?
 
Back
Top