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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:17:29+00:00 2026-05-13T22:17:29+00:00

I’d like to implement a ListView that will have a list of SelectedItems as

  • 0

I’d like to implement a ListView that will have a list of SelectedItems as it has now,
but it will also have a separate item that is under cursor (movable with mouse/keyboard).
Item selecting will be done with special action (for example the space key).

In other words, I’d like to suppress selection on the ListView and only change FocusedItem when selection would normally occur.

I think that I should do something with ListView‘s FocusedItem and SelectedItems properties,
but the thing is that clicking an item selects it (also changes focus).

A solution would be to capture keydown and mouseclick events that can change selection and only change FocusedItem to the item according to the event (item under mouse pointer in mouseclick and item above/below current one in keydown up/down arrow). Then I would only add items to SelectedItems collection on my special event (space key press).

What I’m asking is if there is more ellegant approach to this problem or the solution above is as simple as it can be. Thanks

  • 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-13T22:17:29+00:00Added an answer on May 13, 2026 at 10:17 pm

    Ok, scratch this.

    I needed to subclass ListView (ListViewEx);

    handle keyboard selection events:

    private void ListViewEx_KeyDown(object sender, KeyEventArgs e)
    {
    if (e.KeyData == Keys.Down)
    {
        //move focus down
        if (this.FocusedItem.Index + 1 < this.Items.Count)
        {
            this.FocusedItem = this.Items[this.FocusedItem.Index + 1];
            this.FocusedItem.EnsureVisible();
            e.Handled = true;
        }
    }
    else if (e.KeyData == Keys.Up)
    {
        if (this.FocusedItem.Index - 1 < this.Items.Count)
        {
            this.FocusedItem = this.Items[this.FocusedItem.Index - 1];
            this.FocusedItem.EnsureVisible();
            e.Handled = true;
        }
    }
    }
    

    and mouse events in WndProc

    this way left click/keyboard up/down moves focus and keyboard right click makes selection

    protected override void WndProc(ref Message m)
    {
        const int WM_LBUTTONDOWN = 0x0201;
        const int WM_RBUTTONDOWN = 0x204;
        switch (m.Msg)
        {
            case WM_LBUTTONDOWN:
                Point pos = this.PointToClient(Cursor.Position);
                var item = GetItemAt(pos.X, pos.Y);
                this.FocusedItem = item;
                break;
            case WM_RBUTTONDOWN:
                pos = this.PointToClient(Cursor.Position);
                item = GetItemAt(pos.X, pos.Y);
                item.Selected = !item.Selected;
                break;
            default:
                base.WndProc(ref m);
                break;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have text I am displaying in SIlverlight that is coming from a CMS
I want to count how many characters a certain string has in PHP, but
I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a JSP page retrieving data and when single or double quotes are
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am trying to loop through a bunch of documents I have to put

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.