|
-
March 23rd, 2010, 11:30 PM
#1
ADO.net ListView in C#
Hi Guys... need some help.. I have this code..
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show(listView1.SelectedItems[0].SubItems[0].Text);
}
and I always get this kind of error message evry time I change the selected Item im my listbox...
Argumentoutofrangeexception
InvalidArgument=Value of '0' is not valid for 'index'.
Parameter name: index
i need a way to get each value for the selected item in my listbox so that I can use it as a parameter for my sqlcommand.
need help.. =)
-
March 24th, 2010, 03:04 AM
#2
Re: ADO.net ListView in C#
Check SelectedItems and SubItems if they contain something, because [0] means first element, which may not be presented (e.g. if the list is empty).
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post. 
-
March 24th, 2010, 04:06 AM
#3
Re: ADO.net ListView in C#
Just to add to what boudino has said...you should run it through the debugger and inspect the contents of 'SelectedItems' and 'SubItems' at runtime. They may not be what you expect. If there is any chance those collections could be empty you should put a test around access to the values (e.g. using an 'if' statement...)
-
March 25th, 2010, 12:42 AM
#4
Re: ADO.net ListView in C#
Ok I'l go and check it out...
-
March 25th, 2010, 02:12 AM
#5
Re: ADO.net ListView in C#
why is it that every time I change the selected item in my listview using the SelectedIndexChanged event, it resets its value to nothing?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|