Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ListView SelectedItems

Posted on 2004-08-15
2
Medium Priority
?
3,463 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Accepted Solution

by:
ptmcomp earned 500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

688 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