Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

programatically generate checkbox

Posted on 2004-08-12
3
Medium Priority
?
572 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 24

Accepted Solution

by:
Justin_W earned 2000 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:Mohammed Nasman
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

609 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