I'm trying to fill all selected cells in a datagridview with a string that has been entered into a textbox. The datagridview i am testing with has about 1000 rows and a changing number of columns. Some of the columns can be read only and must not be changed. When i try to change the values of about 900 or more cells it takes a minute or more during which my cpu is at 100%.
What am i doing wrong? How can i improve this replacement?
Everything else works pretty fast; i.e. loading the datagridview from a text file, saving the changed data to another file etc.
I've tried the following code:
Version 1:
foreach (DataGridViewCell cell in dataGridView1.SelectedCells) { if (cell.ReadOnly == false) { cell.Value = fif.textBox1.Text; } }
Version 2:
for (int i = 0; i < dataGridView1.SelectedCells.Count; i++) { if (dataGridView1.SelectedCells[i].ReadOnly == false) { dataGridView1.SelectedCells[i].Value = fif.textBox1.Text; } }
There's no signigicant difference between the two versions.
Thank you very much for your hints.