If I wanted to load an ascii file (which contains 400,000+ lines and each
line is a table row) to a datatable and then display it to a datagrid, what
would the best approach be? I initially had a method that would fill the
table with the ascii file data (the parm was the fileName), it would return
the filled datatable, and then I'd use it as a datasource for the grid. That
was working well with small files but the client just told me that files
would normally contain between 400K-800K rows. So with my layout, the user
would have to wait until the method processes the whole file and attaches
the file to the grid before he/she can see anything. Is there a more
efficient way of doing it? Is there any way I can display some of the
records while the rest is being processed? My only concern there is what
datagrid event to use so I know that the user wants to look at more rows.
The other way I tried is by using delegates and instead of returning a
datatable it'll return a datarow. Unfortunately, it still turns out to be
very slow and its performance doesn't seem correct...
loadFileDelegate LoadAuditFileToTable = new
loadFileDelegate(loadAuditFileToTable);
BeginInvoke (LoadAuditFileToTable, new object[] { sFileName});
loadAuditFileToTable(sFileName);
private void loadAuditFileToTable(string sFileName)
{
DataRow rowAudit;
ZMMatch.Audit zmAudit = new ZMMatch.Audit();
_table_auditAddress = zmAudit.openAZM(sFileName); //Opens ascii file and
prepares datatable
//dataGrid_auditAddress.DataSource = _table_auditAddress;
bool isEndOfFile=false;
while (!isEndOfFile)
{
rowAudit = zmAudit.readAuditAZMFileToView(ref isEndOfFile, ref
iRowsProcessed); //it reads one line and converts to row
if (!isEndOfFile)
{
_table_auditAddress.Rows.Add(rowAudit);
ShowProgress();
}
}
delegate void ShowProgressDelegate();
private void ShowProgress()
{
if(dataGrid_auditAddress.InvokeRequired == false )
{
dataGrid_auditAddress.DataSource = _table_auditAddress;
//dataGrid_auditAddress.Refresh();
//Application.DoEvents();
}
else
{
ShowProgressDelegate showProgress = new
ShowProgressDelegate(ShowProgress);
BeginInvoke(showProgress, new object[] { });
}
}
Any help is appreciated since I'm really stuck with this and it's due Thurs.
morning...