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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:48:13+00:00 2026-06-08T20:48:13+00:00

Update! To clarify the question. I would like to change the selected item in

  • 0

Update!

To clarify the question. I would like to change the selected item in my listview by using the up and down arrow. I have tied keydown to a textbox. If a user presses the period key i make my listview visible. But it’s not focused, that is why I have tied the keydown events to the textbox to be able to change the selecteditem in the listview.

the code that visuaö studio is complaining about is this

index = listView1.SelectedIndices[0];

the zero is somehow wrong?

I’m using a listview!

How do I change the listview selecteditem programatically? I’m currently listening to to the keypress events of up arrow and down arrow.

As they are pressed I would like to change the selected items index. So that it would behave equally as when pressing up or down arrow having it focused!

I have been trying, but it gives me an ugly error message.

Argument out of range exception with the additional information that goes like this:

Value of 0 is not valid for index. Here’s my code for down arrow.

IT really should work I’m totally clueless about this!

if (e.KeyCode == Keys.Down)
{
    if (listView1.Visible)
    {
        index = listView1.SelectedIndices[0];  
        index = index - 1;
        this.listView1.Items[index].Selected = true;
    }
}

and for up arrow

if (e.KeyCode == Keys.Up)
{
    if (this.listView1.Visible)
    {
        index = listView1.SelectedIndices[0];
        index++;
        this.listView1.Items[index].Selected = true;
    }
}
  • 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-08T20:48:14+00:00Added an answer on June 8, 2026 at 8:48 pm

    Try this instead:

    if (e.KeyCode == Keys.Down)
    {
        if (listView1.Visible && listView1.Items.Count > 0)
        {
            index = listView1.SelectedIndices[0];  
            index = index - 1;
            this.listView1.Items[index].Selected = true;
        }
    }
    

    I think you are getting an IndexOutOfBound because you don’t have any items in the list.

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

Sidebar

Related Questions

UPDATE: To clarify a generic error catcher that catches 404's doesn't have enough granularity
UPDATE: To help clarify what I'm asking I have posted a little java code
UPDATE: Let me clarify my files and reiterate my question: main.h #include other.h class
I have a PlaceHolder control inside of a ListView that I am using to
I have a SQL table like so: Update: I'm changing the example table as
(Sorry if it's a trivial question.) I have documents that looks like this (Python
I'm using C#. I have a products class with fields like sku, name, description....
In ASP.NET, does every HttpRequest get its own thread? Update - To clarify, I'm
UPDATE: Based on rrenaud's great comment I wanted to clarify that although I'm generating
UPDATE: I've been playing around with this more, and it seems like tmux's clear-history

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.