|
-
Jan 11th, 2002, 11:09 AM
#1
Thread Starter
Hyperactive Member
ListBox Question
OK,
VB6:
ListBox1.Clear
ListBox1.AddItem "Apples"
ListBox1.AddItem "Oranges"
How do you do this in VB.Net?
Thanks,
Ken
-
Jan 14th, 2002, 05:53 AM
#2
Hyperactive Member
VB Code:
With ListBox1
.Items.Clear()
.Items.Add("Apples")
.Items.Add("Oranges")
End With
-
Jan 14th, 2002, 03:15 PM
#3
Thread Starter
Hyperactive Member
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
-
Jan 15th, 2002, 06:36 AM
#4
Hyperactive Member
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...
-
Jan 15th, 2002, 07:47 PM
#5
Thread Starter
Hyperactive Member
Duh!!
Ok,
I'm tired, I have headache, my back hurts, the Cowboys suck ---
Thanks,
Ken
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|