Performance issues when iterating throug DataGridView.SelectedCells

  • Thread starter Thread starter fomar
  • Start date Start date
F

fomar

Guest
Im 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.


Ive tried the following code:​

Version 1:​


Code Snippet

foreach (DataGridViewCell cell in dataGridView1.SelectedCells)

{


if (cell.ReadOnly == false)

{


cell.Value = fif.textBox1.Text;

}

}








Version 2:



Code Snippet

for (int i = 0; i < dataGridView1.SelectedCells.Count; i++)

{


if (dataGridView1.SelectedCells.ReadOnly == false)


{


dataGridView1.SelectedCells.Value = fif.textBox1.Text;



}


}






Theres no signigicant difference between the two versions.


Thank you very much for your hints.​

Continue reading...
 
Back
Top