473,386 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Updating a list box

Hello All,

I am trying to udapte a listbox as suggested like this,but it gives me error.Please help...

Expand|Select|Wrap|Line Numbers
  1.         private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
  2.         {
  3.  
  4.             int index = listBox1.SelectedIndex;
  5.             Console.WriteLine("Index is {0}",index );
  6.             listBox1.Items[index] = textBox1.Text; 
  7.         }
  8.  
No matter which item I select in the Listbox,the index ( listBox1.Items[index]) always it takes as -1. Error:::InvalidArgument = Value of '-1' is not a valid index.

but when I print the index value using Console.writeLine it prints the correct slected index. I am not able to figure out the reason.

Thank you all
Feb 10 '09 #1
1 1257
falaque
12
use if(index>=0) and put your code inside it.
Feb 11 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? ...
3
by: Robin Tucker | last post by:
Hi, I'm in the process of implementing a multi-user system containing an adjacency list (tree structure). I'm using a TIMESTAMP field on each record in the adjacency list in order to tell when...
9
by: simon.harris | last post by:
I have a 'master' stock list with current stock levels (integer) and another table that contains transactions (i.e. item#, #items added/ removed, date, user etc). What I need is an update query...
14
by: el_sid | last post by:
Our developers have experienced a problem with updating Web References in Visual Studio.NET 2003. Normally, when a web service class (.asmx) is created, updating the Web Reference will...
5
by: Mark R. Dawson | last post by:
Hi all, I may be missing something with how databinding works but I have bound a datasource to a control and everything is great, the control updates to reflect the state of my datasource when I...
2
by: mark4asp | last post by:
Q: Initialising and updating a class with only static members & database dependency I have a class with the following members: public static List<ACISACIS_List; static AssetClass() { //...
2
by: Spam Catcher | last post by:
Hi All, I want to bind a datagridview or ListView to a List that is constantly being updated (items are added/removed all the time). Any ideas what the best way is to do this? I tried binding...
0
by: adalyc | last post by:
I NEED SOME GUIDENCE WITH UPDATING A COLLECTION OF ITEMS IN A LIST BOX WHEN THE USER CLICKS ON A BUTTON FROM ANOTHER FORM,, i HAVE LISTED THE PROBLEM PARTIALLY. I fIGURED OUT MOST OF THE PROBLEM...
2
by: =?Utf-8?B?VmFuZXNzYQ==?= | last post by:
Hi All! I am with a situation where I am not getting the right updating to the form's fields. The situation is the following one: I have one combobox and one textbox. I am using the...
1
by: Edwin.Madari | last post by:
by the way, iterating over bar will throw KeyError if that key does not exist in foo. to see that in action, simply set another key in bar after copy.deepcopy stmt in this example.. bar = 0 and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.