|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Listbox Webcontrol SelectedIndexChanged Event not workingMy Listbox control is a webcontrol and its AutoPostBack property is set to True. When I left-click on an item the event code here executes: Private Sub ListBox2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox2.SelectedIndexChanged If sender.selectedIndex > -1 Then AddUserToDL(sender.selecteditem) End If End Sub The problem is the sender.selectedIndex property is never greater than -1 and the sender.SelectedItem is set to Nothing. This happens whether the control's SelectedMode is set to Single or Multiple and it does not matter which of the 100 plus items, or multiple items, is selected. Does anyone know what could cause this? I am running Visual Studio 2003 Enterprise on a Windows 2000 Pro SP4 computer. The web server is IIS, which is running on my own workstation. Thank you for your assistance. Scott Lemen Instead of sender.SelectedItem, try CType(sender,
ListBox).SelectedIndex. SelectedIndex isn't a property of Object, and sender is an Object unless you convert it. If you're using VS.NET, the fact that the S in SelectedIndex didn't become capitalized would have been a tipoff. Lisa Scott Lemen wrote: Show quoteHide quote > Hi, > > My Listbox control is a webcontrol and its AutoPostBack property is set > to True. When I left-click on an item the event code here executes: > > Private Sub ListBox2_SelectedIndexChanged(ByVal sender As Object, ByVal > e As System.EventArgs) Handles ListBox2.SelectedIndexChanged > If sender.selectedIndex > -1 Then > AddUserToDL(sender.selecteditem) > End If > End Sub > > The problem is the sender.selectedIndex property is never greater than -1 > and the sender.SelectedItem is set to Nothing. This happens whether the > control's SelectedMode is set to Single or Multiple and it does not matter > which of the 100 plus items, or multiple items, is selected. Does anyone > know what could cause this? > > I am running Visual Studio 2003 Enterprise on a Windows 2000 Pro SP4 > computer. The web server is IIS, which is running on my own workstation. > > Thank you for your assistance. > > Scott Lemen Lisa,
Thank you for replying but your solution did not solve the problem. Even when the Event code is changed as shown just below, the myListBox.SelectedIndex = -1 and .SelectedItem is Nothing. Also, mySelectedListItemIndex = -1. Regards, Scott Private Sub ListBox2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox2.SelectedIndexChanged Dim mySelectedListItemIndex As Integer Dim myListBox As ListBox myListBox = CType(sender, ListBox) mySelectedListItemIndex = CType(sender, ListBox).SelectedIndex If mySelectedListItemIndex > -1 Then AddUserToDL(myListBox.Items(mySelectedListItemIndex)) End If End Sub Show quoteHide quote "l***@starways.net" wrote: > Instead of sender.SelectedItem, try CType(sender, > ListBox).SelectedIndex. SelectedIndex isn't a property of Object, and > sender is an Object unless you convert it. If you're using VS.NET, the > fact that the S in SelectedIndex didn't become capitalized would have > been a tipoff. > > Lisa > > > Scott Lemen wrote: > > Hi, > > > > My Listbox control is a webcontrol and its AutoPostBack property is set > > to True. When I left-click on an item the event code here executes: > > > > Private Sub ListBox2_SelectedIndexChanged(ByVal sender As Object, ByVal > > e As System.EventArgs) Handles ListBox2.SelectedIndexChanged > > If sender.selectedIndex > -1 Then > > AddUserToDL(sender.selecteditem) > > End If > > End Sub > > > > The problem is the sender.selectedIndex property is never greater than -1 > > and the sender.SelectedItem is set to Nothing. This happens whether the > > control's SelectedMode is set to Single or Multiple and it does not matter > > which of the 100 plus items, or multiple items, is selected. Does anyone > > know what could cause this? > > > > I am running Visual Studio 2003 Enterprise on a Windows 2000 Pro SP4 > > computer. The web server is IIS, which is running on my own workstation. > > > > Thank you for your assistance. > > > > Scott Lemen > > Hmm... well, I think (I'm not sure, but it's easy enough to check) that
CType(e, Integer) will give you the SelectedIndex. Other than that, I'm stumped. Lisa Scott Lemen wrote: Show quoteHide quote > Lisa, > > Thank you for replying but your solution did not solve the problem. Even > when the Event code is changed as shown just below, the > myListBox.SelectedIndex = -1 and .SelectedItem is Nothing. Also, > mySelectedListItemIndex = -1. > > Regards, > > Scott > > Private Sub ListBox2_SelectedIndexChanged(ByVal sender As Object, ByVal > e As System.EventArgs) Handles ListBox2.SelectedIndexChanged > Dim myListBox As ListBox = CType(sender, ListBox) > Dim mySelectedListItemIndex As Integer = myListBox.SelectedIndex > > If mySelectedListItemIndex > -1 Then > AddUserToDL(myListBox.Items(mySelectedListItemIndex)) > End If > End Sub > > > "l***@starways.net" wrote: > > > Instead of sender.SelectedItem, try CType(sender, > > ListBox).SelectedIndex. SelectedIndex isn't a property of Object, and > > sender is an Object unless you convert it. If you're using VS.NET, the > > fact that the S in SelectedIndex didn't become capitalized would have > > been a tipoff. > > > > Lisa > > > > > > Scott Lemen wrote: > > > Hi, > > > > > > My Listbox control is a webcontrol and its AutoPostBack property is set > > > to True. When I left-click on an item the event code here executes: > > > > > > Private Sub ListBox2_SelectedIndexChanged(ByVal sender As Object, ByVal > > > e As System.EventArgs) Handles ListBox2.SelectedIndexChanged > > > If sender.selectedIndex > -1 Then > > > AddUserToDL(sender.selecteditem) > > > End If > > > End Sub > > > > > > The problem is the sender.selectedIndex property is never greater than -1 > > > and the sender.SelectedItem is set to Nothing. This happens whether the > > > control's SelectedMode is set to Single or Multiple and it does not matter > > > which of the 100 plus items, or multiple items, is selected. Does anyone > > > know what could cause this? > > > > > > I am running Visual Studio 2003 Enterprise on a Windows 2000 Pro SP4 > > > computer. The web server is IIS, which is running on my own workstation. > > > > > > Thank you for your assistance. > > > > > > Scott Lemen > > > >
Validation controls validate before form submits
binding - DropDownList flaw/bug? Who is the true Asp.Net MVP here? asp 2.0 wizard control (how to set focus on button) Trying hard to implement globalisation. Strange error message(urgent help needeed) Can't get the Microsoft Web Library load event doesn't fire unless init event is present Finding the leftmost pixel in a piece of text when using GDI+ How to view properties of control inside table Client Side Calculation involving controls in datagrid template co |
|||||||||||||||||||||||