Solved

programatically generate checkbox

Posted on 2004-08-12
3
564 Views
Last Modified: 2012-05-05
Hi Experts,
   I need to create checkbox in RUNTIME based on the criteria pooling from table which means that got 5 items it will display 5 checkboxes , if got 6 items it will display 6 checkboxes.
How can I do it?


Thanks,rgds,
KA
0
Comment
Question by:SAPKEN
3 Comments
 
LVL 24

Accepted Solution

by:
Justin_W earned 500 total points
ID: 11786242
Assuming you want to do so in an ASP.NET web form, you have 2 options:

1. Use the CheckBoxList control and set its DataSource.  It will display 1 CheckBox per item in the DataSource.

2. Dynamically create CheckBox controls using code.  This PAQ describes how to do this for LinkButtons:
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21023551.html
You would do exactly the same thing for CheckBox controls instead of LinkButtons.

If you are doing this in a Windows Form, then you just instantiate CheckBox controls and add and position them on your form.
0
 
LVL 8

Expert Comment

by:bramsquad
ID: 11786423
i got this from a PAQ, hopefully modded to what you need

       'this will be the locations
       dim x, y as integer

       x = 100
       y = 100


        For i = 0 To ControlCount - 1

            Dim ctrl As New System.Windows.Forms.CheckBox

            ctrl.Name = "CheckBox" + i.ToString()
            ctrl.Text = "CheckBox" + i.ToString()

            ctrl.Location = New System.Drawing.Point(x, y)
            'so its not one on top of the other
            y += 16

            'im assuming youre not needing event handlers...

            Controls.Add(x)                     ' Add the control to the collection of controls
        Next

~b
0
 
LVL 22

Expert Comment

by:mnasman
ID: 11786436
Hello

   Here's a sample, but isntead of reading the No of tables, it will read it from the user using InputBox, reading it from DB is easy using command object and call ExecuatScaler to return the No of CheckBoxes you want to create

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Num As Integer = InputBox("Enter No of check boxes", "CheckBoxes No")
        Dim I As Integer

        For I = 1 To Num
            Dim chk As New CheckBox
            chk.Left = 0
            chk.Top = 20 * I
            chk.Text = "CheckBox No " & I
            Me.Controls.Add(chk)
        Next
    End Sub

HTH

Regards,
Mohammed
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now