How to combine 2 lists of textboxes

W

weg22

Hi all,

I have two lists of textboxes:

'Create list of all textboxes on error log data tab
el_textboxes = New List(Of Windows.Forms.TextBox)(New
Windows.Forms.TextBox() {addr_x100, addr_x101, _
addr_x102, addr_x103, addr_x104, addr_x105, addr_x106,
addr_x107, addr_x108, addr_x109, addr_x10A, _
addr_x10B, addr_x10C, addr_x10D, addr_x10E, addr_x10F})

'Create list of all textboxes on status data tab
sd_textboxes = New List(Of Windows.Forms.TextBox)(New
Windows.Forms.TextBox() {idr_x000, idr_x001, _
idr_x002, idr_x003, idr_x004, idr_x005, idr_x006, idr_x007,
idr_x008, idr_x009, idr_x00A, _
idr_x00B, idr_x00C, idr_x00D, idr_x00E, idr_x00F})


How do I combine these 2 lists into one list (e.g. "all_textboxes")?
I tried the following:
all_textboxes = el_textboxes
all_textboxes.AddRange(sd_textboxes)

but then when I go back and do some processing with el_textboxes, its
size seems to change. I'm guessing there's a better way of combining
the 2 lists?

Thanks in advance,
-weg
 
A

Armin Zingler

Hi all,

I have two lists of textboxes:

'Create list of all textboxes on error log data tab
el_textboxes = New List(Of Windows.Forms.TextBox)(New
Windows.Forms.TextBox() {addr_x100, addr_x101, _
addr_x102, addr_x103, addr_x104, addr_x105, addr_x106,
addr_x107, addr_x108, addr_x109, addr_x10A, _
addr_x10B, addr_x10C, addr_x10D, addr_x10E, addr_x10F})

'Create list of all textboxes on status data tab
sd_textboxes = New List(Of Windows.Forms.TextBox)(New
Windows.Forms.TextBox() {idr_x000, idr_x001, _
idr_x002, idr_x003, idr_x004, idr_x005, idr_x006, idr_x007,
idr_x008, idr_x009, idr_x00A, _
idr_x00B, idr_x00C, idr_x00D, idr_x00E, idr_x00F})


How do I combine these 2 lists into one list (e.g. "all_textboxes")?
I tried the following:
all_textboxes = el_textboxes
all_textboxes.AddRange(sd_textboxes)

but then when I go back and do some processing

What kind of processing?
with el_textboxes,
its size seems to change.

Who's size? all_textboxes'?
I'm guessing there's a better way of
combining the 2 lists?

Do you experience an unexpected behavior or do you look for another way to
copy the items of both Lists into one?


Armin
 
G

Guest

the line of code:
all_textboxes = el_textboxes
just gives you 2 references to the same list.
maybe something like:
dim all_textboxes as new List(of ....)
all_textboxes.addrange(el_textboxes)
all_textboxes.addrange(sd_textboxes)
 
W

weg22

What kind of processing?

For Each _textbox As Windows.Forms.TextBox In el_textboxes
'Processing...
array(i) = 10
i = i + 1
Next

array() is the same size as the number of elements in el_textboxes.
When commenting out the "all_textboxes" lines from above, the For loop
executes without any errors. However, when uncommenting the
"all_textboxes" lines from above, I get an index out of range error
for array(i).
 
A

Armin Zingler

For Each _textbox As Windows.Forms.TextBox In el_textboxes
'Processing...
array(i) = 10
i = i + 1
Next

array() is the same size as the number of elements in el_textboxes.
When commenting out the "all_textboxes" lines from above, the For
loop executes without any errors. However, when uncommenting the
"all_textboxes" lines from above, I get an index out of range error
for array(i).

I was not sure about the problem, but Terry probably has the answer.


Armin
 
C

Cor Ligthert[MVP]

Like Armin I don't understand your problem.

However you can start stopping this kind of code and use a for index loop.
(Every array or collection has a count or length property)
 
Top