Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7165265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:12:40+00:00 2026-05-28T14:12:40+00:00

How do I use the ListView ‘s ItemSelectionChanged event? I have a ListView ,

  • 0

How do I use the ListView‘s ItemSelectionChanged event? I have a ListView, which in turn has 8 columns; and the first column of each row contains the Id for the row and this is what I’m after.

I need this because the Id is to be used to select info from a list. This list is what populates the ListView, but it doesn’t show all of the info. The info not being shown is to be displayed in a RichTextBox and, of course, it should display the info for that selected item in the ListView. The Id’s are the same, of course, but no matter what I try I can’t seem to reach that value.

My code so far:

foreach ([ClassName] x in [List])
{
    if (x.id == Convert.ToInt32(myListView.FocusedItem.Text))
    {
        rtbxSpecific.Text = x.name;
    }
}

This works great for the first object in the ListView, but not for any of the following where it throws a NullReferenceException. Why does this happen? It’s like the event fires, but it doesn’t know about any other item in the list except for the first one.

I’ve also tried using selectedItems[0].Text, selectedItems[0].SubItems[0].Text but it’s basically the same fault. This is really annoying me and I would be really thankful if someone could explain why it works for the first ListViewItem, but not the following.

I even tried using Find(...) on the list with:

[Class] cl = [List].Find(delegate([Class] q) {return q.id == Convert.ToInt32(myListView.FocusedItem.SubItems[0].Text);});

But no dice, which leads me to believe its the FocusedItem that is being nasty right now and I’m not getting anywhere with this. The Find(...) method would be cleaner to use, I suppose, but right now I’m getting the same error with both.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:12:41+00:00Added an answer on May 28, 2026 at 2:12 pm

    Simple check to see if the selected item.count was > 0.

    if (myListView.SelectedItems.Count > 0)
    {
        foreach ([Class] cl in [List])
        {
            if (myListView.SelectedItems[0].SubItems[0].Text == cl.[Field].ToString())
            {
                RichTextBox.Text = cl.[Field];
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listview with 200 items. I use a custom view for each
I use listview but prefer the column size to be fixed. Have no idea
I have two activities, both of which use a listview. I called one android:list,
I use ListView to show several items. My row.xml as below: <TextView android:text=text android:id=@+id/tvViewRow
Listview has a data-inset property to make its corners rounded. However, I can't use
I have a simple question that which method is best and why ? Use
I'm trying to use a ListView which is just like on this page: http://developer.android.com/resources/tutorials/views/hello-listview.html
My recent app is like a forum, i use listview to show each thread.
I am developing a soundboard application in which I use Listview Activity. But since
I am developing a soundboard application in which I use Listview Activity. But since

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.