By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,918 Members | 1,852 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,918 IT Pros & Developers. It's quick & easy.

Checkbox arrays

P: n/a
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!

Mar 14 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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

Mar 14 '06 #2

P: n/a
..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)

"Fred Flintstone" <id**********@nospam.com> wrote in message
news:5g********************************@4ax.com...
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!

Mar 14 '06 #3

P: n/a
".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.

On Tue, 14 Mar 2006 09:09:49 -0800, "Bruce Barker"
<br******************@safeco.com> wrote:
.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)

"Fred Flintstone" <id**********@nospam.com> wrote in message
news:5g********************************@4ax.com.. .
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!


Mar 14 '06 #4

P: n/a
On 14 Mar 2006 09:09:03 -0800, "dkode" <dk****@gmail.com> wrote:
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!

Mar 14 '06 #5

P: n/a
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. :)

On Tue, 14 Mar 2006 09:09:49 -0800, "Bruce Barker"
<br******************@safeco.com> wrote:
.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)

"Fred Flintstone" <id**********@nospam.com> wrote in message
news:5g********************************@4ax.com.. .
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!


Mar 14 '06 #6

P: n/a
i knew it was something along those lines :)

Mar 14 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.