Results 1 to 4 of 4

Thread: How to create indexed controls? [Resolved]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Europe, Lithuania
    Posts
    309

    How to create indexed controls? [Resolved]

    hey,

    I want to create programaticly 100 of checkboxes with names like checkbox(from 1 to 100). Then I should be able to check which one is checked or not. Is is possible to make? In VB 6 it was easy.

    Thanks.
    Last edited by Norkis; Feb 18th, 2004 at 10:29 PM.

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    As you have probably noticed, there is no Index propertyin any of the controls and this is because Collections has replaced them in VB.NET

    Have a look at the MSDN help on Collections.

    Although more difficult to create, Collections offers a more efficient way than Indexes and is great - once you get used to it.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  3. #3
    Lively Member ayan's Avatar
    Join Date
    Jan 2004
    Posts
    112
    halu,

    i'm a newbie though. but check this out... this might help... if not please let me know...

    VB Code:
    1. Friend WithEvents b As New Button()
    2.     Dim c(9) As CheckBox
    3.     Dim WithEvents cc As New CheckBox()
    4.  
    5.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    6.         Dim i As Integer
    7.         Dim l As Integer = 16
    8.         For i = 0 To 9
    9.             cc = New CheckBox()
    10.             c(i) = cc
    11.             c(i).TabIndex = i
    12.             c(i).Name = i.ToString
    13.             c(i).Text = i.ToString
    14.             c(i).Location = New Point(24, l)
    15.             l += 25
    16.             Controls.AddRange(New Control() {c(i)})
    17.         Next
    18.         b.Location = New Point(24, l)
    19.         Controls.AddRange(New Control() {b})
    20.     End Sub
    21.  
    22.     Private Sub b_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b.Click
    23.         Dim c As CheckBox
    24.         Dim s As String = String.Empty
    25.         For Each c In Me.c
    26.             If c.Checked = True Then
    27.                 s += c.Name
    28.             End If
    29.         Next
    30.         MsgBox(s)
    31.     End Sub
    cheers,
    --ayan

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Europe, Lithuania
    Posts
    309
    Cool, It works. Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width