CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2005
    Posts
    200

    Angry Listbox Event Handler Problem

    Hi,
    I am creating a web parts control containing a listbox, a button and a context menu using visual basic.net. I have created both controls and would like to add a selectionIndexChanged event handler for the listbox but the intellisense list did not display the listbox control.

    Here is a code snippet:

    Protected Overrides Sub CreateChildControls()

    listbox1 = new listbox //adding a listbox control
    listbox1.ID = "List1"
    listitem1.Text = "Testing"
    listbox1.Items.Add(listitem1)
    Me.Controls.Add(listbox1)
    //intellisense didnt display the listbox for event handling! [?]

    button1 = new button //adding a button control
    button1.ID = "Button1"
    button1.Text = "Test"
    Me.Controls.Add(button1)
    AddHandler button1.Click, AddressOf button1_Click //intellisense did include the button control for event handling

    End Sub

    How do I allow event handling for the listbox? It seems that vb was unable to recognise the listbox for AddHandler

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Listbox Event Handler Problem

    Did you create the listbox in code¿
    If so, the only thing I can think of is to maybe declare your listbox WithEvents
    Code:
    Public WithEvents List1 As ListBox
    Or am I understanding you wrong¿

  3. #3
    Join Date
    Apr 2005
    Posts
    200

    Red face Re: Listbox Event Handler Problem

    Thank you for the reply

    I've tried it and now there is an event handler for the listbox.

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Listbox Event Handler Problem

    Quote Originally Posted by ZhiYi
    Thank you for the reply

    I've tried it and now there is an event handler for the listbox.
    Ah, That's good news!
    Good Work!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured