datagrid crashes program when loading on the fly

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

polarz

here are the lines of code that I've tried. All crash the program

shownVals is a string array
data is my datatable

//problem code #1

loop here{
((Form1)NewsMyWay.Form1.ActiveForm).data.Rows.Add(shownVals);
}

//problem code #2

((Form1)NewsMyWay.Form1.ActiveForm).data.BeginLoadData();

loop here{

((Form1)NewsMyWay.Form1.ActiveForm).data.LoadDataRow(shownVals,false);

}

((Form1)NewsMyWay.Form1.ActiveForm).data.EndLoadData();

//problem code #3



loop here{
((Form1)NewsMyWay.Form1.ActiveForm).data.BeginLoadData();
((Form1)NewsMyWay.Form1.ActiveForm).data.LoadDataRow(shownVals,false);
((Form1)NewsMyWay.Form1.ActiveForm).data.EndLoadData();
}



I'm pulling data from the internet and trying to put it into my
dataGrid on the fly but I always recieve a

System.NullReferenceException

when the grid is populating or a few seconds after it has finished.
I've also tried to throw in

((Form1)NewsMyWay.Form1.ActiveForm).data.AcceptChanges();

in various spots in my code but that does nothing. When I save the
downloaded data to a txt file I can import the data to the grid fine.
Unless there is too much data, that also causes a crash but is another
issue. I'm at a loss :/
Any suggestions are much appreciated. Thank you
 
You use a "working" thread to load the data in the dataset?

Try to use the following piece of code:

Form1 f=(Form1)NewsMyWay.Form1.ActiveForm;
f.Invoke(f.data.Rows.Add,shownVals);
 
Back
Top