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 8371301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:07:44+00:00 2026-06-09T14:07:44+00:00

i still cannot understand how to make the item in listview to be clickable

  • 0

i still cannot understand how to make the item in listview to be clickable and appear messagebox.

this is my code.

private void button6_Click(object sender, EventArgs e)
    {
        ListViewItem listviewitem;

        listviewitem = new ListViewItem("John");
        listviewitem.SubItems.Add("Smith");
        listviewitem.SubItems.Add("kaya");
        listviewitem.SubItems.Add("bun");
        this.listView1.Items.Add(listviewitem);
        listView1.FullRowSelect = true;

//show header
listView1.View = View.Details;

        // Loop through and size each column header to fit the column header text.
        foreach (ColumnHeader ch in this.listView1.Columns)
        {
            ch.Width = -2;
        }

}

i have read itemActive and i have tried this. im adding listView1.SelectedItems[0].Text

    private void button6_Click(object sender, EventArgs e)
        {
            ListViewItem listviewitem;

            listviewitem = new ListViewItem("John");
            listviewitem.SubItems.Add("Smith");
            listviewitem.SubItems.Add("kaya");
            listviewitem.SubItems.Add("bun");
            this.listView1.Items.Add(listviewitem);
            listView1.FullRowSelect = true;

            MessageBox.Show("You clicked " + listView1.SelectedItems[0].Text);
}

this printout error

argument out of range. ‘0’ is not valid number of index.

please help me with this.

  • 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-06-09T14:07:45+00:00Added an answer on June 9, 2026 at 2:07 pm

    On button6_Click() only add newly created listviewitem in listView1

    private void button6_Click(object sender, EventArgs e)
    {
        ListViewItem listviewitem;
    
        listviewitem = new ListViewItem("John");
        listviewitem.SubItems.Add("Smith");
        listviewitem.SubItems.Add("kaya");
        listviewitem.SubItems.Add("bun");
        this.listView1.Items.Add(listviewitem);
        listView1.FullRowSelect = true;
    
        //MessageBox.Show("You clicked " + listView1.SelectedItems[0].Text);
    }
    

    Register the Click event against listView1

    this.listView1.Click += new System.EventHandler(this.listView1_Click);
    

    And in it’s event handler check for listView1.SelectedItems[0]

    private void listView1_Click(object sender, EventArgs e)
    {
         if(listView1.SelectedItems.Count > 0)
                 MessageBox.Show("You clicked " + listView1.SelectedItems[0].Text);
    }
    

    For documentation, please check MSDN

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I still cannot understand what does it mean to return an object in a
After loosing much sleep I still cannot figure this out: The code below (its
I realize there are similar questions on this topic, but I still cannot find
Method 'Private Sub trigger_Triggered(sender As Object, e As OamsIDD.VoamsWorldIDD.OamsStateChangeEventArgs)' cannot handle event 'Public Event
If the end_user cannot access the source code of the app, why we still
I've searched StackOverflow but still cannot understand the correct syntax to use Single, First
I read several posts regarding this but still don't understand how to solve my
So, I looked through different posts and other resources and I still cannot make
I have repaired .net 4.0 but (still) cannot find: Ilasm.exe Any ideas? I need
I searched high an low and still cannot find a definite answer. How do

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.