I'm loading rows from a file into a DataGridView
. The file has 25000 rows.
The loading takes enough time that I added a progress bar to the GUI (updating every 128 rows).
Is there a method or process to reserve rows before I start using the Add
method?
I'd like to speed up the adding of data rows.
Environment:
C# -- Visual Studio 2017
Windows 10
P.S. All my searches are about adding a single row to the DataGridView
. I didn't find anything about pre-allocating or reserving space.
For those needing a sample code
String[] items = file.Split(',');
List<string> list = new List<string>();
DataGridView data_table;
foreach (String item in items)
list.Add(item.Trim());
for (int i = 0; i < list.count; ++i)
{
string time_interval_as_string = list[i];
uint time_interval = 0;
uint.TryParse(time_interval_as_string, out time_interval);
string energy_value_as_string = list[++i];
double energy_value = 0.0;
double.TryParse(energy_value_as_string, out energy_value);
dataTable.Rows.Add(time_interval, energy_value);
}