Checkbox arrays

F

Fred Flintstone

I have an app that requires the use of a 2 dimensional array of
checkboxes. I can't seem to assign any values to them. I tried this:

Dim BonusChecks(0, 0) As CheckBox

...and then later when I know the domensions I'll need:

ReDim BonusChecks(x,y) ' (3,3), no error
BonusChecks(0,0).ID = "1" 'Object reference not set to an instance of
an object

If it's not allocated any memory, what did the redim statement do?

So I found another syntax:

Dim BonusChecks(3,3) as New Checkbox ' No error
BonusChecks(0,0).ID = "1" ' Same error,

What am I missing? I thought ReDim or New would initialize the array.
How do I get an array of checkboxes working?

Thanks!
 
D

dkode

AFAIK,

ReDim only changes the size of the array, don't you need to add an
instance of type checkbox to (0,0)?

I might be way off base here, never touched checkbox arrays b4
 
B

Bruce Barker

..net does not have control arrays like vb6.

Dim BonusChecks(3,3) as New Checkbox

creates a 2 dimensional array of type Checkbox. all the entries will be null
(nothing in vb), until you put an entry in the array. a redim, keeps the old
values, but the new values will be null.

also unlike vb6 control arrays, adding control to an array will not make
them appear. you need to add then to the page. the most common approach is
to add a place holder to the page, and add the controls to the placeholder.
also if you create dynamic control, you must recreate them on postback
(before onload), so be sure to save some state infomation in viewstate, to
know what to do.

you would proably be better off using a repeater with templates.


-- bruce (sqlwork.com)
 
F

Fred Flintstone

".net does not have control arrays like vb6."

But I use single dimension arrays of dynamic textboxes that work just
fine.

">creates a 2 dimensional array of type Checkbox. all the entries will
be null (nothing in vb), until you put an entry in the array."

Isn't that what this is doing?:

Dim BonusChecks(3,3) as New Checkbox ' No error
BonusChecks(0,0).ID = "1" 'Object reference not set to an instance of

Thanks for the reply, much appreciated.
 
F

Fred Flintstone

AFAIK,

ReDim only changes the size of the array, don't you need to add an
instance of type checkbox to (0,0)?

I might be way off base here, never touched checkbox arrays b4


"don't you need to add an instance of type checkbox to (0,0)?"

Isn't that what this is doing?:

Dim BonusChecks(3,3) as Checkbox
BonusChecks(0,0).ID = "1"

Doesn't the Dim statement allocate memory for the entire array? (16
elements)

It's like this is some kind of new array type that defies the basic
behavior of an array. I'm completely confused by it.

Thanks!
 
F

Fred Flintstone

Wait, I got it:

Dim BonusChecks(3,3) as Checkbox

Bonuschecks(0,0) = New Checkbox
BonusChecks(0,0).ID = "1"

THAT works. Thanks for the push. :)
 

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

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top