I have a trouble with reading from DataGridView and then export data to RichTextBox. I made a Program that read from 4 dataGridView and export data from each cells to the string in Textbox. For small files they work great, but when i have bigger files, my program freezes and doesn’t show me the result. Is there any way to solve it?
my code i use to read cells in excel:
for (int i = 0; i < dataGridView4.Rows.Count - 1; i++)
{
if (dataGridView4.Rows[i].Cells["ABC"].Value.ToString() != "")
{
richTextBox1.Text += "ABC_ " + dataGridView4.Rows[i].Cells["ABC"].Value.ToString()
+ " " + dataGridView4.Rows[i].Cells["DEF"].Value.ToString().Replace("\n", "") + ";";
}
}
Of course it repeat this loop many times, coz i have many columns in datagridview
Instead of
use:
It will work much faster.
In addition to this, you can use StringBuilder instead in which you can append text and then at the end, you can set that text to richTextBox1.