Wrox Programmer Forums
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 18th, 2008, 10:09 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default listbox always selects index 0

I have a listbox for entering phone numbers (lbxPhone). The UI gives the user the ability to remove items from the listbox (single-select) by selecting a phone number and clicking the Remove Button (btnRemovePhone).

The problem is that no matter what selection is made, the item at index zero is removed. Here is the code for btnRemovePhone:
Code:
Protected Sub btnRemovePhone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemovePhone.Click
    lbxPhone.Items.RemoveAt(lbxPhone.SelectedIndex)
End If
lbxPhone.SelectedIndex always returns zero. How can I get it to return that actually index of the selected item? What am I missing here?
 
Old August 18th, 2008, 12:41 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Make sure all the items in your listbox have a value and that they are unique.

 
Old August 18th, 2008, 01:05 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That was it. Thanks.
 
Old August 18th, 2008, 01:07 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

What was it.. no values set, or duplicate values?

 
Old August 18th, 2008, 01:08 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oops, sorry. I had values set, but there was a common scenario where there could be duplicates.
 
Old August 18th, 2008, 01:11 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Ahh ok, I have run into that before. I would be nice if an error occured while binding to you let you know of the problem.






Similar Threads
Thread Thread Starter Forum Replies Last Post
trying to get data from multiple selects ceevk1 VB Databases Basics 1 April 3rd, 2007 12:05 PM
How to combine two value-of selects? myhtpc XSLT 2 February 14th, 2006 06:20 AM
Multiple Selects in SQL QueryStrings doonman BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 6 January 30th, 2006 07:01 AM
multiple selects -single where clause collie SQL Server 2000 3 January 21st, 2005 01:27 AM
Two selects in one procedure Trojan_uk SQL Server 2000 2 December 17th, 2003 05:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.