Note that there are some explanatory texts on larger screens.

plurals
  1. POThe DataGridView is loading very slowly. How to optimise adding of rows in DataGridView?
    text
    copied!<p><strong>The datagridview is loading very slowly. How can I optimise it?</strong> </p> <p>The datagridview has 4-5 thousand rows.<br> I have to generate a datagridview dynamically on a few parameters.(Data from database, No. of columns) </p> <p>I have to generate the datagridview like this vertically from the table (id,name,contact) in database..</p> <p><strong>Column1</strong></p> <p><strong>id</strong><br> <strong>name</strong><br> <strong>contact</strong> </p> <p>Now there can be any number of more empty columns beside <strong>column1.</strong></p> <p>Currently I am following this approach. </p> <ol> <li>First adding all the empty columns. </li> <li>Then adding three rows in each for loop iteration one row for each (id,name,contact).</li> <li><p>I am fetching the data from the database and passing it as a <code>List &lt;string[]&gt;</code> to the <code>GenerateRows</code> function.</p> <pre><code> private void GenerateColumns(int colLen) { dataGridViewGenerate.Rows.Clear(); dataGridViewGenerate.Columns.Clear(); DataGridViewColumn col0 = new DataGridViewTextBoxColumn(); col0.HeaderText = "Employee No. &amp; Name"; dataGridViewGenerate.Columns.Add(col0); for (int i = 0; i &lt; colLen; i++) { DataGridViewColumn col = new DataGridViewTextBoxColumn { HeaderText = (_sTime.AddDays(i)).Day.ToString(CultureInfo.InvariantCulture) + " " + (_sTime.AddDays(i)).ToString("ddd") }; dataGridViewGenerate.Columns.Add(col); } private void GenerateRows(List&lt;string[]&gt; empList) { int len = empList.Count; for (int a = 0; a &lt; len; a++) { string[] arr = empList[a]; //row 1 var row1 = new DataGridViewRow(); row1.Cells.Add(new DataGridViewTextBoxCell { Value = arr[0] }); dataGridViewGenerate.Rows.Add(row1); //row 2 var row2 = new DataGridViewRow(); row2.Cells.Add(new DataGridViewTextBoxCell { Value = arr[1] }); dataGridViewGenerate.Rows.Add(row2); //row3 var row3 = new DataGridViewRow(); row3.Cells.Add(new DataGridViewTextBoxCell { Value = arr[2] }); dataGridViewGenerate.Rows.Add(row3); } } </code></pre></li> </ol> <p><em>I was thinking to make a procedure in sql which will create a table and fill it with the data. Then just assign the datasource to the datagridview.</em> </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload