Solved

Accessing a control's properties

Posted on 2007-11-29
3
181 Views
Last Modified: 2010-04-23
I have one sub where I dynamically create checkboxlist items...

Dim chk As New CheckBox
   With chk
        AddHandler chk.CheckStateChanged, AddressOf chkBox_CheckedChanged
        .Name = strName

In that checkstatechanged event, I'm trying to set another created control's name based off the checkbox's name:

    Private Sub chkBox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim cbo as New CustomCombo
        cbo.Name = "Primary " & chkBox.Name

but that gives me the error: Name 'chkbox' is not declared

How can I get around this?
0
Comment
Question by:sirbounty
  • 2
3 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 250 total points
ID: 20376410
Here's a case where you can use the sender parameter:

Private Sub chkBox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim cbo as New CustomCombo
        Dim chkBox As CheckBox = DirectCast(sender, CheckBox)
        cbo.Name = "Primary " & chkBox.Name
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 20376419
I don't think you can have a space in a control name however...
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20376466
it is no chk?
cbo.Name = "Primary " & chk.Name
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question