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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:55:35+00:00 2026-06-01T18:55:35+00:00

I am trying to mimic the way a ListView and other controls handle SelectedItems

  • 0

I am trying to mimic the way a ListView and other controls handle SelectedItems collections. I have a class with a collection of items and each Item has a Selected property.

I want to mimic the smart behavior where an Item can change its own Selected property and upon doing so would raise a SelectedItemsChanged event in the parent class, and the SelectedItems collection should now reflect the change.

I am trying to implement a SelectedItemsCollection class which does not contain an inner list but instead checks the Selected state of each item in the main Items list. This way it doesn’t need to be constantly updated and synchronized with the main list.

I was looking at the metadata for ListView.SelectedListViewItemCollection and it has the following declaration:

public class SelectedListViewItemCollection : IList, ICollection, IEnumerable

It does not implement Add, Remove, RemoveAt, etc. Isn’t this against the rules of using the IList interface? I cannot compile without implementing them. Is this just a glitch in the way the metadata is created?

How should I go about emulating this functionality?

  • 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-01T18:55:36+00:00Added an answer on June 1, 2026 at 6:55 pm

    Those methods are implemented explicitly.
    For example disassembling the class with ILspy you can see that the Add() method is implemented as follows:

    int IList.Add(object value)
    {
        throw new NotSupportedException();
    }
    

    So, for instance if you have an instance of SelectedItemsCollection and you want to invoke the Add() method, you must cast the object to IList e.g. :

    ((IList)mySelectedItemsCollection).Add(...)
    

    And yes, if you look at the metadata of the class through Visual Studio, the explicitly implemented methods are hidden.

    About the Selected property… well the “trick” is that each item has a reference to the ListView it belongs to. When Selected property changes, the item calls SetSelectedState() method of the listView that raises a SelectedChanged event.

    Also SelectedItemsCollection is created passing the ListView reference in the constructor, in this way the enumerations of the elements is actually performed on an inner member of ListView that is accessible from SelectedItemsCollection because it’s a nested class.

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

Sidebar

Related Questions

I'm trying to mimic what every other tabular view does with the DataGridView control,
Trying to avoid repetition here. I have an action in a base class controller
I'm trying to mimic the webforms multiview functionality and the only way i can
I'm trying to come up with a way to mimik something we were previously
i am trying to mimic an effect found usually on mobile devices where you
I'm trying to mimic the web functionality of having a label over a textbox
I'm trying to create a custom UserControl that will mimic auto-complete as it works
In my application, I am trying to get my API to mimic GitHub's in
I have a class that represents an external physical measuring device. The simplified version
I am trying to mimic snapshot materialized view based on this article on valena.com

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.