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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:17:30+00:00 2026-05-23T05:17:30+00:00

When I populate a ListBox with RIA Services, an item is automatically selected. This

  • 0

When I populate a ListBox with RIA Services, an item is automatically selected. This triggers the SelectionChanged event. If I move the selection up or down with the arrow keys, the event also gets triggered.

I don’t want this. I want the user to press enter or click the item for it to be selected. How do I accomplish 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-05-23T05:17:31+00:00Added an answer on May 23, 2026 at 5:17 am

    You could handle the MouseLeftButtonDown and KeyDown events for the ListBox. For the KeyDown event, you’ll need to check the EventArgs to determine whether the Enter key was pressed (as opposed to any other key).

    These events can fire even when an item is not selected (e.g., if the user clicks inside the ListBox but not over an actual item), so within your event handlers you should check for this.

    Your event handlers might look something like this:

    public void MyListBox_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
       ItemSelected();
    }
    
    public void MyListBox_KeyDown(object sender, KeyEventArgs e)
    {
       if ((e.Key & Key.Enter) == Key.Enter)
       {
          ItemSelected();
       }
    }
    
    public void ItemSelected()
    {
       if (MyListBox.SelectedItem != null)
       { 
          // Handle item selection here
       } 
    }
    

    These are off the top of my head, so you may need to tweak these slightly to get them to work exactly right. Hopefully you see the general idea though.


    Another way to do it would be to simply remove the SelectionChanged event handler when populating the ListBox with items (use the “-=” syntax), then re-attach it once this operation is complete.

    I’d recommend doing it this way (since you’re concerned about the event firing when the list is populated). It wouldn’t stop the users from selecting items using the Up and Down arrow keys, but unless you have a really good reason for doing so you’re making things unnecessary inconvenient (users don’t want to be arbitrarily restricted from doing things that ought to work).

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

Sidebar

Related Questions

I have a ListBox populated with a list from ImageDomainService (RIA Services). I want
I'm trying to populate a listbox with a series checkbox entries, however once running
I learnt example from msdn to populate a listbox control with arraylist. http://msdn.microsoft.com/en-us/library/1818w7we(v=VS.100).aspx I
I have a listbox with runat=server Items are added to this listbox on the
I like to populate a Listbox with a List<T> as the ItemsControl.ItemsSource . It
I want to populate a listbox after inputting text into a text box and
i want to populate a listbox with the table names from a database. here's
I wanted to know how can I populate a ListBox dinamically. But I don't
I have a problem regarding with C#. How to populate a listbox with those
In ASP C#, you can create a select (ListBox) then populate it with items

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.