OK,
VB6:
ListBox1.Clear
ListBox1.AddItem "Apples"
ListBox1.AddItem "Oranges"
How do you do this in VB.Net?
Thanks,
Ken
Printable View
OK,
VB6:
ListBox1.Clear
ListBox1.AddItem "Apples"
ListBox1.AddItem "Oranges"
How do you do this in VB.Net?
Thanks,
Ken
VB Code:
With ListBox1 .Items.Clear() .Items.Add("Apples") .Items.Add("Oranges") End With
Thanks Bananafish,
That solved that problem. However, now I don't have access to the ListBox except within the routine where I used the Dim statement.
Public Sub Template_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ListBox1 As New ListBox()
End Sub
This next routine generates an error!
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
With listbox1
.Visible = False
End With
End Sub
What am I doing wrong?
Thanks,
Ken
It's a scope problem. The Dim statement makes the variable (in this case a listbox) only available in the sub routine it is declared.
If you wanted the scope of the listbox to be available to the entire class (a form is also a class) then you would have to declare it at the start. ie
VB Code:
Public Class YourClass Private ListBox1 as New ListBox()
However, If your class is a form is there any reason you aren't adding the Listbox control to the form? you should do this at design time by dragging the ListBox from the ToolBox and on to your form...
or if you actually wish to do it at run time, you can add it toi the forms control collection...
Duh!!
Ok,
I'm tired, I have headache, my back hurts, the Cowboys suck ---
Thanks,
Ken