1

I want to create TextBoxes dynamically in tabular format. So far i am successful of creating 10 textboxes in a vertical format. But i want to create 10X10 grid of textboxes. Here is the code. This code runs successfully but creates only 10 textboxes. I know there's a small mistake in code but i am not getting it. Please help

Dim XPos, YPos As Integer
    Dim i As Integer = 1
    Dim j As Integer = 1
    Dim newBox As TextBox
    XPos = 20
    YPos = 30
    For i = 1 To 10
        For j = 1 To 10
            newBox = New TextBox
            newBox.Name = "txtR" & i & "C" & j
            newBox.Size = New Drawing.Size(54, 22)
            newBox.Location = New Point(XPos, YPos)
            newBox.Text = newBox.Name
            Me.Controls.Add(newBox)
        Next
        YPos += 30
    Next
1
  • 1
    You're not incrementing XPos in your j loop, your textboxes are being created over the top of each other. Commented Mar 6, 2015 at 11:36

2 Answers 2

2

Below code will help you

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim XPos, YPos As Integer
    Dim i As Integer = 1
    Dim j As Integer = 1
    Dim newBox As TextBox
    XPos = 20
    YPos = 30
    For i = 1 To 10
        XPos = 20
        For j = 1 To 10
            newBox = New TextBox
            newBox.Name = "txtR" & i & "C" & j
            newBox.Size = New Drawing.Size(54, 22)
            newBox.Location = New Point(XPos, YPos)
            newBox.Text = newBox.Name
            Me.Controls.Add(newBox)
            XPos += newBox.Width + 5
        Next
        YPos += 30
    Next
End Sub
Sign up to request clarification or add additional context in comments.

Comments

0

enter image description here

Hello, add tasks EXAMPLE Here this code to add the textbox in runtime to panel (container_control) then move the scrollbar of the panel to the current and last textbox will add:

Dim txt As TextBox
Dim newLine As Integer = 50
Dim taskN As Integer = 1




Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Panel1.AutoScrollPosition = New Point()

    txt = New TextBox()
    txt.Name = "note1"

    'txt.BringToFront()

    txt.Location = New System.Drawing.Point(111, newLine)
    txt.Size = New System.Drawing.Size(318, 68)
    txt.Text = "Task" + taskN.ToString()

    txt.Font = New Font("Verdana", 30, FontStyle.Regular)

    Panel1.Controls.Add(txt)

    Me.Text = Panel1.AutoScrollPosition.ToString()
    Label1.Text = txt.Location.ToString()

    newLine += 60
    taskN += 1
    'Me.SuspendLayout()

    Panel1.ScrollControlIntoView(txt)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.