Solved

ListBox1_SelectedIndexChanged' is not declared.

Posted on 2006-07-14
13
352 Views
Last Modified: 2009-12-16
I am adding a list box to the form like this and i am getting this error.Can you please tell me how to fix it?

       Dim ListBox1 = New ListBox
        ListBox1.Size = New Size(200, 100)   'set size
        ListBox1.Location = New Point(10, 60)  'location
        AddHandler ListBox1.SelectedIndexChanged, AddressOf ListBox1_SelectedIndexChanged   'add the event.
        Me.Controls.Add(ListBox1)
        ListBox1.MultiColumn = True
        ListBox1.SelectionMode = SelectionMode.MultiExtended

 

    for AddressOf ListBox1_SelectedIndexChanged it is giving error
"  Name 'ListBox1_SelectedIndexChanged' is not declared."

0
Comment
Question by:aio419
  • 6
  • 4
13 Comments
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 17109646
Have you created the event handler?
0
 

Author Comment

by:aio419
ID: 17109813
While creating the event hander it is giving error
AddHandler ListBox1.SelectedIndexChanged, AddressOf ListBox1_SelectedIndexChanged  
it  do not like the 2nd part ie.AddressOf ListBox1_SelectedIndexChanged  
Is that what you asked?
0
 
LVL 17

Assisted Solution

by:ZeonFlash
ZeonFlash earned 20 total points
ID: 17109823
As Chaosian said, you're getting that error because you haven't created the event function yet.  Add the following to your code:

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub


You might also need to re-type the listbox (at least I did when trying it out):

        AddHandler CType(ListBox1, ListBox).SelectedIndexChanged, AddressOf ListBox1_SelectedIndexChanged  'add the event.


0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 24

Accepted Solution

by:
Jeff Certain earned 20 total points
ID: 17110049
Of course, the easy way to do this is

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

    End Sub
0
 

Author Comment

by:aio419
ID: 17111095
Thanks guys.
Okay. If you want to create a list box at run time, how we do that. Do we have to make the event hander first and then make the list box object? I am not getting that.
I thought I need to create the object and then write the event handler code.
0
 

Author Comment

by:aio419
ID: 17111105
and how much minimun point is requied to split it?
Thanks
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 17111120
You have to have the event handler written before you add the handler. Second argument to the AddHandler is the name of the subroutine that handles your event

Private Sub CreateControls
       Dim ListBox1 = New ListBox
        ListBox1.Size = New Size(200, 100)   'set size
        ListBox1.Location = New Point(10, 60)  'location
        AddHandler ListBox1.SelectedIndexChanged, AddressOf myHandler
        Me.Controls.Add(ListBox1)
        ListBox1.MultiColumn = True
        ListBox1.SelectionMode = SelectionMode.MultiExtended
End Sub

Private Sub myHandler(ByVal sender As Object, ByVal e As System.EventArgs)
' Do something here
End Sub
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 17111124
I don't htink you can assign less than 20 points per person.
0
 

Author Comment

by:aio419
ID: 17131497
okay i will increase points.
0
 

Author Comment

by:aio419
ID: 17131603
I increasd to 40.Still i do not get split point option!
i can not ignore ZeonFlash' answer either.B'cos he explained  my missing code from Chaosian's answer.

If i am  not getting any other option to split the points , i will award points to Chaosian .
i do not know Chaosian  can do anything to share it.
if that is the case i am very sorry ZeonFlash(even though it is only 20 points)
0
 

Author Comment

by:aio419
ID: 17169015
i do not see the Split Points in that screen.( i had done in the past with 'big' points)
If you(Chaosian) can do it,please do it.Accept your first comment as the answer and ZeonFlash's first comment as the assisted answer.
Thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

792 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