higginsonline
asked on
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.
https://www.experts-exchange.com/questions/22879803/Programmatically-Add-Text-Boxes-to-a-WinForm-in-Visual-Basic-2005.html
Thanks!
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.
https://www.experts-exchange.com/questions/22879803/Programmatically-Add-Text-Boxes-to-a-WinForm-in-Visual-Basic-2005.html
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
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?
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?
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?
ASKER
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(CommandB ehavior.Cl oseConnect ion)
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(tbPric e)
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(tbGLac ct)
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(tbGLac ct.Name, tbGLacct)
htTextBoxPrice.Add(tbPrice .Name, tbPrice)
htTextBoxName.Add(tbName.N ame, tbName)
End While
OledbRead.Close()
con.Close()
Private htTextBoxPrice As New Hashtable
Private htTextBoxGLacct As New Hashtable
Private htCheckBoxOver As New Hashtable
con.Open()
OledbRead = cmd.ExecuteReader(CommandB
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(tbPric
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(tbGLac
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")
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.
htTextBoxGLacct.Add(tbGLac
htTextBoxPrice.Add(tbPrice
htTextBoxName.Add(tbName.N
End While
OledbRead.Close()
con.Close()
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("plNam e" & row), TextBox).ReadOnly = True
CType(htTextBoxPrice("plPr ice" & row), TextBox).ReadOnly = True
CType(htTextBoxGLacct("plG Lacct" & row), TextBox).ReadOnly = True
Fernando
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("plNam
CType(htTextBoxPrice("plPr
CType(htTextBoxGLacct("plG
Fernando
ASKER
Once again you are the man, thank you
Not a problem, glad I was of some help. ;=)
Bob