Change properites/read information of progrmmatically created items

There is probably a simple answer to this but...

I programmatically created text boxes with a loop from a database.  Now I need to be able to click a button(that I also created progrmmatically) and it will turn those text boxes read only value from true to false, I also need it to pop up information about the current text in those text fields.  Below is the link that discusses how I created the text boxes and buttons.

I need to be able to do this at a later time then they are created.

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_22879803.html

Thanks!
higginsonlineAsked:
Who is Participating?
 
Fernando SotoRetiredCommented:
Hi higginsonline;

This will do what you need.

    Private Sub DisableTextBoxes_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles DisableTextBoxes.Click

        For Each obj As Object In htTextBox.Values
            Dim tb As TextBox = CType(obj, TextBox)
            tb.ReadOnly = True
        Next

    End Sub

Fernando
0
 
Bob LearnedCommented:
If you are dynamically creating TextBox controls, and then you later want to reference those controls from a button click event handler, then you need to store the reference in some kind of list structure.

Bob
0
 
higginsonlineAuthor Commented:
Fernando,

The only problem with that is I create 3 different text boxes per row
  tbName   tbPrice  tbGLAcct
I want tbName tbPrice and tbGLAcct read only to = false
Not every instance of tbName.

So what would I change the obj to?
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
Fernando SotoRetiredCommented:
If I understand you correctly the button that you created on each row should make the three text boxes on that same row read only when it is clicked?

If that is the case then you need a way to identify the three text boxes on the same row as the button. How do you set the Name property of the TextBox's on each row?
0
 
higginsonlineAuthor Commented:
Private htTextBoxName As New Hashtable
    Private htTextBoxPrice As New Hashtable
    Private htTextBoxGLacct As New Hashtable
    Private htCheckBoxOver As New Hashtable

con.Open()
        OledbRead = cmd.ExecuteReader(CommandBehavior.CloseConnection)
        While OledbRead.Read()
            Dim idx As Integer = OledbRead.Item("itemID")
            Dim tbName As New TextBox
            tbName.Name = "plName" & idx.ToString()
            tbName.Location = New Point(X, Y)
            tbName.Text = OledbRead.Item("ItemName")
            tbName.Font = verdana
            tbName.BorderStyle = BorderStyle.FixedSingle
            tbName.Width = 120
            tbName.ReadOnly = True
            Panel2.Controls.Add(tbName)

            Dim tbPrice As New TextBox
            tbPrice.Name = "plPrice" & idx.ToString()
            tbPrice.Location = New Point(Xprice, Y)
            tbPrice.Text = OledbRead.Item("BasePrice")
            tbPrice.Font = verdana
            tbPrice.BorderStyle = BorderStyle.FixedSingle
            tbPrice.Width = 75
            tbPrice.ReadOnly = True
            tbPrice.TextAlign = HorizontalAlignment.Right
            Panel2.Controls.Add(tbPrice)

            Dim tbGLacct As New TextBox
            tbGLacct.Name = "plGLacct" & idx.ToString()
            tbGLacct.Location = New Point(Xglacct, Y)
            tbGLacct.Text = OledbRead.Item("GLacct")
            tbGLacct.Font = verdana
            tbGLacct.BorderStyle = BorderStyle.FixedSingle
            tbGLacct.Width = 75
            tbGLacct.ReadOnly = True
            tbGLacct.TextAlign = HorizontalAlignment.Right
            Panel2.Controls.Add(tbGLacct)

            Dim cbOver As New CheckBox
            cbOver.Name = "plOverRide" & idx.ToString()
            cbOver.Location = New Point(Xover, Y)
            cbOver.Width = 15
            cbOver.Font = verdana
            If OledbRead.Item("Override") = True Then cbOver.Checked = True
            cbOver.Enabled = False
            Panel2.Controls.Add(cbOver)

            Dim ebtn As New Button()
            ebtn.Text = "Edit"
            ebtn.Name = "Row" & row.ToString()
            ebtn.Location = New Point(Xbtn, Y)
            ' I am using the Tag property to identify the row clicked on
            ebtn.Tag = idx.ToString
            ebtn.Font = verdana
            ebtn.Width = 75
            ' Because you want to be able to click on the button and have an event fired
            ' you need to have written a subroutine to handle that in advance. This wires
            ' the Click event on the button to that subroutine
            AddHandler ebtn.Click, AddressOf Row_Click
            Panel2.Controls.Add(ebtn)

            Dim dbtn As New Button()
            dbtn.Text = "Delete"
            dbtn.Name = "dRow" & row.ToString()
            dbtn.Location = New Point(Xbtn1, Y)
            ' I am using the Tag property to identify the row clicked on
            dbtn.Tag = idx.ToString
            dbtn.Font = verdana
            dbtn.Width = 75
            ' Because you want to be able to click on the button and have an event fired
            ' you need to have written a subroutine to handle that in advance. This wires
            ' the Click event on the button to that subroutine
            AddHandler dbtn.Click, AddressOf Row_Click2
            Panel2.Controls.Add(dbtn)


            Y += 30
            htCheckBoxOver.Add(cbOver.Name, cbOver)
            htTextBoxGLacct.Add(tbGLacct.Name, tbGLacct)
            htTextBoxPrice.Add(tbPrice.Name, tbPrice)
            htTextBoxName.Add(tbName.Name, tbName)
        End While
        OledbRead.Close()
        con.Close()
0
 
Fernando SotoRetiredCommented:
Hi higginsonline;

This code when placed in the click event of the button that you click will make the three TextBox's in that row ReadOnly

        Dim btn As Button = CType(sender, Button)
        Dim row As String = btn.Tag.ToString()

        CType(htTextBoxName("plName" & row), TextBox).ReadOnly = True
        CType(htTextBoxPrice("plPrice" & row), TextBox).ReadOnly = True
        CType(htTextBoxGLacct("plGLacct" & row), TextBox).ReadOnly = True

Fernando
0
 
higginsonlineAuthor Commented:
Once again you are the man, thank you
0
 
Fernando SotoRetiredCommented:
Not a problem, glad I was of some help. ;=)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.