?
Solved

Change properites/read information of progrmmatically created items

Posted on 2007-10-10
8
Medium Priority
?
185 Views
Last Modified: 2010-04-23
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!
0
Comment
Question by:higginsonline
  • 4
  • 3
8 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20048388
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
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 1000 total points
ID: 20048451
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
 

Author Comment

by:higginsonline
ID: 20048850
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 64

Expert Comment

by:Fernando Soto
ID: 20048939
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
 

Author Comment

by:higginsonline
ID: 20049625
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
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 20050487
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
 

Author Comment

by:higginsonline
ID: 20050629
Once again you are the man, thank you
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 20050652
Not a problem, glad I was of some help. ;=)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

809 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