Textbox Array
-
Hi, I am stuck on VB.NET 2005, in VB6 i was able to load objects at run-time. Problem is I am asking user how many textboxes they want and then system will create an array of those textboxes. Here's the code I was using in VB6. I already had one textbox on form and the index was set to 0.(can't even do that vb.net):confused:
For i = 1 to iSelectedNum Load TextBox(i) TextBox(i).Visible = True TextBox(i).Top = TextBox(i - 1).Top + TextBox(i - 1).Height TextBox(i).Left = TextBox(i - 1).Left TextBox(i).Text = "" Next i
I tried Code Upgrade function from VS 2005 but did not worK!!! Anyone please HELP!! :sigh:
-
Hi, I am stuck on VB.NET 2005, in VB6 i was able to load objects at run-time. Problem is I am asking user how many textboxes they want and then system will create an array of those textboxes. Here's the code I was using in VB6. I already had one textbox on form and the index was set to 0.(can't even do that vb.net):confused:
For i = 1 to iSelectedNum Load TextBox(i) TextBox(i).Visible = True TextBox(i).Top = TextBox(i - 1).Top + TextBox(i - 1).Height TextBox(i).Left = TextBox(i - 1).Left TextBox(i).Text = "" Next i
I tried Code Upgrade function from VS 2005 but did not worK!!! Anyone please HELP!! :sigh:
Control arrays don't exist under VB.NET. However, you can create your own quite easily.
Dim myTextBoxes As New List(Of TextBox) For i = 1 to iSelectedNum Dim newTextBox As New TextBox() With newTextBox .Top = _calculated Top value_ .Left = _calculated Left value_ .Text = "_whatever text you want_" End With myTextBoxes.Add(newTextBox) Me.Controls.Add(newTextBox) Next
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Control arrays don't exist under VB.NET. However, you can create your own quite easily.
Dim myTextBoxes As New List(Of TextBox) For i = 1 to iSelectedNum Dim newTextBox As New TextBox() With newTextBox .Top = _calculated Top value_ .Left = _calculated Left value_ .Text = "_whatever text you want_" End With myTextBoxes.Add(newTextBox) Me.Controls.Add(newTextBox) Next
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Private myTextBoxes As List(Of TextBox) .... Private Sub CreateTextBoxes(ByVal count As Integer) myTextBoxes = New Dictionary(Of String, TextBox) For i As Integer = 1 To count Dim newTextBox As New TextBox With newTextBox .Top = i \* 20 .Left = 10 .Size = New Size(100, 18) End With myTextBoxes.Add(newTextBox) Me.Controls.Add(newTextBox) Next i ... myTextBoxes(6).ForeColor = Color.Blue
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Private myTextBoxes As List(Of TextBox) .... Private Sub CreateTextBoxes(ByVal count As Integer) myTextBoxes = New Dictionary(Of String, TextBox) For i As Integer = 1 To count Dim newTextBox As New TextBox With newTextBox .Top = i \* 20 .Left = 10 .Size = New Size(100, 18) End With myTextBoxes.Add(newTextBox) Me.Controls.Add(newTextBox) Next i ... myTextBoxes(6).ForeColor = Color.Blue
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007Thanks for Reply. But there is still one problem in the example of code you wrote, and i cant figure it out why is it happening. It gives me following error
"Error1 -> Value of type 'System.Collections.Generic.Dictionary(Of String, System.Windows.Forms.TextBox)' cannot be converted to 'System.Collections.Generic.List(Of System.Windows.Forms.TextBox)'."
myTextBoxes = New Dictionary(Of String, TextBox)
-
Thanks for Reply. But there is still one problem in the example of code you wrote, and i cant figure it out why is it happening. It gives me following error
"Error1 -> Value of type 'System.Collections.Generic.Dictionary(Of String, System.Windows.Forms.TextBox)' cannot be converted to 'System.Collections.Generic.List(Of System.Windows.Forms.TextBox)'."
myTextBoxes = New Dictionary(Of String, TextBox)
Sorry, my mistake. That line should be:
myTextBoxes = New List(Of String)
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007