PC Review


Reply
Thread Tools Rate Thread

Controls function

 
 
James@aol.com
Guest
Posts: n/a
 
      6th Feb 2007
I have three checkbox that I want to check the state (checkbox1
checkbox2 checkbox3

I do the following

Dim i As Integer
Dim chk As New CheckBox
For i = 1 To 3
chk = (Controls("CheckBox" & CStr(i)))
If chk.CheckState = CheckState.Unchecked Then
.....Code
End If
Next

This works if the checkbox are NOT in a Panel only. Why??

 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      6th Feb 2007
<(E-Mail Removed)> schrieb
> I have three checkbox that I want to check the state (checkbox1
> checkbox2 checkbox3
>
> I do the following
>
> Dim i As Integer
> Dim chk As New CheckBox
> For i = 1 To 3
> chk = (Controls("CheckBox" & CStr(i)))
> If chk.CheckState = CheckState.Unchecked Then .....Code
> End If
> Next
>
> This works if the checkbox are NOT in a Panel only. Why??


Because they are not controls in the Form but controls in the Panel. Use
this instead:

chk = YourPanel.Controls("CheckBox" & CStr(i))

Armin

 
Reply With Quote
 
rowe_newsgroups
Guest
Posts: n/a
 
      6th Feb 2007
On Feb 6, 5:59 am, "Armin Zingler" <az.nos...@freenet.de> wrote:
> <J...@aol.com> schrieb
>
> > I have three checkbox that I want to check the state (checkbox1
> > checkbox2 checkbox3

>
> > I do the following

>
> > Dim i As Integer
> > Dim chk As New CheckBox
> > For i = 1 To 3
> > chk = (Controls("CheckBox" & CStr(i)))
> > If chk.CheckState = CheckState.Unchecked Then .....Code
> > End If
> > Next

>
> > This works if the checkbox are NOT in a Panel only. Why??

>
> Because they are not controls in the Form but controls in the Panel. Use
> this instead:
>
> chk = YourPanel.Controls("CheckBox" & CStr(i))
>
> Armin


Just adding to Armin. If the only checkboxes your panel contains are
the checkboxes you want to investigate you could do this (as I hate
getting controls by name):

<pseudocode>

For each ctl as Control in YourPanel.Controls
If typeof(ctl) is Checkbox andalso directcast(ctl,
Checkbox).CheckState = CheckState.Unchecked then
' Do Stuff
End If
Next

</pseudocode>

Thanks,

Seth Rowe


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing check box controls to a function Dennis Microsoft Access Form Coding 2 19th May 2008 01:55 PM
Call Same Function for multiple controls =?Utf-8?B?Q2FuIE9mIFdvcm1z?= Microsoft Access Form Coding 3 15th Oct 2007 08:54 PM
Multiple controls to call the same function Rob Meade Microsoft Dot NET Framework Forms 9 4th Jul 2004 03:51 PM
do some function like HTML controls Grey Microsoft ASP .NET 1 20th Jan 2004 05:21 PM
Dot Matrix Printer Controls Don't Function John Microsoft Windows 2000 Printing 0 29th Aug 2003 07:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:07 AM.