473,386 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Loading Large Lists

I am writing code for a list box editor, one of the lists is large was
hoping that there is a way to either speed it up by making the server do
the IF statements of there is a faster way of checking the lists? Any
help would be useful. Have posted the code I am using below

Tom
parentControl = New Windows.Forms.ListBox
parentControl = control
table = sourceTable
column = field

' populate right list box
For i = 0 To control.Items.Count - 1 Step 1
lstDestination.Items.Add(control.Items.Item(i))
Next

' populate left list box
tempString = "SELECT " & field & " FROM " & sourceTable
myDataSet = Q.Query(tempString)
For i = 0 To myDataSet.Tables("myData").Rows.Count - 1 Step 1
' add to box only if it does not have that item already
If
lstDestination.Items.Contains(myDataSet.Tables("my Data").Rows(i).Item(fi
eld)) = False Then

lstSource.Items.Add(myDataSet.Tables("myData").Row s(i).Item(field))
End If
Next
*** Sent via Developersdex http://www.developersdex.com ***
Nov 29 '05 #1
3 1366

"Thomas Beyerlein" <tb***@yahoo.com> wrote in message news:OU**************@TK2MSFTNGP09.phx.gbl...
I am writing code for a list box editor, one of the lists is large was
hoping that there is a way to either speed it up by making the server do
the IF statements of there is a faster way of checking the lists? Any
help would be useful. Have posted the code I am using below

Tom
parentControl = New Windows.Forms.ListBox
parentControl = control
table = sourceTable
column = field

' populate right list box
For i = 0 To control.Items.Count - 1 Step 1
lstDestination.Items.Add(control.Items.Item(i))
Next

' populate left list box
tempString = "SELECT " & field & " FROM " & sourceTable
myDataSet = Q.Query(tempString)
For i = 0 To myDataSet.Tables("myData").Rows.Count - 1 Step 1
' add to box only if it does not have that item already
If
lstDestination.Items.Contains(myDataSet.Tables("my Data").Rows(i).Item(fi
eld)) = False Then

lstSource.Items.Add(myDataSet.Tables("myData").Row s(i).Item(field))
End If
Next


You should first reduce the amount of dereferencing going on. The With
statement exists for several reasons. It not only simplifies your coding
(making it easier to read and write) it also dereferences objects. That's
a huge overhead when dealing with the exact same object repeatedly,
as you are.

Note that only one object can be dereferenced with the With statement.
If you need multiple dereferences (as you do), use local variables as well.
The With statement actually provides an implicit local variable and they
can be nested if necessary (as I've done below).

You should also use BeginUpdate and EndUpdate on the lists during
an update. There's no point drawing the list each time an item is added.
Just add the items in a oner, then refresh the list.

All in all, the following amendments should significantly improve
performance.

' These first few statements don't do anything useful. Declare them
' immediately before you use them--don't place all your declarations
' at the top of a sub or function unless they're guaranteed to be used
' before an Exit Sub or Exit Function is encountered.
parentControl = New Windows.Forms.ListBox
parentControl = control
table = sourceTable
column = field

' Dereference the destination listbox items collections (explicit variable).
Dim dstItems as ListBox.ObjectCollection = lstDestination.Items

' Dereference the destination list (implicit variable)
With lstDestination

' stop drawing control
.BeginUpdate()

' Dereference control items (implicit variable).
With control.Items

' Update the destination list
For i = 0 To .Count - 1 Step 1
dstItems.Add(.Item(i))
Next

End With

' refresh control
.EndUpdate()

End With

tempString = "SELECT " & field & " FROM " & sourceTable
myDataSet = Q.Query(tempString)

' Dereference the source listbox items collections (explicit variable).
Dim srcItems as ListBox.ObjectCollection = lstSource.Items

' Dereference the source list (implicit variable).
With lstSource

' Stop drawing the list
.BeginUpdate()

' Dereference the data table (implicit variable)
With myDataSet.Tables("myData")

' Add items not in destination list to source list.
For i = 0 To .Rows.Count - 1 Step 1
If dstItems.Contains(.Rows(i).Item(field)) = False Then
srcItems.Add(.Rows(i).Item(field))
End If
Next

End With

' Refresh the list
.EndUpdate()

End With
Nov 29 '05 #2
if you really want to speed it up, make an array of items then do an
addrange with the control showing them instead of adding them one at a time,
this will drastically speed up the process
"Micky" <mi***@n05pam.com> wrote in message
news:dm**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...

"Thomas Beyerlein" <tb***@yahoo.com> wrote in message
news:OU**************@TK2MSFTNGP09.phx.gbl...
I am writing code for a list box editor, one of the lists is large was
hoping that there is a way to either speed it up by making the server do
the IF statements of there is a faster way of checking the lists? Any
help would be useful. Have posted the code I am using below

Tom
parentControl = New Windows.Forms.ListBox
parentControl = control
table = sourceTable
column = field

' populate right list box
For i = 0 To control.Items.Count - 1 Step 1
lstDestination.Items.Add(control.Items.Item(i))
Next

' populate left list box
tempString = "SELECT " & field & " FROM " & sourceTable
myDataSet = Q.Query(tempString)
For i = 0 To myDataSet.Tables("myData").Rows.Count - 1 Step 1
' add to box only if it does not have that item already
If
lstDestination.Items.Contains(myDataSet.Tables("my Data").Rows(i).Item(fi
eld)) = False Then

lstSource.Items.Add(myDataSet.Tables("myData").Row s(i).Item(field))
End If
Next


You should first reduce the amount of dereferencing going on. The With
statement exists for several reasons. It not only simplifies your coding
(making it easier to read and write) it also dereferences objects. That's
a huge overhead when dealing with the exact same object repeatedly,
as you are.

Note that only one object can be dereferenced with the With statement.
If you need multiple dereferences (as you do), use local variables as
well.
The With statement actually provides an implicit local variable and they
can be nested if necessary (as I've done below).

You should also use BeginUpdate and EndUpdate on the lists during
an update. There's no point drawing the list each time an item is added.
Just add the items in a oner, then refresh the list.

All in all, the following amendments should significantly improve
performance.

' These first few statements don't do anything useful. Declare them
' immediately before you use them--don't place all your declarations
' at the top of a sub or function unless they're guaranteed to be used
' before an Exit Sub or Exit Function is encountered.
parentControl = New Windows.Forms.ListBox
parentControl = control
table = sourceTable
column = field

' Dereference the destination listbox items collections (explicit
variable).
Dim dstItems as ListBox.ObjectCollection = lstDestination.Items

' Dereference the destination list (implicit variable)
With lstDestination

' stop drawing control
.BeginUpdate()

' Dereference control items (implicit variable).
With control.Items

' Update the destination list
For i = 0 To .Count - 1 Step 1
dstItems.Add(.Item(i))
Next

End With

' refresh control
.EndUpdate()

End With

tempString = "SELECT " & field & " FROM " & sourceTable
myDataSet = Q.Query(tempString)

' Dereference the source listbox items collections (explicit variable).
Dim srcItems as ListBox.ObjectCollection = lstSource.Items

' Dereference the source list (implicit variable).
With lstSource

' Stop drawing the list
.BeginUpdate()

' Dereference the data table (implicit variable)
With myDataSet.Tables("myData")

' Add items not in destination list to source list.
For i = 0 To .Rows.Count - 1 Step 1
If dstItems.Contains(.Rows(i).Item(field)) = False Then
srcItems.Add(.Rows(i).Item(field))
End If
Next

End With

' Refresh the list
.EndUpdate()

End With

Nov 30 '05 #3

Thanks
*** Sent via Developersdex http://www.developersdex.com ***
Nov 30 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Beau E. Cox | last post by:
Hi - I have an application which is essentially 'read-only' - once the database is loaded it is only read from. So, I am trying to implement it with various indices and a table containg some...
4
by: blackhawk | last post by:
I need to build a web page that has to potentially display a large amount of data in two grids on the same page. The HTML file with all of the formatting is about 7MB in size. This is too large...
3
by: Vivek Khera | last post by:
I have some historic data that I want to analyze. To do this I set up postgres on a spare box I picked up for cheap, which just lucked into having tons of RAM (1.5G). I set up postgres to use...
1
by: Jerry LeVan | last post by:
I am getting ready to try to add image viewing into my postgresql browser... I am probably going to start with storing a thumbnail and a URL for the actual image in the table. Is there any...
6
by: Ivan Bútora | last post by:
I have recently looked at http://alistapart.com/articles/imagegallery to implement a simple picture gallery on a webpage that I'm working on. Everything works fine; however, I have one question....
19
by: Chaz Ginger | last post by:
I have a system that has a few lists that are very large (thousands or tens of thousands of entries) and some that are rather small. Many times I have to produce the difference between a large list...
0
by: AndySummers | last post by:
Hi We have just re-written a majour asp.net project to use a user control embedded in a web page. The main dll references 3 other custom controls and so to deploy the project I copy the 4 dll's to...
1
by: rekkufa | last post by:
I am currently building a system for serializing python objects to a readable file-format, as well as creating python objects by parsing the same format. It is more or less complete except for a...
2
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
I was wonder if there is any protocol or suggestions on how to setup unit testing projects in large solution??? If you have a large solution of say 50 projects and add a project for every unit...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.