Click to See Complete Forum and Search --> : Listbox Event Handler Problem


ZhiYi
February 20th, 2006, 03:44 AM
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

HanneSThEGreaT
February 20th, 2006, 07:00 AM
Did you create the listbox in codeż
If so, the only thing I can think of is to maybe declare your listbox WithEvents
Public WithEvents List1 As ListBox
Or am I understanding you wrongż

ZhiYi
February 20th, 2006, 09:00 PM
Thank you for the reply

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

HanneSThEGreaT
February 20th, 2006, 11:50 PM
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!