Duplicating Objects

G

Guest

I'm still having trouble grasping what's going on here and how to resolve it.

In VB6 I have a form that has several combo boxes with lots of items in
each; it takes a long time to load the form because of having to load each
combobox. As I think about converting this to .Net, I believe I should be
able to do something like this:

'position & load the primary object
ComboBox1.Top = 40
ComboBox1.Left = 8
Dim intLoop As Integer
For intLoop = 1 To 5000
ComboBox1.Items.Add(intLoop)
Next

'define & place the copy
Dim cbo2 As New ComboBox
cbo2 = ComboBox1
cbo2.Top = 80
cbo2.Left = 8
cbo2.Text = "ComboBox2"
Me.Controls.Add(cbo2)

But the statement

cbo2 = ComboBox1

doesn't do what I expect. When I view the form, I only see one combobox.
It's like by setting them equal, they become one.

What is the proper way to accomplish this task?
 
K

Ken Tucker [MVP]

Hi,

You are not creating a new combobox1. You are making cbo2 reference
combobox1.

Ken
------------------------
I'm still having trouble grasping what's going on here and how to resolve
it.

In VB6 I have a form that has several combo boxes with lots of items in
each; it takes a long time to load the form because of having to load each
combobox. As I think about converting this to .Net, I believe I should be
able to do something like this:

'position & load the primary object
ComboBox1.Top = 40
ComboBox1.Left = 8
Dim intLoop As Integer
For intLoop = 1 To 5000
ComboBox1.Items.Add(intLoop)
Next

'define & place the copy
Dim cbo2 As New ComboBox
cbo2 = ComboBox1
cbo2.Top = 80
cbo2.Left = 8
cbo2.Text = "ComboBox2"
Me.Controls.Add(cbo2)

But the statement

cbo2 = ComboBox1

doesn't do what I expect. When I view the form, I only see one combobox.
It's like by setting them equal, they become one.

What is the proper way to accomplish this task?
 
G

Guest

That does not solve my problem. Populating one combobox is not an issue.
Having just one combobox is not an option.

Am I going down a path that does not exist?

Are you (and Ken) saying that I can not set up a source combobox, with all
it's entries, then copy it in total and use the copy independently from the
source?
 
M

Mike McIntyre

EdB,

I am not saying "you can not set up a source combobox, with all it's
entries, then copy it in total and use the copy independently from the
source".

What I proposed is a common solution to optimizing the loading of
ComboBoxes.

There are other techniques too, but at this point I think I don't understand
your goal clearly.

What is the purpose of loading the ComboBoxes the way you outlined?

Is it to let the rest of the form load and be viewable immediately while
several ComboBoxes build in the background and become useable when they are
filled?

If that is the case you can use asynchronous delegates (one way to thread).

As the form loads your calls the delegate(s) that fill the ComboBoxe(s). The
delegates start building the ComboBoxes in the background and do not
interfer with loading the rest of the form. You can start with the
ComboBoxes disabled. You can have the delegate(s) call back to a procedure
in your code each time a ComboBox is filled and the procedure can enable the
ComboBox.

Or, please clarify your goal and we will see what we can do. ;-)


--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com
 
C

Cor Ligthert

EdB,

Are you searching for this?
\\\
ComboBox1.Top = 40
ComboBox1.Left = 8
Dim intLoop As Integer
For intLoop = 1 To 5000
ComboBox1.Items.Add(intLoop)
Next
Dim cbo2 As New ComboBox
cbo2.Top = 80
cbo2.Left = 8
cbo2.Text = "ComboBox2"
Dim myarray(ComboBox1.Items.Count - 1) As Object
ComboBox1.Items.CopyTo(myarray, 0)
cbo2.Items.AddRange(myarray)
Me.Controls.Add(cbo2)
///

http://msdn.microsoft.com/library/d...scomboboxobjectcollectionclasscopytotopic.asp

I hope this helps?

Cor
 
M

Mike McIntyre

Cor,

Or to avoid the overhead of building a CombBox to build the data:


Dim integers(4999) As Object

Dim i As Integer
For i = 0 To 4999
integers(i) = i
Next

Me.ComboBox1.Items.AddRange(integers)

Mike
 
C

Cor Ligthert

Mike,

True, however my purpose of the sample was to show the tocopy.

However the solution could be even shorter with what you wrote.

:)

Cor
 
G

Guest

I appreciate the help. Let me give more detail as to the application and
then perhaps you'll reccommend a best approach.

The application is for a national courier company. Drivers get paid for
routes they run on given days. At the end of the week, a settlement
(compensation) process occurs. While most of the information is set for the
user, exceptions must be dealt with.

So, for each day of the week, there is a combo box populated with all the
routes that exist within a given geographic area. In more dense areas, there
can be lots of routes. The screen takes a long time to paint for these
"terminals" because I am populating the SundayRoute, MondayRoute,
TuesdayRoute, etc... combo boxes.

I need one for each day because a driver may do one route on Monday, another
on Tuesday. The day by day comboboxes are very intuitive to the user.

Since the content is all the same for each, I figured I could populate one,
then copy. I'm afraid that the copyto won't reduce the overhead.
 
M

Mike McIntyre

EdB,

I am starting to see a solution. I need a little more clarification:

When you say 'Since the content is the same for each' does this mean each
combo box holds the same data as the next? For example, using a number
series as an example of route data:

MondayComboBox Items
1
2
3
4

TuesdayComboBox Items
1
2
3
4

WednesdayComboBox Items
1
2
3
4
5

and the same for Thursday, Friday, etc.?

Is the operation on the screen to, for one driver - pick one route for
Monday, one route for Tuesday, and so on?

Can you give an example of the real data? Is it really numbers you showed
in your original example? If not what is actually shown for each route item
in the ComboBox.

Mike
 
M

Mike McIntyre

EdB,

I am leaving for a project meeting.

If you want send the information to (e-mail address removed). I won't be
checking this newsgroup until tomorrow AM but I will be checking my email
several times today.


--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com\
 
L

Larry Serflaten

EdB said:
I need one for each day because a driver may do one route on Monday, another
on Tuesday. The day by day comboboxes are very intuitive to the user.

Since the content is all the same for each, I figured I could populate one,
then copy. I'm afraid that the copyto won't reduce the overhead.

Are you sure combo boxes would be more intuitive than a grid? With the
week days as the columns, and the routes as the rows, where checkmarks
indicate which route was taken, it would be pretty intuitive to know how to
use that interface. Plus with an option (you'd add) to view only the selected
routes, the entire week could be verified at a glance.

And what if, one day, a driver pulls two routes in one day?

For an example grid, check out this link:
http://www.vbnet.mvps.org/code/intrinsic/matrixcheck.htm

LFS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top