1

I have to make some modification to an application that have perfomance issues. I ran the profiler and one of the problem is that one:

A sql query is made and stored in a DataReader. The query returns about 2000 rows.

then a while loop start

Dim monSQL as IDataReader 
monSQL = a SQL Query

Do While monSQL.Read
  strArray(0) = 
  strArray(1) = 
  strArray(2) = 
  strArray(3) = monSQL("Something").ToString
  strArray(4) = monSQL("Something").ToString
  strArray(5) = monSQL("Something").ToString

  If Not IsDBNull(monSQL("Something")) Then
    strArray(6) = (monSQL("Something"))
    strArray(7) = monSQL("Something")).ToString
    strArray(8) = monSQL("Something").ToString
    strArray(9) = monSQL("Something").ToString
    strArray(10) = monSQL("Something").ToString
  End If

  objListItem = New ListViewItem(strArray)
  objListItem.Tag = lngNoLot
  ListView.Items.Add(objListItem)
Loop

In the while loop, the data are insert in the listview

It takes quite some time to go throught the loop (about 10 sec)

What are my option to make things go faster?

7
  • If you fill a DataTable you can use that as the Datasource for a DataGridview and save lots of time and code Commented Jun 4, 2015 at 17:10
  • Would i still be able to have a check box at the beginning of each row to select a certain row? Commented Jun 4, 2015 at 17:23
  • How to speed adding items to a ListView? Commented Jun 4, 2015 at 17:27
  • The problem is not in inserting the item. Even if I comment everything in the while loop, i.e not adding anything to the list, it takes the same amount of time. Commented Jun 4, 2015 at 17:30
  • A ListView is sub-optimal for viewing DB data - you are actually making string copies of the data -and lots of subitems - to add to the LV. Commented Jun 4, 2015 at 17:35

1 Answer 1

1

Try suspending any drawing during the loop updates:

listView1.BeginUpdate()
// your loop
listView1.EndUpdate()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.