Solved

ListBox1_SelectedIndexChanged' is not declared.

Posted on 2006-07-14
13
353 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Passing data between Forms 3 26
VB.net Duplicating a table - primary key not created 3 38
MYSQL responding very slow 3 48
vb.net convert long time to mm:ss 23 20
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

679 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