Solved

ListView SelectedItems

Posted on 2004-08-15
2
3,446 Views
Last Modified: 2008-01-09
Hello all,

I'm trying to get item text out of selected item of a list view. Following event code works out once:

private void listView1_SelectedIndexChanged(object sender, System.EventArgs e)
{
   textBox1.Text=listView1.Items[listView1.SelectedIndices[0]].Text;
}

When selecting another item afterwards,  I get 'System.ArgumentOutOfRangeException'. Why?

Any hints are welcome!
0
Comment
Question by:zaratin
2 Comments
 
LVL 10

Accepted Solution

by:
ptmcomp earned 125 total points
ID: 11803770
SelectedIndexChanged will also be fired when no item is selected. Therefore you must check first if SelectedIndices.Count is greater than 0.

private void listView1_SelectedIndexChanged(object sender, System.EventArgs e)
{
   if (listView1.SelectedIndices.Count > 0)
   {
      textBox1.Text=listView1.Items[listView1.SelectedIndices[0]].Text;
   }
}
0
 

Author Comment

by:zaratin
ID: 11804257
Thanks for your answer ptmcomp.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now